I don't want to close the socket in case of a timeout, but only cancel the operation and retry later.
The read is "byte-based" instead of "line-based".
It works fine on Linux. However, on Windows the io_context.run() sometimes (about once per 2-3 minutes) blocks for about 20 seconds after socket cancel(). I can reproduce the problem only if the TCP server is on a different machine (localhost to localhost does not seem to exhibit the problem).
How to reproduce
Start a TCP server on a different machine, e.g.:
while sleep 1; do echo "hello"; done | nc -l 20000
On the Windows host launch the program below.
Each 2-3 minutes, you should see the message, e.g. "cancel took 20405 ms".
Environment
Boost Asio version 1.79.0
Windows 10, MSVC 2017 (tcp client)
Ubuntu 20.04, gcc 9.40 (tcp server)
Problem description
Using a TCP client, I need to read N bytes and return after some timeout if not all bytes have been received. Here is the code:
This is very similar to the blocking tcp client example, with the following differences:
It works fine on Linux. However, on Windows the io_context.run() sometimes (about once per 2-3 minutes) blocks for about 20 seconds after socket cancel(). I can reproduce the problem only if the TCP server is on a different machine (localhost to localhost does not seem to exhibit the problem).
How to reproduce
while sleep 1; do echo "hello"; done | nc -l 20000
Environment Boost Asio version 1.79.0 Windows 10, MSVC 2017 (tcp client) Ubuntu 20.04, gcc 9.40 (tcp server)