{ inercia }

  • Archive
  • RSS
  • Ask me anything

ZeroMq with libevent (cont)

I have just discovered the reason why my libevent program did not receive any more ZeroMq messages after the first one. It seems that, after creating the ZeroMq socket, you have to read until you get a EAGAIN error or you will not set the socket events in the right state. If you don’t do so, the idea libevent and ZeroMq have about that socket will not match, so your program will not receive/send anything.

From this thread:

The socket is initially considered ready for reading & writing. Given that ZMQ_FD is edge triggered, you won’t get next event unless you fail to send/recv a message.

So, when you create a socket, you have to do something like this:

zsocket  = new zmq::socket_t (*ZMqLink::m_pZContext, ZMQ_XREQ);

/* read until EAGAIN */
while (TRUE)
{
    zmq::message_t  msg;
    bool more = zsocket->recv(&msg, ZMQ_NOBLOCK);
    if (!more) break;
}

/* now we can get the zsocket fd */
int      fd        = (-1);
size_t   fd_size   = sizeof(fd);
zocket->getsockopt(ZMQ_FD, &fd, &fd_size);

/* ... and register it with libevent for EV_READ */
    • #libevent
    • #zeromq
  • 2 years ago
  • Permalink
  • Share
← Previous • Next →

About

Avatar My name is Alvaro and I´m currently working in Telefonica R&D in Barcelona (Spain). I previously lived in Madrid, Edinburgh, Glasgow, Michigan (USA) and A Coruña (Spain).

Pages

  • My background
  • My linkedin
  • My facebook
  • My github

Find me elsewhere...

  • @inercia_tech on Twitter
  • Facebook Profile
  • inercia on Flickr
  • Call me on Skype
  • Linkedin Profile
  • inercia on github
  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr