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"
23 #if wxUSE_SOCKETS && wxUSE_SELECT_DISPATCHER
25 #include "wx/apptrait.h"
26 #include "wx/private/socket.h"
29 // ============================================================================
31 // ============================================================================
33 // ----------------------------------------------------------------------------
34 // wxSocketFDIOManager: socket manager using wxFDIODispatcher
35 // ----------------------------------------------------------------------------
37 class wxSocketFDIOManager
: public wxSocketFDBasedManager
40 virtual void Install_Callback(wxSocketImpl
*socket
, wxSocketNotify event
);
41 virtual void Uninstall_Callback(wxSocketImpl
*socket
, wxSocketNotify event
);
44 void wxSocketFDIOManager::Install_Callback(wxSocketImpl
*socket_
,
47 wxSocketImplUnix
* const socket
= static_cast<wxSocketImplUnix
*>(socket_
);
49 const int fd
= socket
->m_fd
;
54 const SocketDir d
= GetDirForEvent(socket
, event
);
56 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
62 // register it when it's used for the first time, update it if it had been
63 // previously registered
64 const bool alreadyRegistered
= socket
->HasAnyEnabledCallbacks();
66 socket
->EnableCallback(d
== FD_INPUT
? wxFDIO_INPUT
: wxFDIO_OUTPUT
);
68 if ( alreadyRegistered
)
69 dispatcher
->ModifyFD(fd
, socket
, socket
->GetEnabledCallbacks());
71 dispatcher
->RegisterFD(fd
, socket
, socket
->GetEnabledCallbacks());
74 void wxSocketFDIOManager::Uninstall_Callback(wxSocketImpl
*socket_
,
77 wxSocketImplUnix
* const socket
= static_cast<wxSocketImplUnix
*>(socket_
);
79 const SocketDir d
= GetDirForEvent(socket
, event
);
81 const int fd
= FD(socket
, d
);
87 const wxFDIODispatcherEntryFlags
88 flag
= d
== FD_INPUT
? wxFDIO_INPUT
: wxFDIO_OUTPUT
;
90 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
94 socket
->DisableCallback(flag
);
96 if ( !socket
->HasAnyEnabledCallbacks() )
97 dispatcher
->UnregisterFD(fd
);
99 dispatcher
->ModifyFD(fd
, socket
, socket
->GetEnabledCallbacks());
102 // set the wxBase variable to point to our wxSocketManager implementation
104 // see comments in wx/apptrait.h for the explanation of why do we do it
106 static struct ManagerSetter
110 static wxSocketFDIOManager s_manager
;
111 wxAppTraits::SetDefaultSocketManager(&s_manager
);
116 // see the relative linker macro in socket.cpp
117 wxFORCE_LINK_THIS_MODULE( socketiohandler
);
119 #endif // wxUSE_SOCKETS