[zeromq-dev] JZMQ non-blocking recvByteBuffer

Petr Postulka ppostulka at gmail.com
Tue Jul 1 23:27:13 CEST 2014


Hi all,

I have a question regarding non-blocking recvByteBuffer call in JZMQ -
whenever there are no data to receive the call throws an exception and I'm
not sure whether this is the proper way how it should be implemented. Maybe
I'm missing something here, but when I checked the corresponding C++ code
in Socket.cpp class I can see the following block of code in recvByteBuffer
method implementation:

    int read = zmq_recv(sock, buf + pos, rem, flags);
    if (read > 0) {
        read = read > rem ? rem : read;
        env->CallObjectMethod(buffer, setPositionMID, read + pos);
        return read;
    }
    else if(read == -1) {
        int err = zmq_errno();
        if(err == EAGAIN) {
            raise_exception (env, err);
            return 0;
        }
    }
    return read;

If I understand it correctly, shouldn't there be  if(err != EAGAIN) then
raise_exception? Because right now it is throwing exception only when there
are no data to receive, which is making non-blocking call basically
unusable because throwing and catching the exception is very costly
operation. At the same time other errors, which are in contrast to EAGAIN
much more important do not throw the exception at all.

Please let me know whether my assumption is correct or not.

Thank you and kind regards,

Petr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140701/0abcc77d/attachment.htm>


More information about the zeromq-dev mailing list