add reset functionality
authorMart Lubbers <mart@martlubbers.net>
Wed, 17 May 2017 09:42:11 +0000 (11:42 +0200)
committerMart Lubbers <mart@martlubbers.net>
Wed, 17 May 2017 09:42:11 +0000 (11:42 +0200)
client/client.c
client/client.h [new file with mode: 0644]
client/interface.h
client/linux/client.h [new symlink]
client/linux/interface.c

index 19a68e9..a86de24 100644 (file)
@@ -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 (file)
index 0000000..2eb5250
--- /dev/null
@@ -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
index 266c13d..738dd85 100644 (file)
@@ -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 (symlink)
index 0000000..10b598d
--- /dev/null
@@ -0,0 +1 @@
+../client.h
\ No newline at end of file
index 520873f..e611ea8 100644 (file)
@@ -13,6 +13,7 @@
 #include <unistd.h>
 
 #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);
+}