|
Boost Users : |
From: Keith Robinson (Keith.Robinson_at_[hidden])
Date: 2020-06-10 15:14:11
Hi,
I'm sending data from one process to another using a tcp connection. Sender use scatter-gather to send the data using 3 buffers (total just over 2000 bytes). The reader uses 2 separate sync reads to read the data (using the asio free function read()) using a non blocking socket.
Sometimes everything is fine, the 2 reads return the amount of data requested, but sometimes I see strange behaviour. I'm trying to work out whether I am doing something wrong, or whether I've stumbled across a bug.
When it goes wrong for me, the second read always returns less data than I requested, along with the error code 'would_block'. I then loop, performing further reads (using the same buffer as before), eventually (one read, or multiple reads later) the read function returns the remainder of the data, but still with the error code 'would_block' set. However, when I check the contents of the buffer, it is not what I expected. I think, but haven't been able to confirm, that the start of the buffer is not the start of the data.
1. Is it expected that the read() free function, when the socket is non blocking, can return less data than requested, along with the error code 'would_block'?
2. If it is expected, does the buffer passed in subsequent reads have to be adjusted to read only the remaining about of data?
3. If the buffer does have to be changed to only read what is left, how does this work with scatter-gather reads using multiple buffers?
As a little bit of extra info, I confirmed using tcpdump that the correct data is sent/received, although it arrives in 2 chunks (MTU size of 1500). This is on Linux using Boost 1.73.0.
Cheers,
Keith
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net