diff --git a/src/logger.c b/src/logger.c index 28a87f2..9f9d78d 100644 --- a/src/logger.c +++ b/src/logger.c @@ -32,6 +32,7 @@ void publish(int queue_id, void* publisher); typedef struct queue { int size; + char issending; char msg[ZMQ_MSG_SIZE]; } queue; queue queues[MAX_QUEUES]; @@ -97,10 +98,17 @@ int main (int argc, char *argv []) struct timespec power_ts; int queue_id=0; + // Init queues + for(int i=0;i=MAX_QUEUES ? 0 : (queue_id+1); + // Busy wait: + while(queues[queue_id].issending){}; // Write msg header: *queues[queue_id].msg='\0'; sprintf(queues[queue_id].msg,"%s\n%s\n%s\n%ld\n",ZMQ_TOKEN,__key,__client,interval); @@ -128,6 +136,7 @@ int main (int argc, char *argv []) #endif //printf("Tick\n"); fflush(stdout); } + queues[queue_id].issending=1; publish(queue_id,publisher); } @@ -142,5 +151,6 @@ int main (int argc, char *argv []) void publish(int queue_id, void* publisher){ printf("Publishing..."); zmq_send(publisher,queues[queue_id].msg,queues[queue_id].size,0); + queues[queue_id].issending=0; printf("done\n"); } \ No newline at end of file