[zeromq-dev] Non-Blocking REQ/REP Server
Lee Sylvester
lee.sylvester at gmail.com
Tue Feb 19 16:16:01 CET 2013
Thank you, that's great. So, based on what I've read, does this look correct for what I'm trying to accomplish?
int read_zmq_connections() {
zmq_pollitem_t items [] = {
{ zmq_responder, 0, ZMQ_POLLIN, 0 }
};
while (1) {
zmq_msg_t message;
zmq_poll(items, 1, 0);
if (items[0].revents & ZMQ_POLLIN) {
char *str = s_recv(zmq_responder);
parse_new_data(str);
free(str);
} else {
break;
}
}
return 0;
}
Thanks,
Lee
On 19 Feb 2013, at 14:52, Charles Remes <lists at chuckremes.com> wrote:
> Take a look at the man page for zmq_poll. You can do a non-blocking poll for incoming messages on your socket. If it returns immediately with 0, then no sockets in your pollset have pending messages to read.
>
> Be aware that when zmq_poll does indicate that you have messages, you must read *all* of them from the socket before zmq_poll will work again. I'm pretty sure the man page explains this.
>
> Good luck.
>
> On Feb 19, 2013, at 8:44 AM, Lee Sylvester <lee.sylvester at gmail.com> wrote:
>
>> Hey guys,
>>
>> So, I've integrated ØMQ into my server. Now, I want to use ØMQ as a means to supply information to a HTTP server from a separate management app. So, in theory, it will look something like this
>>
>> int read_zmq_connections() {
>> int ret = 0;
>> while (zmq_has_messages(zmq_responder)) {
>> char *str = s_recv(zmq_responder);
>> parse_new_data(str);
>> free(str);
>> ++ret;
>> }
>> return ret;
>> }
>>
>> This way, if there are no messages on zmq_responder, then the function will simply return. What I don't know how to do (and can't quite find) is how to check if messages exist on the connection. Can anyone please point me in the right direction?
>>
>> The reason why I need this non-blocking is that I will only be calling 'read_zmq_connections' approximately once every five minutes and I don't want my app to hang while waiting for messages.
>>
>> Thanks loads in advance,
>> Lee
>> _______________________________________________
>> 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
More information about the zeromq-dev
mailing list