[zeromq-dev] Breaking blocking in a server app
Matt Weinstein
mattweinstein at gmail.com
Fri Jul 2 16:20:38 CEST 2010
Brian et al,
Just a followup on my comment earlier:
I look at ØMQ as enabling richer computational topologies / event-
driven models.
So if you look at your problem, it's not a "shutdown" problem, but
rather another event occurred ("shutdown") which triggers a different
branch.
If you generalize the model a bit, you might end up with an interface
that wraps poll() + recv(ZMQ_NOBLOCK) into a tidier interface (no
flames please :-) ):
int index = zmq_recv_next({your favorite way of building a list of
sockets});
switch (index) {
case 1: // normal socket
...
break;
case 2: // shutdown socket
...
break;
default: // ouch
...
}
You could add, e.g. a command socket:
case 3: // report status
...
break;
If you wanted to, or simply re-use the broadcast node of case 2 to
carry more than one "command".
This should extend gracefully to a full message-passing paradigm if
you want (see some of the previous posts et al), but this
functionality should suffice for the case you described.
Best,
Matt
On Jul 1, 2010, at 3:15 PM, Matt Weinstein wrote:
> One simple way might be to use an inproc: PUB/SUB socket:
>
> zmq::socket_t kill_me(*ctx, ZMQ_SUB);
> kill_me.setsockopt(ZMQ_SUBSCRIBE, "", 0); // [typographic
> correction applied-MW]
>
> Service threads would then poll() both their normal socket and the
> "kill" socket. As soon as a message arrived, the thread would
> cleanup and quit.
>
> On Jun 30, 2010, at 9:05 PM, Brian Granger wrote:
>
>>
>>
>> On Wed, Jun 30, 2010 at 5:27 PM, Matt Weinstein <matt_weinstein at yahoo.com
>> > wrote:
>> Under what circumstances do you want to break blocking?
>>
>> E.g. timeout, connection failure, etc.?
>>
>>
>>
>> For us, we want to do this when we want to kill a process that is
>> sitting there blocking in zmq.recv. IOW, we want SIGINT to trigger
>> the process to shutdown in a semi-clean manner (no seg faults!).
>>
>> Cheers,
>>
>> Brian
>>
>> On Jun 30, 2010, at 10:23 AM, Derek Developer wrote:
>>
>>> Is there any way to break the blocking of zmq_recv() without
>>> firing up a client and sending a message like "QUIT SERVER"?
>>>
>>> _______________________________________________
>>> zeromq-dev mailing list
>>> zeromq-dev at lists.zeromq.org
>>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>>
>>
>>
>> --
>> Brian E. Granger, Ph.D.
>> Assistant Professor of Physics
>> Cal Poly State University, San Luis Obispo
>> bgranger at calpoly.edu
>> ellisonbg at gmail.com
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20100702/8646801e/attachment.htm>
More information about the zeromq-dev
mailing list