Whether or not you do a blocking lwip_recv(), the amount of data returned can
be any number of bytes up to the number you specified.
There is no option to make lwip_recv() block until a certain minimum number of
bytes have been received.
You cannot control the pattern of receive data, as it is affected by many
factors beyond your control. You should never assume that data will be received
in the same sized chunks as were written by the sender.
Your application must be able to deal with receiving only a few of the bytes
you need, storing them in your own buffer, then calling lwip_recv() again to
get the next chunk, and repeating until you have the number of bytes you want.
For the protocol as you describe it, I suggest you set up an 8 byte buffer to
receive the length and command code, and do repeated lwip_recv() calls as
required to fill that buffer, initially asking for 8 bytes, then if the initial
call returns fewer than 8 bytes (and no error), repeat as required, asking for
the remaining bytes and adjusting the memory pointer to allow for the bytes
already received. Once you have the full 8 bytes, you can interpret the length
and command fields, and decide what to do about the data field which follows.
If you can't cope with 4 gigabytes of data at once, you will have to do sanity
checks on the received length field, and for acceptable but large lengths you
may need to use a relatively small buffer and process the data in chunks,
rather than trying to receive all the data into a single contiguous buffer. You
will also have to make repeated lwip_recv() calls to receive all of the data
(up to the total number of bytes specified in your protocol's length field).
Error checking will also be required, e.g. to detect premature closure of the
connection.
----- Original Message -----
From: Oscar F
To: Mailing list for lwIP users
Sent: Wednesday, September 16, 2009 5:30 PM
Subject: [lwip-users] function recv
Hello everybody, i have a question about function recv in a TCP socket
connection. In my application i receive several command with diferent lenght.
the command is composed for 4 byte of lenght + 4 byte comamnd code + N byte of
data.
Does the recv function return me the lenght total, or can be posible to
return me less data of the total lenght?
What is the best form to implement this buffer, create a buffer of maximun
size (i don´t known exactly the total lenght for command, and i don´t want to
create a buffer of 4 byte because is very big?
any suggestion?
thanks
Oscar
_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users