I can't close socket once i bind socket to a session.
Closed this issue · 3 comments
On my side. i implement a DAP client.
Why? because session is start when bind a socket to session.
Then it start to read. It will only return when the socket is close by DAP server or a message come from server.
At the same time , i can't close the socket ,because , it lock in read function.
size_t read(void* buffer, size_t bytes) {
RLock lock(mutex); // lock here.
if (s == InvalidSocket) {
return 0;
}
auto len =
recv(s, reinterpret_cast<char*>(buffer), static_cast(bytes), 0);
return (len < 0) ? 0 : len;
}
void close() {
#if !defined(_WIN32)
{
RLock l(mutex);
if (s != InvalidSocket) {
::shutdown(s, SHUT_RDWR);
}
}
#endif
**WLock l(mutex);// wait here**
if (s != InvalidSocket) {
#if defined(_WIN32)
closesocket(s);
#else
::close(s);
#endif
s = InvalidSocket;
}
}
Thank you for the detailed bug report. That was a stupid bug for me to have introduced, my apologies.
#38 should fix this, and adds tests for the clearly missing test coverage.
Thanks you @ben-clayton