[zeromq-dev] Resource temporarily unavailable

Ashok Chippa a.n.chippa at gmail.com
Sun Dec 25 01:20:51 CET 2011


Hi,

I am getting a "Resource temporarily unavailable" with a REP/XREP/DEALER
socket on zmq_recv(). I have tried all three with and without ZMQ_NOBLOCK
option and still see the same issue. This is with a simple inproc socket
for testing.

Basically, I have a process which creates a test thread. The main process
opens the socket, and does a zmq_recv() in a while loop. The test thread
sends messages into this socket. The zmq_send() on the test thread seems to
be working (did not see any error there.) Even though I have a while loop I
see the error (Resource temporarily unavailable) only once! Seems like even
with ZMQ_NOBLOCK it is blocking and probably not receiving anything.

What am I missing? (Not sure how to specify end point for inproc socket
though.)

Here's the code snippets:

CREATION OF SOCKET
------------------------------------

    /* Create socket to talk to local user/test harness.
     */
    user = zmq_socket(context, ZMQ_DEALER);
    if (!user) {
        printf("user socket create failed: %s\n", zmq_strerror(errno));
        assert(0);
        return 0;
    }
    if (zmq_bind(user, "inproc://group_chat_client") == -1) {
        printf("user socket bind failed: %s\n", zmq_strerror(errno));
        assert(0);
        return 0;
    }

WHILE LOOP
--------------------

    while (1) {
        /* Check the user socket. If there is something
         * from the user handle it. We are basically
         * doing round-robin between user, requestor and
         * subscriber sockets. (Wonder zmq can be enhanced
         * to do WRR for us between multiple sockets., Better
         * to block on multiple sockets and unblock when a
         * message arrives of any one of them.)
         */
        zmq_msg_init(&msg);
        zmqret = zmq_recv(user, &msg, ZMQ_NOBLOCK);

        if (zmqret == -1) {
            printf("zmq_recv on user returned \"%s\"\n",
                    zmq_strerror(errno));
        }

        if (errno != EAGAIN && errno != EWOULDBLOCK) {

            printf("we have something in the user socket");

            /* We have a server/user message. Parse it. We do not
             * want zmq APIs deep within our code.
             */
            gc_client_get_message(&msg, &size, &request);

            /* Handle the request/reply.
             */
            if (size) gc_client_handle_message(request, size);
        }
        /* Close the message.
         */
        zmq_msg_close(&msg);
...
}

CONNECT FROM TEST THREAD
--------------------------------------------------

void *
test_main (void *arg)
{
    zmq_msg_t   msg;
    size_t      size;
    int         zmqret;
    uint8_t    *request;
    char       *newline;
    char        text[256];

    /* Connect to the client user socket.
     */
    if (zmq_connect(user, "inproc://group_chat_client") == -1) {
        printf("connect to user socket failed: %s\n", zmq_strerror(errno));
        pthread_exit(0);
    }
...

SEND CODE FROM TEST THREAD
-----------------------------------------------------
I verified the size (13 bytes)

    /* Send it to the parent process.
     */
    zmq_msg_init_data(&zmsg, buf, size, NULL, NULL);
    if (zmq_send(user, &zmsg, 0) == -1) {
        printf("zmq_send returned \"%s\"\n", zmq_strerror(errno));
    }
    zmq_msg_close(&zmsg);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20111224/5474a66d/attachment.htm>


More information about the zeromq-dev mailing list