[zeromq-dev] zmq_poll return value and C-CTRL interrupts

mycircuit mycircuit at sunrise.ch
Fri Feb 15 15:19:24 CET 2013


Hi Statis

Thank you for your comment. I didn't consider CTRL-C as a failure , but
after reading the api doc again, I understand that it is treated as such .

mycircuit


On 15 February 2013 14:47, Stathis Gkotsis
<stathis.gkotsis at commsquare.com>wrote:

> 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:* zeromq-dev-bounces at lists.zeromq.org [mailto:
> zeromq-dev-bounces at lists.zeromq.org] *On Behalf Of *mycircuit
> *Sent:* Friday, February 15, 2013 2:05 PM
> *To:* zeromq-dev at lists.zeromq.org
> *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
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130215/9521b092/attachment.html>


More information about the zeromq-dev mailing list