Skip to content
This repository

Non blocking read triggers log message #4

Open
whatupdave opened this Issue · 3 comments

3 participants

Dave Newman Tony Schneider Robert McGibbon
Dave Newman

If you do a non blocking read:

id data = [socket receiveDataWithFlags:ZMQ_NOBLOCK];

and there's nothing on the queue, you get the log message:

zmq_recv: Resource temporarily unavailable

Perhaps it should check for the ZMQ_NOBLOCK flag?

Tony Schneider

I am also getting this. Is this the intended behavior?

Is this library still being maintained?

Robert McGibbon

I had to switch the code to using 0MQ 2 instead of but here's a fix for the nonblocking issue:

If I have time later, I'll package this all up as a PR

Basically, you just need to check for errno=EAGAIN per http://api.zeromq.org/2-1:zmq-recv

#pragma mark Communication
- (NSData *) recv:(ZMQMessageReceiveFlags) flags {
    zmq_msg_t data;
    int err = zmq_msg_init(&data);
    if (err) {
        ZMQLogError(self, @"zmq_msg_init");
        return nil;
    }

    errno = 0;
    err = zmq_recv(self.socket, &data, flags);
    if (err) {
        if (flags == ZMQ_NOBLOCK && errno == EAGAIN) {
            zmq_msg_close(&data);
            return nil;
        } else {
            ZMQLogError(self, @"zmq_recv");
            err = zmq_msg_close(&data);
            if (err) {
                ZMQLogError(self, @"zmq_msg_close");
            }
        }
    }

    size_t length = zmq_msg_size(&data);
    NSData *msg = [NSData dataWithBytes:zmq_msg_data(&data) length:length];

    err = zmq_msg_close(&data);
    if (err) {
        ZMQLogError(self, @"zmq_msg_close");
        /* fall through */
    }
    return msg;
}
Robert McGibbon

I just learned objective-c today, but fortunately this library is pretty simple, if poorly documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.