A bug was introduced in the atomic vector feature for blocking netconns
where if we couldn't write the entire vector due to send buffer being
full (write_more is 0), we would not update the vector state and then
when sent_tcp() is called, it would actually re-send the previous vector
and if additional calls were required to finish the write, msg.w.offset
would eventually exceed msg.w.len, This was found by testing "stats"
from the shell and hitting the LWIP_ASSERT in do_writemore() that
checks offset < len
The fix simply updates the vector state after every ERR_OK return from
tcp_write(). While not all cases (non-blocking sockets) need to update
the state in this case, it keeps the logic simple and also makes
debugging simpler because you don't have stale vector state at any
point
This commit adds support to the netconn write APIs to take an input of
vectors instead of a single data pointer
This allows vectors sent on a TCP connection via sendmsg to be treated
atomically. The set of vectors is segmented into as much data as can
fit into the send buffer and then the TCP output function is called
Previously, each vector was passed to netconn_write_partly and tcp_write
segmented it into its own packet, which was then it was sent via
tcp_output (if not Nagleing)
This commit adds vector support to lwip_netconn_do_writemore() which
is the meat of the TCP write functionality from netconn/sockets layer.
A new netconn API netconn_write_vectors_partly() takes a set of vectors
as input and hooks up to do_writemore()
This commit also defines IOV_MAX because we are limited to only
supporting 65535 vectors due to choice of u16_t for the vector count
This commit changes netconn_write_partly to use msg.w.offset to set
bytes_written for both blocking and non-blocking connections
This is correct because msg.w.offset is the canonical output from
the do_write call and in the case that not all bytes were written,
(a bug?) returning the full size to the caller is dangerous
Lastly, this commit adds an assert for the blocking case to sanity
check that all the bytes we requested were written. This will help
catch bugs in do_write
This commit makes a couple of cleanups discussed in patch #8882:
1) msg.w.offset should not be set to 0 in the error case. It is
only valid when err == ERR_OK
2) Remove out-of-date comment which indicated the entire write had
completed (not true for non-blocking write)
This also updates the documentation on offset to include that offset
is only valid when err == ERR_OK