It takes quite a while to return socket.read_some after calling socket.close, on linux

I use Boost.Asio as a simple socket library.

When I open a socket, I create a stream that continues to read on this socket and returns when the socket was closed or some other errors occurred.

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, socket::read_someit takes quite a long time to return - I found it for more than 2 minutes.

Is there anything I can do to improve this?

+3
source share
2 answers

, : Linux, socket:: close, . , .

socket->shutdown(shutdown_both); // add this
socket->close();
+2

-, . , read_some. asio-users. ticket .

. .

+2

All Articles