Hi, "Upon failure, zmq_poll() shall return -1 and set errno to one of the values defined below", so you should check errno.
BR, Stathis From: [email protected] [mailto:[email protected]] On Behalf Of mycircuit Sent: Friday, February 15, 2013 2:05 PM To: [email protected] Subject: [zeromq-dev] zmq_poll return value and C-CTRL interrupts Hi I am using zeromq 3.2.2 on linux ubuntu 12.04. I am confused about the behavior of zmq_poll when getting a ctrl-c. The guide says: If your code is blocking in zmq_msg_recv()<http://api.zeromq.org/3-2:zmq_msg_recv>, zmq_poll()<http://api.zeromq.org/3-2:zmq_poll>, or zmq_msg_send()<http://api.zeromq.org/3-2:zmq_msg_send>, when a signal arrives, the call will return with EINTR. EINTR is defined as 4 , but when I interrupt the zmq_poll , I get -1 as return value. Am I missing something ? The code is below. I get : start poll ^Cfinished poll with -1 start poll ^Cfinished poll with -1 each time I press CTRL-C. I am not sending anything to this socket during this test. Thanks for your thoughts. mycircuit ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #include "czmq.h" static int s_interrupted = 0; static void s_signal_handler (int signal_value) { (void) signal_value; s_interrupted = 1; printf("handle interrupt \n"); } static void s_catch_signals (void) { struct sigaction action; action.sa_handler = s_signal_handler; action.sa_flags = 0; sigemptyset (&action.sa_mask); sigaction (SIGINT, &action, NULL); sigaction (SIGTERM, &action, NULL); } int main (void) { char *interf = "*"; int service = 5562; s_catch_signals(); zctx_t *ctx = zctx_new (); assert (ctx); void *rep_skt = zsocket_new (ctx, ZMQ_REP); assert (rep_skt); int rc = zsocket_bind (rep_skt, "tcp://%s:%d", interf, service); assert (rc == service); zmq_pollitem_t items [] = { { rep_skt, 0, ZMQ_POLLIN, 0 } }; while (!s_interrupted) { printf("start poll \n"); int rc = zmq_poll(items, 1, -1); printf("finished poll with %d \n", rc); sleep(0.1); } zsocket_destroy (ctx, rep_skt); zctx_destroy (&ctx); return 0; }
_______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
