[zeromq-dev] Non-Blocking REQ/REP Server
Charles Remes
lists at chuckremes.com
Tue Feb 19 15:52:36 CET 2013
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
More information about the zeromq-dev
mailing list