Hi Y'alls!
I have a problem that drives me nuts regarding CZMQ use of zpoller. First let
me explain the environment: CZMQ version 4.2.1, ZMQ version 5.2.3, Centos 7,
GCC version 4.8.5.
I am trying to use a client to push messages to a server. The client and the
server at this point are pairs, but in the future, there will be a server and
multiple clients.
I have the following C client:
int main() {
zsys_debug("Sending...");
zsock_t *client = zsock_new_push ("@tcp://127.0.0.1:9000");
assert (client);
char *string = NULL;
int i = 0;
for (i = 0; i < 100; i++) {
string = zsys_sprintf ("%02d %s %s %s!", i, "Kilroy", "was", "here");
zstr_send(client, string);
zsys_debug("Sent: %s", string);
free(string);
}
sleep(3);
zsock_destroy (&client);
zsys_debug("Done!'");
return 0;
}
And I have the following C server running on a thread:
void *server(void *args) {
zsock_t *my_server = zsock_new_pull(">tcp://127.0.0.1:9000");
assert (my_server);
// Set up poller
zpoller_t *poller = zpoller_new (my_server, NULL);
assert (poller);
while(!zsys_interrupted) {
zsock_t *which = (zsock_t *) zpoller_wait (poller, -1);
if (which != NULL) {
char *message = zstr_recv (which);
zsys_debug("Message: %s", message);
zstr_free (&message);
} /*else {
zsys_debug("nothing\n");
}*/
}
zpoller_remove(poller, &my_server);
zpoller_destroy (&poller);
zsock_destroy (&my_server);
pthread_exit(NULL);
}
My problem is this: When I use this code in two separate simple applications,
the above code works. However, when I move the server into a larger application
with multiple threads, it is starting to behave randomly: it works in some
cases, but it mostly doesn't. The poller does detect anything on wait.
I am looking at this for over a week now and I cannot understand why. Can
somebody please tell me what should I look for? Maybe I should use another
approach?
Thank you,
Johnny
_______________________________________________
zeromq-dev mailing list
[email protected]
https://lists.zeromq.org/mailman/listinfo/zeromq-dev