[zeromq-dev] full duplex asynch messaging
Arun Jayaprakash
arun.jaiprakash at gmail.com
Mon Mar 15 14:15:18 CET 2010
Hi Martin,
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
void io_thread_routine ()
{
socket_t s (ctx, ZMQ_SUB);
s.connect (...);
while (true) {
message_t msg;
s.recv (&msg); // non blockingb recv
callback (msg);
}
}
On Mon, Mar 15, 2010 at 5:08 PM, Martin Sustrik <sustrik at 250bpm.com> wrote:
> Arun,
>
>
> Thanks for you quick response. In my application there can be messages
>> to be sent and received at random unpredictable points of time (and in any
>> order) and they need to be processed with minimal latency. The latter would
>> require me to call recv in a loop. The sends would come in from a separate
>> thread. From docs, i see that i can only access zmq_socket from the creating
>> thread. So this essentially needs the sender thread to enqueue its messages
>> somewhere , then the looping thread has to repeatedly initiate non blocking
>> recvs and chk send queue, then a (nonblocking) send etc within a single
>> loop. That doesnt look like a very efficient design at the surface. I was
>> ideally looking for something which fits the below model. Is there a
>> callback which can be registered when there are messages waiting to be read
>> ? If not, do you have any suggestions for the above requirements?
>> // This method would be called by one single thread
>> sendMessage(msg)
>> {
>> socket.send(msg);
>> }
>>
>> // incoming message from network should // call below method (from a
>> specifed thread or pool)
>> // for boost asio , this is the thread/s which start io_service
>> messageFromNetworkCallback(msg)
>> {
>> process_message (msg);
>> }
>>
>
> If you like the callback API better than socket API, create a thread that
> would do following:
>
> void recv_thread_routine ()
> {
> socket_t s (ctx, ZMQ_SUB);
> s.connect (...);
>
> while (true) {
> message_t msg;
> s.recv (&msg);
> callback (msg);
> }
> }
>
> Martin
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20100315/8684eb30/attachment.htm>
More information about the zeromq-dev
mailing list