From e0102c2396df94c574a331db0443613eca748c51 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 20 Nov 2019 18:47:09 +0100 Subject: [PATCH] Allow disabling events for blocking sockets in Unix version It should still be possible to use DoEnableEvents() to disable events for blocking sockets and this can be useful if a previously non-blocking socket became blocking due to a SetFlags(wxSOCKET_BLOCK) call, so adjust the fix of e18c8fd29a10b1b87ea5cff7c5b3a16fe5b32690 (see #17031) to avoid calling EnableEvents() for blocking sockets instead of ignoring them in DoEnableEvents() itself. Also add an assert checking that we never try enabling events for blocking sockets as this still doesn't make sense and so shouldn't happen. No real changes yet, but this is necessary for the upcoming commits. See #12886. --- include/wx/unix/private/sockunix.h | 4 ++++ src/unix/sockunix.cpp | 11 ++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/wx/unix/private/sockunix.h b/include/wx/unix/private/sockunix.h index 05d043d354..2e4506bcbc 100644 --- a/include/wx/unix/private/sockunix.h +++ b/include/wx/unix/private/sockunix.h @@ -40,6 +40,10 @@ public: virtual void ReenableEvents(wxSocketEventFlags flags) wxOVERRIDE { + // Events are only ever used for non-blocking sockets. + if ( GetSocketFlags() & wxSOCKET_BLOCK ) + return; + // enable the notifications about input/output being available again in // case they were disabled by OnRead/WriteWaiting() // diff --git a/src/unix/sockunix.cpp b/src/unix/sockunix.cpp index 78542648ef..e1ffee352a 100644 --- a/src/unix/sockunix.cpp +++ b/src/unix/sockunix.cpp @@ -90,17 +90,18 @@ wxSocketError wxSocketImplUnix::GetLastError() const void wxSocketImplUnix::DoEnableEvents(int flags, bool enable) { - // No events for blocking sockets, they should be usable from the other - // threads and the events only work for the sockets used by the main one. - if ( GetSocketFlags() & wxSOCKET_BLOCK ) - return; - wxSocketManager * const manager = wxSocketManager::Get(); if (!manager) return; if ( enable ) { + // We should never try to enable events for the blocking sockets, they + // should be usable from the other threads and the events only work for + // the sockets used by the main one. + wxASSERT_MSG( !(GetSocketFlags() & wxSOCKET_BLOCK), + "enabling events for a blocking socket?" ); + if ( flags & wxSOCKET_INPUT_FLAG ) manager->Install_Callback(this, wxSOCKET_INPUT); if ( flags & wxSOCKET_OUTPUT_FLAG )