[zeromq-dev] full duplex asynch messaging
Martin Sustrik
sustrik at 250bpm.com
Mon Mar 15 14:23:14 CET 2010
Arun,
> I didnt really mean the API differences (which as you point out,
> differ only by a loop). However, as i explained, i have to use this same
> socket for sending too. Then the code becomes
> queue<msg_t> outgoing queue;
> void recv_thread_routine ()
> {
> socket_t s (ctx, ZMQ_SUB);
> s.connect (...);
>
> while (true) {
> message_t msg;
> s.recv (&msg);
> callback (msg);
> acquire lock on outgoingqueue then if (outgoingQueue not empty)
> dequeue and send contents()
> }
> }
>
> Is this the only design possible?
The above won't work. You can't send messages to SUB socket.
However, if you have a bi-directional socket (such as P2P), you can poll
for IN & OUT and do the send/recv depending on the result.
Martin
More information about the zeromq-dev
mailing list