1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/socketiohandler.cpp
3 // Purpose: implementation of wxFDIOHandler for wxSocket
4 // Author: Angel Vidal, Lukasz Michalski
6 // Copyright: (c) 2006 Angel vidal
7 // (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
29 #include "wx/apptrait.h"
30 #include "wx/private/socket.h"
33 // ============================================================================
34 // wxSocketFDBasedManager implementation
35 // ============================================================================
37 bool wxSocketFDBasedManager::OnInit()
39 wxAppTraits
* const traits
= wxApp::GetTraitsIfExists();
43 m_fdioManager
= traits
->GetFDIOManager();
44 return m_fdioManager
!= NULL
;
47 void wxSocketFDBasedManager::Install_Callback(wxSocketImpl
*socket_
,
50 wxSocketImplUnix
* const
51 socket
= static_cast<wxSocketImplUnix
*>(socket_
);
53 wxCHECK_RET( socket
->m_fd
!= -1,
54 "shouldn't be called on invalid socket" );
56 const wxFDIOManager::Direction d
= GetDirForEvent(socket
, event
);
58 int& fd
= FD(socket
, d
);
60 m_fdioManager
->RemoveInput(socket
, fd
, d
);
62 fd
= m_fdioManager
->AddInput(socket
, socket
->m_fd
, d
);
65 void wxSocketFDBasedManager::Uninstall_Callback(wxSocketImpl
*socket_
,
68 wxSocketImplUnix
* const
69 socket
= static_cast<wxSocketImplUnix
*>(socket_
);
71 const wxFDIOManager::Direction d
= GetDirForEvent(socket
, event
);
73 int& fd
= FD(socket
, d
);
76 m_fdioManager
->RemoveInput(socket
, fd
, d
);
81 wxFDIOManager::Direction
82 wxSocketFDBasedManager::GetDirForEvent(wxSocketImpl
*socket
,
88 wxFAIL_MSG( "unknown socket event" );
89 return wxFDIOManager::INPUT
; // we must return something
92 wxFAIL_MSG( "unexpected socket event" );
93 return wxFDIOManager::INPUT
; // as above
96 return wxFDIOManager::INPUT
;
99 return wxFDIOManager::OUTPUT
;
101 case wxSOCKET_CONNECTION
:
102 // for server sockets we're interested in events indicating
103 // that a new connection is pending, i.e. that accept() will
104 // succeed and this is indicated by socket becoming ready for
105 // reading, while for the other ones we're interested in the
106 // completion of non-blocking connect() which is indicated by
107 // the socket becoming ready for writing
108 return socket
->IsServer() ? wxFDIOManager::INPUT
109 : wxFDIOManager::OUTPUT
;
113 // set the wxBase variable to point to our wxSocketManager implementation
115 // see comments in wx/apptrait.h for the explanation of why do we do it
117 static struct ManagerSetter
121 static wxSocketFDBasedManager s_manager
;
122 wxAppTraits::SetDefaultSocketManager(&s_manager
);
127 // see the relative linker macro in socket.cpp
128 wxFORCE_LINK_THIS_MODULE( socketiohandler
);
130 #endif // wxUSE_SOCKETS