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 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/apptrait.h"
31 #include "wx/private/socket.h"
34 // ============================================================================
35 // wxSocketFDBasedManager implementation
36 // ============================================================================
38 bool wxSocketFDBasedManager::OnInit()
40 wxAppTraits
* const traits
= wxApp::GetTraitsIfExists();
44 m_fdioManager
= traits
->GetFDIOManager();
45 return m_fdioManager
!= NULL
;
48 void wxSocketFDBasedManager::Install_Callback(wxSocketImpl
*socket_
,
51 wxSocketImplUnix
* const
52 socket
= static_cast<wxSocketImplUnix
*>(socket_
);
54 wxCHECK_RET( socket
->m_fd
!= -1,
55 "shouldn't be called on invalid socket" );
57 const wxFDIOManager::Direction d
= GetDirForEvent(socket
, event
);
59 int& fd
= FD(socket
, d
);
61 m_fdioManager
->RemoveInput(socket
, fd
, d
);
63 fd
= m_fdioManager
->AddInput(socket
, socket
->m_fd
, d
);
66 void wxSocketFDBasedManager::Uninstall_Callback(wxSocketImpl
*socket_
,
69 wxSocketImplUnix
* const
70 socket
= static_cast<wxSocketImplUnix
*>(socket_
);
72 const wxFDIOManager::Direction d
= GetDirForEvent(socket
, event
);
74 int& fd
= FD(socket
, d
);
77 m_fdioManager
->RemoveInput(socket
, fd
, d
);
82 wxFDIOManager::Direction
83 wxSocketFDBasedManager::GetDirForEvent(wxSocketImpl
*socket
,
89 wxFAIL_MSG( "unknown socket event" );
90 return wxFDIOManager::INPUT
; // we must return something
93 wxFAIL_MSG( "unexpected socket event" );
94 return wxFDIOManager::INPUT
; // as above
97 return wxFDIOManager::INPUT
;
100 return wxFDIOManager::OUTPUT
;
102 case wxSOCKET_CONNECTION
:
103 // for server sockets we're interested in events indicating
104 // that a new connection is pending, i.e. that accept() will
105 // succeed and this is indicated by socket becoming ready for
106 // reading, while for the other ones we're interested in the
107 // completion of non-blocking connect() which is indicated by
108 // the socket becoming ready for writing
109 return socket
->IsServer() ? wxFDIOManager::INPUT
110 : wxFDIOManager::OUTPUT
;
114 // set the wxBase variable to point to our wxSocketManager implementation
116 // see comments in wx/apptrait.h for the explanation of why do we do it
118 static struct ManagerSetter
122 static wxSocketFDBasedManager s_manager
;
123 wxAppTraits::SetDefaultSocketManager(&s_manager
);
128 // see the relative linker macro in socket.cpp
129 wxFORCE_LINK_THIS_MODULE( socketiohandler
);
131 #endif // wxUSE_SOCKETS