[En-Nut-Discussion] Industrial interfaces (Modbus TCP, Profinet, etc.)
Philipp Burch
phip at hb9etc.ch
Thu Jul 17 20:53:28 CEST 2014
Oh, what happened? I somehow didn't get that post from you Thiago...
Anyway, don't mind about that code, I should be able to get it right :)
Cheers,
Philipp
On 17.07.2014 20:48, Nathan Moore wrote:
> On Thu, Jul 17, 2014 at 1:59 PM, Thiago A. Corrêa <thiago.correa at gmail.com>
> wrote:
>>
>> Please notice the API returns the number of actually received bytes.
>> The size is a maximum buffer size, not a minimum or required read
>> size. That's a fairly common bug, to expect reads to return with the
>> "requested" amount of bytes. Sometimes it does, sometimes it doesn't.
>> It's your job to loop thru receive calls until you get the amount of
>> bytes you want, something along:
>>
>> int rcvCount = 0;
>> while( rcvCount < sizeof(mbap_header) )
>> rcvCount += receive( socket, &mbap_header + rcvCount,
>> sizeof(mbap_header) - rcvCount );
>
>
> True, but it's actually still more complicated because receive can return -1
> which isn't a real count and shouldn't be added to rcvCount, but I wanted
> the code to be easy to follow.
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion
>
More information about the En-Nut-Discussion
mailing list