From 9b67181b39239792840c83c1cff84e8a96bebab5 Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Wed, 5 Oct 2005 23:20:10 +0000 Subject: [PATCH 1/1] When recv returns 0, the connection has been remotely closed or dropped. Changes are to Read [ modified patch 1303565 ] and Select [ patch 1283936 ] git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35802 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/unix/gsocket.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/unix/gsocket.cpp b/src/unix/gsocket.cpp index 874098d3b6..eaa732bb78 100644 --- a/src/unix/gsocket.cpp +++ b/src/unix/gsocket.cpp @@ -882,7 +882,13 @@ int GSocket::Read(char *buffer, int size) else ret = Recv_Dgram(buffer, size); - if (ret == -1) { + /* If recv returned zero, then the connection is lost, and errno is not set. + * Otherwise, recv has returned an error (-1), in which case we have lost the + * socket only if errno does _not_ indicate that there may be more data to read. + */ + if (ret == 0) + m_error = GSOCK_IOERR; + else if (ret == -1) { if ((errno == EWOULDBLOCK) || (errno == EAGAIN)) m_error = GSOCK_WOULDBLOCK; else @@ -1026,7 +1032,12 @@ GSocketEventFlags GSocket::Select(GSocketEventFlags flags) result |= GSOCK_CONNECTION_FLAG; m_detected |= GSOCK_CONNECTION_FLAG; } - else if ((errno != EWOULDBLOCK) && (errno != EAGAIN) && (errno != EINTR)) + /* If recv returned zero, then the connection is lost, and errno is not set. + * Otherwise, recv has returned an error (-1), in which case we have lost the + * socket only if errno does _not_ indicate that there may be more data to read. + */ + else if (num == 0 || + (errno != EWOULDBLOCK) && (errno != EAGAIN) && (errno != EINTR)) { m_detected = GSOCK_LOST_FLAG; m_establishing = false; -- 2.45.2