[zeromq-dev] JZMQ non-blocking recvByteBuffer

Petr Postulka ppostulka at gmail.com
Wed Jul 2 10:50:26 CEST 2014


Hi Trevor,

here is the pull request for the issue mentioned above:
https://github.com/zeromq/jzmq/pull/330

I have one more question regarding recvByteBuffer method: in c++ code I
noticed that in case you receive more data than it is available in provided
buffer, you return truncated number of bytes ... I think in this case the
method should still return number of bytes read from the socket (even
though they were truncated because of not enough space in buffer) so it
corresponds with zeromq API and the caller can check whether the data were
truncated or not.

it is the following block of code in recvByteBuffer method in Socket.cpp
file:

if (read > 0) {
        read = read > rem ? rem : read;
        env->CallObjectMethod(buffer, setPositionMID, read + pos);
        return read;
    }

and I think it should be something like this:

if (read > 0) {
        int newPos = (read > rem ? rem : read) + pos;
        env->CallObjectMethod(buffer, setPositionMID, newPos);
        return read;
    }

Please let me know if it makes sense to you and if so I can create another
pull request.

Thank you and kind regards,

Petr



On Wed, Jul 2, 2014 at 12:01 AM, Petr Postulka <ppostulka at gmail.com> wrote:

> Hi Trevor,
>
> thank you for your prompt response and confirmation.
>
> I will let you know once I submit a patch.
>
> Kind regards,
>
> Petr
>
>
> On Tue, Jul 1, 2014 at 11:38 PM, Trevor Bernard <trevor.bernard at gmail.com>
> wrote:
>
>> This is likely a typo -- I'd be happy to merge a pull request if you
>> would be so kind to submit a patch.
>>
>> On Tue, Jul 1, 2014 at 6:27 PM, Petr Postulka <ppostulka at gmail.com>
>> wrote:
>> > 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
>> >
>> > _______________________________________________
>> > 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
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140702/6ca2ebed/attachment.htm>


More information about the zeromq-dev mailing list