]> git.saurik.com Git - wxWidgets.git/blame - src/common/socketiohandler.cpp
Workaround for #15404: wxRichTextCtrl: caret does not disappear when focus is lost...
[wxWidgets.git] / src / common / socketiohandler.cpp
CommitLineData
30c45bdd 1///////////////////////////////////////////////////////////////////////////////
86c5b12b 2// Name: src/common/socketiohandler.cpp
51fe4b60 3// Purpose: implementation of wxFDIOHandler for wxSocket
30c45bdd 4// Author: Angel Vidal, Lukasz Michalski
30c45bdd 5// Created: 08.24.06
30c45bdd 6// Copyright: (c) 2006 Angel vidal
2804f77d 7// (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
526954c5 8// Licence: wxWindows licence
30c45bdd
VZ
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19// for compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
b4715d08
VZ
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
6bcc1145 26#if wxUSE_SOCKETS
30c45bdd 27
6bcc1145 28#include "wx/app.h"
2804f77d 29#include "wx/apptrait.h"
a9d859df 30#include "wx/private/socket.h"
54e757fc 31#include "wx/link.h"
30c45bdd
VZ
32
33// ============================================================================
6bcc1145 34// wxSocketFDBasedManager implementation
30c45bdd
VZ
35// ============================================================================
36
6bcc1145 37bool wxSocketFDBasedManager::OnInit()
30c45bdd 38{
6bcc1145
VZ
39 wxAppTraits * const traits = wxApp::GetTraitsIfExists();
40 if ( !traits )
41 return false;
51fe4b60 42
6bcc1145
VZ
43 m_fdioManager = traits->GetFDIOManager();
44 return m_fdioManager != NULL;
45}
30c45bdd 46
6bcc1145
VZ
47void wxSocketFDBasedManager::Install_Callback(wxSocketImpl *socket_,
48 wxSocketNotify event)
49{
50 wxSocketImplUnix * const
51 socket = static_cast<wxSocketImplUnix *>(socket_);
30c45bdd 52
6bcc1145
VZ
53 wxCHECK_RET( socket->m_fd != -1,
54 "shouldn't be called on invalid socket" );
30c45bdd 55
6bcc1145 56 const wxFDIOManager::Direction d = GetDirForEvent(socket, event);
30c45bdd 57
6bcc1145
VZ
58 int& fd = FD(socket, d);
59 if ( fd != -1 )
60 m_fdioManager->RemoveInput(socket, fd, d);
30c45bdd 61
6bcc1145 62 fd = m_fdioManager->AddInput(socket, socket->m_fd, d);
30c45bdd
VZ
63}
64
6bcc1145
VZ
65void wxSocketFDBasedManager::Uninstall_Callback(wxSocketImpl *socket_,
66 wxSocketNotify event)
30c45bdd 67{
6bcc1145
VZ
68 wxSocketImplUnix * const
69 socket = static_cast<wxSocketImplUnix *>(socket_);
30c45bdd 70
6bcc1145 71 const wxFDIOManager::Direction d = GetDirForEvent(socket, event);
30c45bdd 72
6bcc1145
VZ
73 int& fd = FD(socket, d);
74 if ( fd != -1 )
75 {
76 m_fdioManager->RemoveInput(socket, fd, d);
77 fd = -1;
78 }
79}
a9d859df 80
6bcc1145
VZ
81wxFDIOManager::Direction
82wxSocketFDBasedManager::GetDirForEvent(wxSocketImpl *socket,
83 wxSocketNotify event)
84{
85 switch ( event )
86 {
87 default:
88 wxFAIL_MSG( "unknown socket event" );
89 return wxFDIOManager::INPUT; // we must return something
90
91 case wxSOCKET_LOST:
92 wxFAIL_MSG( "unexpected socket event" );
93 return wxFDIOManager::INPUT; // as above
94
95 case wxSOCKET_INPUT:
96 return wxFDIOManager::INPUT;
97
98 case wxSOCKET_OUTPUT:
99 return wxFDIOManager::OUTPUT;
100
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;
110 }
30c45bdd
VZ
111}
112
86c5b12b
VZ
113// set the wxBase variable to point to our wxSocketManager implementation
114//
115// see comments in wx/apptrait.h for the explanation of why do we do it
116// like this
117static struct ManagerSetter
30c45bdd 118{
86c5b12b
VZ
119 ManagerSetter()
120 {
6bcc1145 121 static wxSocketFDBasedManager s_manager;
86c5b12b
VZ
122 wxAppTraits::SetDefaultSocketManager(&s_manager);
123 }
124} gs_managerSetter;
30c45bdd 125
54e757fc
FM
126
127// see the relative linker macro in socket.cpp
128wxFORCE_LINK_THIS_MODULE( socketiohandler );
129
30c45bdd 130#endif // wxUSE_SOCKETS