1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/gsocketiohandler.cpp
3 // Purpose: implementation of wxFDIOHandler for GSocket
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/unix/private.h"
27 #include "wx/private/gsocketiohandler.h"
29 // ============================================================================
31 // ============================================================================
33 // ----------------------------------------------------------------------------
34 // GSocketSelectManager
35 // ----------------------------------------------------------------------------
37 class GSocketSelectManager
: public GSocketFDBasedManager
40 virtual void Install_Callback(GSocket
*socket
, GSocketEvent event
);
41 virtual void Uninstall_Callback(GSocket
*socket
, GSocketEvent event
);
44 void GSocketSelectManager::Install_Callback(GSocket
*socket
,
47 const int fd
= socket
->m_fd
;
52 const SocketDir d
= GetDirForEvent(socket
, event
);
54 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
58 wxGSocketIOHandler
*& handler
= socket
->m_handler
;
60 // we should register the new handlers but modify the existing ones in place
64 registerHandler
= false;
66 else // no existing handler
68 registerHandler
= true;
69 handler
= new wxGSocketIOHandler(socket
);
75 handler
->AddFlag(wxFDIO_INPUT
);
79 handler
->AddFlag(wxFDIO_OUTPUT
);
82 if ( registerHandler
)
83 dispatcher
->RegisterFD(fd
, handler
, handler
->GetFlags());
85 dispatcher
->ModifyFD(fd
, handler
, handler
->GetFlags());
88 void GSocketSelectManager::Uninstall_Callback(GSocket
*socket
,
91 const SocketDir d
= GetDirForEvent(socket
, event
);
93 const int fd
= FD(socket
, d
);
99 const wxFDIODispatcherEntryFlags
100 flag
= d
== FD_INPUT
? wxFDIO_INPUT
: wxFDIO_OUTPUT
;
102 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
106 wxGSocketIOHandler
*& handler
= socket
->m_handler
;
109 handler
->RemoveFlag(flag
);
111 if ( !handler
->GetFlags() )
113 dispatcher
->UnregisterFD(fd
);
115 socket
->m_handler
= NULL
;
119 dispatcher
->ModifyFD(fd
, handler
, handler
->GetFlags());
124 dispatcher
->UnregisterFD(fd
);
128 GSocketManager
*wxAppTraits::GetSocketManager()
130 static GSocketSelectManager s_manager
;
135 #endif // wxUSE_SOCKETS