From: Mart Lubbers Date: Wed, 17 May 2017 09:42:11 +0000 (+0200) Subject: add reset functionality X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=fcb4abeb34dc3302f15b10c3b916bc14e3047707;p=mTask.git add reset functionality --- diff --git a/client/client.c b/client/client.c index 19a68e9..a86de24 100644 --- a/client/client.c +++ b/client/client.c @@ -20,6 +20,7 @@ #define MSG_SDS_DEL 'a' #define MSG_SDS_UPD 'u' #define MSG_SPEC 'c' +#define MSG_SHUTDOWN 'h' #define LOOPDELAY 100 @@ -61,6 +62,9 @@ void read_message(void) debug("Receiving a spec request"); spec_send(); break; + case MSG_SHUTDOWN: + debug("Shutdown received"); + reset(); case '\0': debug("Server closed connection"); break; diff --git a/client/client.h b/client/client.h new file mode 100644 index 0000000..2eb5250 --- /dev/null +++ b/client/client.h @@ -0,0 +1,13 @@ +#ifndef CLIENT_H +#define CLIENT_H + +#ifdef __cplusplus +extern "C" { +#endif + +int main(int argc, char **argv); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/client/interface.h b/client/interface.h index 266c13d..738dd85 100644 --- a/client/interface.h +++ b/client/interface.h @@ -77,6 +77,7 @@ void real_setup(void); void debug(char *fmt, ...); void pdie(char *s); void die(char *fmt, ...); +void reset(void); #ifdef __cplusplus } diff --git a/client/linux/client.h b/client/linux/client.h new file mode 120000 index 0000000..10b598d --- /dev/null +++ b/client/linux/client.h @@ -0,0 +1 @@ +../client.h \ No newline at end of file diff --git a/client/linux/interface.c b/client/linux/interface.c index 520873f..e611ea8 100644 --- a/client/linux/interface.c +++ b/client/linux/interface.c @@ -13,6 +13,7 @@ #include #include "interface.h" +#include "client.h" struct timeval tv1; int sock_fd = -1; @@ -143,10 +144,12 @@ void real_setup(void) sa.sin_addr.s_addr = INADDR_ANY; sa.sin_port = htons(port); - if((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) - pdie("socket"); - if(bind(sock_fd, (struct sockaddr*)&sa, sizeof(sa)) == -1) - pdie("bind"); + if(sock_fd == -1){ + if((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) + pdie("socket"); + if(bind(sock_fd, (struct sockaddr*)&sa, sizeof(sa)) == -1) + pdie("bind"); + } if(listen(sock_fd, 10) == -1) pdie("listen"); @@ -180,3 +183,10 @@ void die(char *fmt, ...) va_end(ap); exit(EXIT_FAILURE); } + +void reset() +{ + close(fd); + fd = -1; + main(gargc, gargv); +}