I'm using Boost.Asio as a simple socket library.
When I open a socket, I create a thread which keeps reading on that socket, and returns when the socket has been closed, or some other errors occured.
while((read = socket->read_some(buf, ec)) != 0) {
// deal with bytes read
}
This code works well on Windows and Mac. However with linux, when the socket is closed from the main thread, it takes quite long time for socket::read_some to return - I found it's more than 2 minutes.
Is there anything I can do to improve this?
If you desire cancel-ability, use asynchronous sockets. Don't use synchronous methods such as read_some. This has been discussed ad infinitum on the asio-users mailing list. There's also a ticket on the boost bug tracker discussing it.
Also see my answer to a similar question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With