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"
28 // ============================================================================
30 // ============================================================================
32 // ----------------------------------------------------------------------------
33 // wxSocketFDIOManager: socket manager using wxFDIODispatcher
34 // ----------------------------------------------------------------------------
36 class wxSocketFDIOManager
: public wxSocketFDBasedManager
39 virtual void Install_Callback(wxSocketImpl
*socket
, wxSocketNotify event
);
40 virtual void Uninstall_Callback(wxSocketImpl
*socket
, wxSocketNotify event
);
43 void wxSocketFDIOManager::Install_Callback(wxSocketImpl
*socket_
,
46 wxSocketImplUnix
* const socket
= static_cast<wxSocketImplUnix
*>(socket_
);
48 const int fd
= socket
->m_fd
;
53 const SocketDir d
= GetDirForEvent(socket
, event
);
55 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
61 // register it when it's used for the first time, update it if it had been
62 // previously registered
63 const bool alreadyRegistered
= socket
->HasAnyEnabledCallbacks();
65 socket
->EnableCallback(d
== FD_INPUT
? wxFDIO_INPUT
: wxFDIO_OUTPUT
);
67 if ( alreadyRegistered
)
68 dispatcher
->ModifyFD(fd
, socket
, socket
->GetEnabledCallbacks());
70 dispatcher
->RegisterFD(fd
, socket
, socket
->GetEnabledCallbacks());
73 void wxSocketFDIOManager::Uninstall_Callback(wxSocketImpl
*socket_
,
76 wxSocketImplUnix
* const socket
= static_cast<wxSocketImplUnix
*>(socket_
);
78 const SocketDir d
= GetDirForEvent(socket
, event
);
80 const int fd
= FD(socket
, d
);
86 const wxFDIODispatcherEntryFlags
87 flag
= d
== FD_INPUT
? wxFDIO_INPUT
: wxFDIO_OUTPUT
;
89 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
93 socket
->DisableCallback(flag
);
95 if ( !socket
->HasAnyEnabledCallbacks() )
96 dispatcher
->UnregisterFD(fd
);
98 dispatcher
->ModifyFD(fd
, socket
, socket
->GetEnabledCallbacks());
101 // set the wxBase variable to point to our wxSocketManager implementation
103 // see comments in wx/apptrait.h for the explanation of why do we do it
105 static struct ManagerSetter
109 static wxSocketFDIOManager s_manager
;
110 wxAppTraits::SetDefaultSocketManager(&s_manager
);
114 #endif // wxUSE_SOCKETS