#define MSG_SDS_DEL 'a'
#define MSG_SDS_UPD 'u'
#define MSG_SPEC 'c'
+#define MSG_SHUTDOWN 'h'
#define LOOPDELAY 100
debug("Receiving a spec request");
spec_send();
break;
+ case MSG_SHUTDOWN:
+ debug("Shutdown received");
+ reset();
case '\0':
debug("Server closed connection");
break;
#include <unistd.h>
#include "interface.h"
+#include "client.h"
struct timeval tv1;
int sock_fd = -1;
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");
va_end(ap);
exit(EXIT_FAILURE);
}
+
+void reset()
+{
+ close(fd);
+ fd = -1;
+ main(gargc, gargv);
+}