[zeromq-dev] Checking for errors on zmq_poll: is it correct?
gonzalo diethelm
gdiethelm at dcv.cl
Thu Aug 16 21:08:09 CEST 2012
A tiny nitpick: it is an ERROR to check errno (or zmq_error()) if the call did not return an error status.
--
Gonzalo Diethelm
DCV Chile
> -----Original Message-----
> From: zeromq-dev-bounces at lists.zeromq.org [mailto:zeromq-dev-
> bounces at lists.zeromq.org] On Behalf Of Chuck Remes
> Sent: Thursday, August 16, 2012 2:16 PM
> To: ZeroMQ development list
> Cc: erupter at libero.it
> Subject: Re: [zeromq-dev] Checking for errors on zmq_poll: is it correct?
>
> Correct. No need to check zmq_error() unless zmq_poll() returns an error
> code.
>
> cr
>
> On Aug 16, 2012, at 12:11 PM, Michel Pelletier wrote:
>
> > It looks like you are assigning zerr twice and not checking the return
> > from poll. I don't think zmq_error() will return a sensible value
> > unless zmq_poll returns -1.
> >
> > -Michel
> >
> > On Thu, Aug 16, 2012 at 9:49 AM, erupter at libero.it <erupter at libero.it>
> wrote:
> >> Hello.
> >>
> >> I'm a newbie still playing around trying to grasp 0mq.
> >>
> >>
> >> I'm re-writing the first example with polling.
> >>
> >> So my REP has become
> >>
> >>
> >> zmq_pollitem_t local_zmq_sockets[1];
> >>
> >>
> >> int main (void)
> >> {
> >> zmq_msg_t request;
> >> void *context = zmq_init (1);
> >> const char * chptr = 0;
> >> int zerr = 0;
> >> // Socket to talk to clients
> >> void *responder = zmq_socket (context, ZMQ_REP);
> >> zmq_bind (responder, "tcp://*:5555");
> >> s_catch_signals ();
> >> local_zmq_sockets[0].socket = responder;
> >> local_zmq_sockets[0].events = ZMQ_POLLIN;
> >>
> >> while (1) {
> >> // Wait for next request from client
> >>
> >>
> >> zerr = zmq_poll(local_zmq_sockets,1,5);
> >> if (local_zmq_sockets[0].revents & ZMQ_POLLIN) {
> >> zmq_msg_init (&request);
> >> zmq_recv (responder, &request, 0);
> >> zmq_msg_close(&request);
> >> }
> >> zerr = zmq_errno();
> >> if (zerr != 0)
> >> { chptr = zmq_strerror(zerr);
> >> printf ("\n%s\n", chptr);
> >> }
> >>
> >> zmq_msg_close (&request);
> >> if (s_interrupted) {
> >> printf ("\nSIGTERM interrupt received, killing server...\n");
> >> break;
> >> }
> >> // Do some 'work'
> >> sleep (1);
> >>
> >> // Send reply back to client
> >> zmq_msg_t reply;
> >> zmq_msg_init_size (&reply, 5);
> >> memcpy (zmq_msg_data (&reply), "Prova", 5);
> >> zmq_send (responder, &reply, 0);
> >> zmq_msg_close (&reply);
> >> }
> >> // We never get here but if we did, this would be how we end
> >> zmq_close (responder);
> >> zmq_term (context);
> >> return 0;
> >> }
> >>
> >>
> >> Now the fact is that when it's sitting idly waiting for a REQ, the
> >> error number reported after the POLL call is always 11, and the
> >> associated string is
> >>
> >> "Resource temporarily unavailable"
> >>
> >>
> >> I don't get this: should I *not* check for errors after zmq_poll???
> >> I expected a 0 after a correct poll.
> >>
> >> Even when a message comes in, it still gives the same error code.
> >>
> >>
> >> Can anyone please explaing this behviour to me?
> >> Thanks
> >>
> >> Regards
> >>
> >> Claudio Carbone
> >>
> >>
> >>
> >>
> >> _______________________________________________
> >> zeromq-dev mailing list
> >> zeromq-dev at lists.zeromq.org
> >> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> >>
> > _______________________________________________
> > zeromq-dev mailing list
> > zeromq-dev at lists.zeromq.org
> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
-----------------------------------------
Declaración de confidencialidad: Este Mensaje esta destinado para
el uso de la o las personas o entidades a quien ha sido dirigido y
puede contener información reservada y confidencial que no puede
ser divulgada, difundida, ni aprovechada en forma alguna. El uso no
autorizado de la información contenida en este correo podrá ser
sancionado de conformidad con la ley chilena.
Si usted ha recibido este correo electrónico por error, le pedimos
eliminarlo junto con los archivos adjuntos y avisar inmediatamente
al remitente, respondiendo este mensaje.
"Before printing this e-mail think if is really necesary".
Disclosure: This Message is to be used by the individual,
individuals or entities that it is addressed to and may include
private and confidential information that may not be disclosed,
made public nor used in any way at all. Unauthorized use of the
information in this electronic mail message may be subject to the
penalties set forth by Chilean law.
If you have received this electronic mail message in error, we ask
you to destroy the message and its attached file(s) and to
immediately notify the sender by answering this message.
More information about the zeromq-dev
mailing list