Minor changes

This commit is contained in:
Loic Guegan 2023-07-15 12:45:13 +02:00
parent 97e167da1b
commit a37251135e

View file

@ -12,18 +12,32 @@
// Global:
char *__logdir;
int __loginterval;
int __port;
void publish(char *filepath, char* client, int interval);
int main (int argc, char *argv [])
{
if(argc != 3){
printf("Usage: %s <abslogdir> <loginterval>",argv[0]);
if(argc != 4){
printf("Usage: %s <abslogdir> <loginterval> <port>",argv[0]);
exit(1);
}
//----- Init global variables
__logdir=argv[1];
__loginterval=atoi(argv[2]);
__port=atoi(argv[3]);
//----- Prepare our context and publisher
void *context = zmq_ctx_new ();
void *publisher = zmq_socket (context, ZMQ_PUB);
char bindto[30];
sprintf(bindto,"tcp://*:%d",__port);
int rc = zmq_bind (publisher, bindto);
if(rc!=0){
printf("Failed to bind zmq on %s\n",bindto);
exit(1);
}
//----- Start publisher
DIR *dr = opendir(__logdir);
@ -46,7 +60,7 @@ int main (int argc, char *argv [])
}
// Send current one
if(FILE_EXISTS(logfile)){
printf("Sending....\n");
publish(logfile,client,interval);
}
}
}
@ -54,20 +68,26 @@ int main (int argc, char *argv [])
closedir(dr);
return 0;
// Prepare our context and publisher
void *context = zmq_ctx_new ();
void *publisher = zmq_socket (context, ZMQ_PUB);
int rc = zmq_bind (publisher, "tcp://*:"STRINGIFY(PUBLISHER_PORT));
assert (rc == 0);
// Initialize random number generator
while (1) {
zmq_send (publisher, "Hello World", 5, 0);
printf("AA\n");
}
zmq_close (publisher);
zmq_ctx_destroy (context);
return 0;
// // Prepare our context and publisher
// void *context = zmq_ctx_new ();
// void *publisher = zmq_socket (context, ZMQ_PUB);
// int rc = zmq_bind (publisher, "tcp://*:"STRINGIFY(PUBLISHER_PORT));
// assert (rc == 0);
// // Initialize random number generator
// while (1) {
// zmq_send (publisher, "Hello World", 5, 0);
// printf("AA\n");
// }
// zmq_close (publisher);
// zmq_ctx_destroy (context);
return 0;
}
void publish(char *filepath, char* client, int interval){
}