1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/socketiohandler.cpp
3 // Purpose: implementation of wxFDIOHandler for wxSocket
4 // Author: Angel Vidal, Lukasz Michalski
7 // Copyright: (c) 2006 Angel vidal
8 // (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_SOCKETS && wxUSE_SELECT_DISPATCHER
29 #include "wx/apptrait.h"
30 #include "wx/private/socket.h"
33 // ============================================================================
35 // ============================================================================
37 // ----------------------------------------------------------------------------
38 // wxSocketFDIOManager: socket manager using wxFDIODispatcher
39 // ----------------------------------------------------------------------------
41 class wxSocketFDIOManager
: public wxSocketFDBasedManager
44 virtual void Install_Callback(wxSocketImpl
*socket
, wxSocketNotify event
);
45 virtual void Uninstall_Callback(wxSocketImpl
*socket
, wxSocketNotify event
);
48 void wxSocketFDIOManager::Install_Callback(wxSocketImpl
*socket_
,
51 wxSocketImplUnix
* const socket
= static_cast<wxSocketImplUnix
*>(socket_
);
53 const int fd
= socket
->m_fd
;
58 const SocketDir d
= GetDirForEvent(socket
, event
);
60 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
66 // register it when it's used for the first time, update it if it had been
67 // previously registered
68 const bool alreadyRegistered
= socket
->HasAnyEnabledCallbacks();
70 socket
->EnableCallback(d
== FD_INPUT
? wxFDIO_INPUT
: wxFDIO_OUTPUT
);
72 if ( alreadyRegistered
)
73 dispatcher
->ModifyFD(fd
, socket
, socket
->GetEnabledCallbacks());
75 dispatcher
->RegisterFD(fd
, socket
, socket
->GetEnabledCallbacks());
78 void wxSocketFDIOManager::Uninstall_Callback(wxSocketImpl
*socket_
,
81 wxSocketImplUnix
* const socket
= static_cast<wxSocketImplUnix
*>(socket_
);
83 const SocketDir d
= GetDirForEvent(socket
, event
);
85 const int fd
= FD(socket
, d
);
91 const wxFDIODispatcherEntryFlags
92 flag
= d
== FD_INPUT
? wxFDIO_INPUT
: wxFDIO_OUTPUT
;
94 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
98 socket
->DisableCallback(flag
);
100 if ( !socket
->HasAnyEnabledCallbacks() )
101 dispatcher
->UnregisterFD(fd
);
103 dispatcher
->ModifyFD(fd
, socket
, socket
->GetEnabledCallbacks());
106 // set the wxBase variable to point to our wxSocketManager implementation
108 // see comments in wx/apptrait.h for the explanation of why do we do it
110 static struct ManagerSetter
114 static wxSocketFDIOManager s_manager
;
115 wxAppTraits::SetDefaultSocketManager(&s_manager
);
120 // see the relative linker macro in socket.cpp
121 wxFORCE_LINK_THIS_MODULE( socketiohandler
);
123 #endif // wxUSE_SOCKETS