[zeromq-dev] Socket Polling

Ivajlo Donev ivajlo at codeforte.com
Fri Jan 17 16:47:22 CET 2014


Hello,

 

I've been having some problems with polling for messages between two
remote computers or a computer and VM. I managed to write a small
reproducible program.

It is two 32bit test programs written in  c++ in windows (7) (zmq 3.2.4)
that form a simple REQ/REP loop. In the REP program after I bind the
socket I run the following loop  :

 

While(1) {

         mySocket.getsockopt(ZMQ_FD, &sock, &sock_size);

         hRecvEvent = ::WSACreateEvent();
         WSAEventSelect(sock, hRecvEvent, FD_ALL_EVENTS );
         WSAResetEvent(hRecvEvent);

 

         DWORD retVal = WaitForSingleObject(hRecvEvent, 1000);        

                

                    if (retVal == WAIT_OBJECT_0)

   {

           ::WSAResetEvent(hRecvEvent);
 
             int events = 0;
             do {
                 events = 0;
                 size_t eventsSize = sizeof(events);
                mySocket.getsockopt(ZMQ_EVENTS, &events, &eventsSize);
                 if (events & ZMQ_POLLIN) {
                       mySocket.rev(&message);
                       mySocket.send(reply);
                  }
             } while (events & ZMQ_POLLIN);
         }
}
 
When the two programs are running on remote computers or on VMs the
"WaitForSingleObject" never triggers for the first message. If I force
the first receive/reply pair 
Everything runs fine after that. I'm not sure what the problem could be
but I also noticed that if I add "mySocket.getsockopt(ZMQ_EVENTS,
&events, &eventsSize);" just after the bind and before the loop the
problem also goes away. Does this maybe have something to do with the
sockets not being ready ?
 
Hopefully you guys might be able to help me ....
Ivo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140117/34130820/attachment.htm>


More information about the zeromq-dev mailing list