]> git.saurik.com Git - wxWidgets.git/commitdiff
move enabled callbacks flag down to wxSocketImplUnix from wxSocketImplFDIO, this...
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 28 Nov 2008 15:01:41 +0000 (15:01 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 28 Nov 2008 15:01:41 +0000 (15:01 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56999 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/unix/private/sockunix.h
src/common/socketiohandler.cpp

index 26b7f90d82f5653bb46745f7ad224e3790b01b8c..dd82c31045b934e318ba083d4432392149bc0af8 100644 (file)
@@ -27,6 +27,7 @@ public:
         m_fds[1] = -1;
 
         m_use_events = false;
+        m_enabledCallbacks = 0;
     }
 
     virtual void Shutdown();
@@ -42,6 +43,14 @@ public:
     virtual void OnWriteWaiting();
     virtual void OnExceptionWaiting();
 
+    // Unix-specific functions
+    bool HasAnyEnabledCallbacks() const { return m_enabledCallbacks != 0; }
+    void EnableCallback(wxFDIODispatcherEntryFlags flag)
+        { m_enabledCallbacks |= flag; }
+    void DisableCallback(wxFDIODispatcherEntryFlags flag)
+        { m_enabledCallbacks &= ~flag; }
+    int GetEnabledCallbacks() const { return m_enabledCallbacks; }
+
 private:
     virtual wxSocketError DoHandleConnect(int ret);
     virtual void DoClose()
@@ -99,6 +108,7 @@ private:
     int Send_Stream(const char *buffer, int size);
     int Send_Dgram(const char *buffer, int size);
 
+
 protected:
     // true if socket should fire events
     bool m_use_events;
@@ -107,6 +117,13 @@ protected:
     // with the socket
     int m_fds[2];
 
+    // the events which are currently enabled for this socket, combination of
+    // wxFDIO_INPUT and wxFDIO_OUTPUT values
+    //
+    // TODO: this overlaps with m_detected but the semantics of the latter are
+    //       very unclear so I don't dare to remove it right now
+    int m_enabledCallbacks;
+
 private:
     // notify the associated wxSocket about a change in socket state and shut
     // down the socket if the event is wxSOCKET_LOST
index 97af802a370fe28c11c25e6e840ebee047f824fe..87a9c457bbe463df86497dd252788e5d9ff08fbf 100644 (file)
 // implementation
 // ============================================================================
 
-// ----------------------------------------------------------------------------
-// wxSocketImplFDIO
-// ----------------------------------------------------------------------------
-
-class wxSocketImplFDIO : public wxSocketImplUnix
-{
-public:
-    wxSocketImplFDIO(wxSocketBase& wxsocket)
-        : wxSocketImplUnix(wxsocket)
-    {
-    }
-
-    int GetFlags() const { return m_flags; }
-    void RemoveFlag(wxFDIODispatcherEntryFlags flag) { m_flags &= ~flag; }
-    void AddFlag(wxFDIODispatcherEntryFlags flag) { m_flags |= flag; }
-
-private:
-    int m_flags;
-};
-
 // ----------------------------------------------------------------------------
 // wxSocketSelectManager
 // ----------------------------------------------------------------------------
@@ -56,11 +36,6 @@ private:
 class wxSocketSelectManager : public wxSocketFDBasedManager
 {
 public:
-    virtual wxSocketImpl *CreateSocket(wxSocketBase& wxsocket)
-    {
-        return new wxSocketImplFDIO(wxsocket);
-    }
-
     virtual void Install_Callback(wxSocketImpl *socket, wxSocketNotify event);
     virtual void Uninstall_Callback(wxSocketImpl *socket, wxSocketNotify event);
 };
@@ -68,7 +43,7 @@ public:
 void wxSocketSelectManager::Install_Callback(wxSocketImpl *socket_,
                                              wxSocketNotify event)
 {
-    wxSocketImplFDIO * const socket = static_cast<wxSocketImplFDIO *>(socket_);
+    wxSocketImplUnix * const socket = static_cast<wxSocketImplUnix *>(socket_);
 
     const int fd = socket->m_fd;
 
@@ -85,20 +60,20 @@ void wxSocketSelectManager::Install_Callback(wxSocketImpl *socket_,
 
     // register it when it's used for the first time, update it if it had been
     // previously registered
-    const bool registerHandler = socket->GetFlags() == 0;
+    const bool alreadyRegistered = socket->HasAnyEnabledCallbacks();
 
-    socket->AddFlag(d == FD_INPUT ? wxFDIO_INPUT : wxFDIO_OUTPUT);
+    socket->EnableCallback(d == FD_INPUT ? wxFDIO_INPUT : wxFDIO_OUTPUT);
 
-    if ( registerHandler )
-        dispatcher->RegisterFD(fd, socket, socket->GetFlags());
+    if ( alreadyRegistered )
+        dispatcher->ModifyFD(fd, socket, socket->GetEnabledCallbacks());
     else
-        dispatcher->ModifyFD(fd, socket, socket->GetFlags());
+        dispatcher->RegisterFD(fd, socket, socket->GetEnabledCallbacks());
 }
 
 void wxSocketSelectManager::Uninstall_Callback(wxSocketImpl *socket_,
                                                wxSocketNotify event)
 {
-    wxSocketImplFDIO * const socket = static_cast<wxSocketImplFDIO *>(socket_);
+    wxSocketImplUnix * const socket = static_cast<wxSocketImplUnix *>(socket_);
 
     const SocketDir d = GetDirForEvent(socket, event);
 
@@ -115,16 +90,12 @@ void wxSocketSelectManager::Uninstall_Callback(wxSocketImpl *socket_,
     if ( !dispatcher )
         return;
 
-    socket->RemoveFlag(flag);
+    socket->DisableCallback(flag);
 
-    if ( !socket->GetFlags() )
-    {
+    if ( !socket->HasAnyEnabledCallbacks() )
         dispatcher->UnregisterFD(fd);
-    }
     else
-    {
-        dispatcher->ModifyFD(fd, socket, socket->GetFlags());
-    }
+        dispatcher->ModifyFD(fd, socket, socket->GetEnabledCallbacks());
 }
 
 // set the wxBase variable to point to our wxSocketManager implementation