The behavior should be fixed at the libzmq level IMO, and documented. I'd suggest that reading from a socket that was neither bound nor connected is an error, and should perhaps even assert. Or at least return an ENOTCONN error.
-Pieter On Mon, Dec 30, 2013 at 1:37 PM, Matt Connolly <[email protected]> wrote: > After some further testing with czmq, I have discovered that the behaviour of > not being able to read from a socket when not bound is particular to the ruby > rbczmq bindings, and that czmq does not operate this way. I’m curious if > other bindings such as python are the same as czmq. > > I can update the rbczmq bindings to allow the read from a socket that has no > connections/binds. > > So another question then: > > > Consider doing a blocking read from a socket with no active endpoints > (connect/bind). If there are messages, they should be returned. Should this > call block indefinitely when there are no messages in the internal queue? Or > would it be better to return an error code (e.g.: EAGAIN)? > > > -Matt > > > On 29 Dec 2013, at 9:34 pm, Matt Connolly <[email protected]> wrote: > >> Dear list, >> >> I’ve been playing around with how to ensure that a service has processed all >> messages that it has received (in the receiving socket queue) before >> shutting down. In particular, I’m using the rbczmq ruby bindings, so this >> question is also to see if those bindings are consistent with other >> languages. >> >> Scenario: >> >> A service has a ROUTER socket, bound to a tcp endpoint. >> A client has a DEALER socket, connected to that tcp endpoint. >> The client has sent one or more messages and is expecting a reply to each >> message. >> The messages have been transmitted and are in the service’s inbound message >> queue waiting for processing. >> The service receives a shutdown request (for example, a system being >> restarted for maintenance). >> The service should process all received messages or store them for >> processing on next start-up. >> >> — >> >> When I do a socket.disconnect in the service, it is unable to read any >> message in the queue for that socket. However, if I subsequently connect >> that socket to a dummy endpoint, such as “ipc://foo”, then I can receive all >> of the messages in the queue that were sent to the real address. Once >> disconnected, the service is unable to send a response to the client, but at >> least the message can be saved, and a reply could be sent when the service >> comes back online. >> >> The service should only be down for a small amount of time (just a few >> minutes I suppose) so for messages queued at the client side, this is not a >> problem because the client will wait for a reply and the io thread will >> continue to reconnect and send when it connects to the service. >> >> Is the behaviour normal that socket.receive will fail with an error if the >> socket has no active endpoints (bind or connect)? I suppose this only makes >> sense for a non-blocking call, otherwise if there are no messages in queue, >> then the call will BlockForever™… >> >> Also, I notice that if I disconnect/unbind the socket from the service, that >> ZMQ::Poller#poll and ZMQ::Socket#poll both report the socket as being >> readable, but reading from the socket still fails. Is this particular to >> rbczmq? >> >> >> Cheers, >> Matt >> >> PS: happy holidays all! >> >> _______________________________________________ >> zeromq-dev mailing list >> [email protected] >> http://lists.zeromq.org/mailman/listinfo/zeromq-dev > > _______________________________________________ > zeromq-dev mailing list > [email protected] > http://lists.zeromq.org/mailman/listinfo/zeromq-dev _______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
