Ticket #12886: fix-socket-events.patch

File fix-socket-events.patch, 4.8 KB (added by chrisstankevitz, 8 years ago)

do not reenable events if they were not enabled in the first place

  • src/unix/sockunix.cpp

     
    106106    if ( enable )
    107107    {
    108108        if ( flags & wxSOCKET_INPUT_FLAG )
     109        {
    109110            manager->Install_Callback(this, wxSOCKET_INPUT);
     111            m_socket_input_flag_enabled = true;
     112        }
    110113        if ( flags & wxSOCKET_OUTPUT_FLAG )
     114        {
    111115            manager->Install_Callback(this, wxSOCKET_OUTPUT);
     116            m_socket_output_flag_enabled = true;
     117        }
    112118    }
    113119    else // off
    114120    {
    115121        if ( flags & wxSOCKET_INPUT_FLAG )
     122        {
    116123            manager->Uninstall_Callback(this, wxSOCKET_INPUT);
     124            m_socket_input_flag_enabled = false;
     125        }
    117126        if ( flags & wxSOCKET_OUTPUT_FLAG )
     127        {
    118128            manager->Uninstall_Callback(this, wxSOCKET_OUTPUT);
     129            m_socket_output_flag_enabled = false;
     130        }
    119131    }
    120132}
    121133
  • src/common/socket.cpp

     
    207207        wxASSERT_MSG( !m_socket->m_reading, "read reentrancy?" );
    208208
    209209        m_socket->m_reading = true;
     210
     211        m_reenable = m_socket->m_impl->IsEventEnabled(wxSOCKET_INPUT_FLAG);
    210212    }
    211213
    212214    ~wxSocketReadGuard()
     
    216218        // connection could have been lost while reading, in this case calling
    217219        // ReenableEvents() would assert and is not necessary anyhow
    218220        wxSocketImpl * const impl = m_socket->m_impl;
    219         if ( impl && impl->m_fd != INVALID_SOCKET )
     221        if ( m_reenable && impl && impl->m_fd != INVALID_SOCKET )
    220222            impl->ReenableEvents(wxSOCKET_INPUT_FLAG);
    221223    }
    222224
    223225private:
    224226    wxSocketBase * const m_socket;
    225227
     228    bool m_reenable;
     229
    226230    wxDECLARE_NO_COPY_CLASS(wxSocketReadGuard);
    227231};
    228232
     
    235239        wxASSERT_MSG( !m_socket->m_writing, "write reentrancy?" );
    236240
    237241        m_socket->m_writing = true;
     242
     243        m_reenable = m_socket->m_impl->IsEventEnabled(wxSOCKET_OUTPUT_FLAG);
    238244    }
    239245
    240246    ~wxSocketWriteGuard()
     
    242248        m_socket->m_writing = false;
    243249
    244250        wxSocketImpl * const impl = m_socket->m_impl;
    245         if ( impl && impl->m_fd != INVALID_SOCKET )
     251        if ( m_reenable && impl && impl->m_fd != INVALID_SOCKET )
    246252            impl->ReenableEvents(wxSOCKET_OUTPUT_FLAG);
    247253    }
    248254
    249255private:
    250256    wxSocketBase * const m_socket;
    251257
     258    bool m_reenable;
     259
    252260    wxDECLARE_NO_COPY_CLASS(wxSocketWriteGuard);
    253261};
    254262
  • include/wx/unix/private/sockunix.h

     
    3333    {
    3434        m_fds[0] =
    3535        m_fds[1] = -1;
     36
     37        m_socket_input_flag_enabled = false;
     38
     39        m_socket_output_flag_enabled = false;
    3640    }
    3741
    3842    virtual wxSocketError GetLastError() const;
     
    5458        EnableEvents(flags);
    5559    }
    5660
     61    virtual bool IsEventEnabled(wxSocketEventFlags flags)
     62    {
     63      if ((flags & wxSOCKET_INPUT_FLAG) && m_socket_input_flag_enabled)
     64      {
     65        return true;
     66      }
     67
     68      if ((flags & wxSOCKET_OUTPUT_FLAG) && m_socket_output_flag_enabled)
     69      {
     70        return true;
     71      }
     72
     73      return false;
     74    }
     75
    5776    // wxFDIOHandler methods
    5877    virtual void OnReadWaiting();
    5978    virtual void OnWriteWaiting();
     
    90109    // with the socket
    91110    int m_fds[2];
    92111
     112    bool m_socket_input_flag_enabled;
     113
     114    bool m_socket_output_flag_enabled;
     115
    93116private:
    94117    // notify the associated wxSocket about a change in socket state and shut
    95118    // down the socket if the event is wxSOCKET_LOST
  • include/wx/msw/private/sockmsw.h

     
    4747        // anything here
    4848    }
    4949
     50    virtual bool IsEventEnabled(wxSocketEventFlags flags)
     51    {
     52      // See comment in ReenableEvents: notifications are never disabled
     53      return true;
     54    }
     55
    5056private:
    5157    virtual void DoClose();
    5258
  • include/wx/private/socket.h

     
    290290    // turned off when this data was first detected
    291291    virtual void ReenableEvents(wxSocketEventFlags flags) = 0;
    292292
     293    virtual bool IsEventEnabled(wxSocketEventFlags flags) = 0;
     294
    293295    // TODO: make these fields protected and provide accessors for those of
    294296    //       them that wxSocketBase really needs
    295297//protected: