From ffda2b39b6fe070a3f5edb229dd7806c362cc9e1 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 15 Apr 2017 09:54:31 +0200 Subject: server: Add cmd_ping --- command.c | 6 ++++++ net.c | 8 ++++++++ net.h | 1 + 3 files changed, 15 insertions(+) diff --git a/command.c b/command.c index 92556de..b966a75 100644 --- a/command.c +++ b/command.c @@ -258,6 +258,11 @@ static bool cmd_history(struct conn_data *data,const char *tag,const char **args return closed; } +static bool cmd_ping(struct conn_data *data,const char *tag,const char **args){ + (void)args; + return net_send_pong(data->fd,tag); +} + struct cmd_info{ const char *cmdname; @@ -275,6 +280,7 @@ static const struct cmd_info commands[]={ {"invite",2,false,cmd_invite}, {"send",2,true,cmd_send}, {"history",2,false,cmd_history}, + {"ping",0,false,cmd_ping}, }; #define NCOMMANDS (sizeof(commands)/sizeof(commands[0])) diff --git a/net.c b/net.c index 8e6644c..e5bdb6b 100644 --- a/net.c +++ b/net.c @@ -73,3 +73,11 @@ bool net_send_list(int fd,const char *tag,i64 count,const char **list){ return net_send_raw_text(fd,"\n",1); } + +bool net_send_pong(int fd,const char *tag){ + char *buf=NULL; + i64 len=asprintf(&buf,"%s pong\n",tag); + bool closed=net_send_raw_text(fd,buf,len); + free(buf); + return closed; +} diff --git a/net.h b/net.h index de78c12..4528e42 100644 --- a/net.h +++ b/net.h @@ -8,3 +8,4 @@ bool net_send_ok(int fd,const char *tag); bool net_send_error(int fd,const char *tag,const char *msg); bool net_send_name(int fd,const char *tag,const char *name); bool net_send_list(int fd,const char *tag,i64 count,const char **list); +bool net_send_pong(int fd,const char *tag); -- cgit v1.2.3-70-g09d2