X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a9d859df6f433c962a9ed777d2c26da6ce714441..c437b3f4e47b74715a2f2385d4862972babd7802:/src/common/socketiohandler.cpp?ds=sidebyside diff --git a/src/common/socketiohandler.cpp b/src/common/socketiohandler.cpp index 97af802a37..080532be0f 100644 --- a/src/common/socketiohandler.cpp +++ b/src/common/socketiohandler.cpp @@ -24,51 +24,27 @@ #include "wx/apptrait.h" #include "wx/private/socket.h" +#include "wx/link.h" // ============================================================================ // implementation // ============================================================================ // ---------------------------------------------------------------------------- -// wxSocketImplFDIO +// wxSocketFDIOManager: socket manager using wxFDIODispatcher // ---------------------------------------------------------------------------- -class wxSocketImplFDIO : public wxSocketImplUnix +class wxSocketFDIOManager : public wxSocketFDBasedManager { 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 -// ---------------------------------------------------------------------------- - -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); }; -void wxSocketSelectManager::Install_Callback(wxSocketImpl *socket_, +void wxSocketFDIOManager::Install_Callback(wxSocketImpl *socket_, wxSocketNotify event) { - wxSocketImplFDIO * const socket = static_cast(socket_); + wxSocketImplUnix * const socket = static_cast(socket_); const int fd = socket->m_fd; @@ -85,20 +61,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_, +void wxSocketFDIOManager::Uninstall_Callback(wxSocketImpl *socket_, wxSocketNotify event) { - wxSocketImplFDIO * const socket = static_cast(socket_); + wxSocketImplUnix * const socket = static_cast(socket_); const SocketDir d = GetDirForEvent(socket, event); @@ -115,16 +91,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 @@ -135,9 +107,13 @@ static struct ManagerSetter { ManagerSetter() { - static wxSocketSelectManager s_manager; + static wxSocketFDIOManager s_manager; wxAppTraits::SetDefaultSocketManager(&s_manager); } } gs_managerSetter; + +// see the relative linker macro in socket.cpp +wxFORCE_LINK_THIS_MODULE( socketiohandler ); + #endif // wxUSE_SOCKETS