diff options
Diffstat (limited to 'src/subscriber.c')
| -rw-r--r-- | src/subscriber.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/subscriber.c b/src/subscriber.c index 2f8dd2a..27c9441 100644 --- a/src/subscriber.c +++ b/src/subscriber.c @@ -2,9 +2,17 @@ #include <assert.h> #include <time.h> #include <string.h> - +#include <signal.h> #include "utils.h" +unsigned char __stop=0; +void sighandler(int signo){ + if (signo == SIGINT){ + printf("Stopping...\n"); + __stop=1; + } +} + int main (int argc, char *argv []) { if(argc != 3){ @@ -18,6 +26,7 @@ int main (int argc, char *argv []) //----- Various inits mkdirp(cdatadir); + signal(SIGINT,sighandler); //----- Init ZMQ void *context = zmq_ctx_new (); @@ -35,8 +44,10 @@ int main (int argc, char *argv []) //----- Listen char buffer[ZMQ_MSG_SIZE]; int size; - while(1){ + while(!__stop){ size=zmq_recv (subscriber, buffer, ZMQ_MSG_SIZE-1, 0); + if(size<=0) + continue; buffer[size < ZMQ_MSG_SIZE ? size : ZMQ_MSG_SIZE - 1] = '\0'; //----- Read buffer char *token = strtok(buffer, "\n"); |
