X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cf86dc50e0a5f20a9c696e49942cb50c761aa86f..0372d42ea50de251b381c22855b372a967bc04d9:/src/unix/gsocket.cpp diff --git a/src/unix/gsocket.cpp b/src/unix/gsocket.cpp index 08dbb42dfa..5cb9783b71 100644 --- a/src/unix/gsocket.cpp +++ b/src/unix/gsocket.cpp @@ -21,7 +21,6 @@ #ifndef __GSOCKET_STANDALONE__ #include "wx/defs.h" #include "wx/private/gsocketiohandler.h" -#include "wx/thread.h" // for wxThread::IsMain() used in assert #endif #if defined(__VISAGECPP__) @@ -872,10 +871,6 @@ void GSocket::Notify(bool flag) { if (flag == m_use_events) return; -#if wxUSE_THREADS - // it is not safe to attach or detach i/o descriptor in child thread - wxASSERT_MSG( wxThread::IsMain(), "should be called in main thread only" ); -#endif m_use_events = flag; EnableEvents(flag); } @@ -1198,11 +1193,16 @@ int GSocket::Read(char *buffer, int size) else ret = Recv_Dgram(buffer, size); - /* If recv returned zero, then the connection has been gracefully closed. - * 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 recv returned zero for a TCP socket (if m_stream == NULL, it's an UDP + * socket and empty datagrams are possible), then the connection has been + * gracefully closed. + * + * 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) + if ((ret == 0) && m_stream) { /* Make sure wxSOCKET_LOST event gets sent and shut down the socket */ if (m_use_events) @@ -1777,9 +1777,17 @@ void GSocket::Detected_Read() } else if (num == 0) { - /* graceful shutdown */ - CALL_CALLBACK(this, GSOCK_LOST); - Shutdown(); + if (m_stream) + { + /* graceful shutdown */ + CALL_CALLBACK(this, GSOCK_LOST); + Shutdown(); + } + else + { + /* Empty datagram received */ + CALL_CALLBACK(this, GSOCK_INPUT); + } } else {