ReadBuffer() exits before read all requested bytes ... PumpThread ends


I discovered following problem in ReadBuffer() method of Reader class using .Net Micro Framework and Netduino Plus 2 board with ActiveMQ as broker. However, the problem isn't related to the platforms used.

Receiving messages the following case happened :

count was 56 .... so we ask to read 56 bytes
bytes was 28 ... we received 28 on 56 bytes
count -= bytes --> count = 28 ... half of bytes requested

the "if" is true because (bytes == count) but we didn't read all 56 requested bytes !
In this case the ReadBuffer() exits and returns false (count == 0) the caller ReadFromBuffer returns null, in the PumpThread() we have that buffer is null and set sizeBuffer to null so the while exits and the PumpThread() finishes !

I solved changing ...

if (bytes == 0 || bytes == count)

in ...

if (bytes == 0)

Removing (bytes == count) ... I think it is useless.
In this way we can exit if no bytes are read. We will exit from while when count == 0 so all bytes are read.

Closed Sep 1, 2015 at 1:13 AM by xinchen


xinchen wrote Jul 27, 2014 at 10:59 PM

Yes that's a bug. I have committed the change you proposed to fix it.