]> git.saurik.com Git - wxWidgets.git/blame - src/common/gsocketiohandler.cpp
Fix tracking rectangles in 64-bit build by remembering the tag as the 64-bit integer...
[wxWidgets.git] / src / common / gsocketiohandler.cpp
CommitLineData
30c45bdd
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/common/gsocketiohandler.cpp
3// Purpose: implementation of wxFDIOHandler for GSocket
4// Author: Angel Vidal, Lukasz Michalski
30c45bdd
VZ
5// Created: 08.24.06
6// RCS-ID: $Id$
7// Copyright: (c) 2006 Angel vidal
2804f77d 8// (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
30c45bdd
VZ
9// License: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// for compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
a1873279 23#if wxUSE_SOCKETS && wxUSE_SELECT_DISPATCHER
30c45bdd 24
2804f77d 25#include "wx/apptrait.h"
30c45bdd 26#include "wx/unix/private.h"
2804f77d 27#include "wx/private/gsocketiohandler.h"
30c45bdd
VZ
28
29// ============================================================================
30// implementation
31// ============================================================================
32
33// ----------------------------------------------------------------------------
2804f77d 34// GSocketSelectManager
30c45bdd
VZ
35// ----------------------------------------------------------------------------
36
2804f77d 37class GSocketSelectManager : public GSocketFDBasedManager
30c45bdd 38{
2804f77d
VZ
39public:
40 virtual void Install_Callback(GSocket *socket, GSocketEvent event);
41 virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event);
42};
30c45bdd 43
2804f77d
VZ
44void GSocketSelectManager::Install_Callback(GSocket *socket,
45 GSocketEvent event)
30c45bdd 46{
2804f77d 47 const int fd = socket->m_fd;
30c45bdd 48
2804f77d
VZ
49 if ( fd == -1 )
50 return;
30c45bdd 51
2804f77d 52 const SocketDir d = GetDirForEvent(socket, event);
30c45bdd 53
2804f77d
VZ
54 wxFDIODispatcher * const dispatcher = wxFDIODispatcher::Get();
55 if ( !dispatcher )
56 return;
30c45bdd 57
2804f77d 58 wxGSocketIOHandler *& handler = socket->m_handler;
30c45bdd 59
2804f77d
VZ
60 // we should register the new handlers but modify the existing ones in place
61 bool registerHandler;
62 if ( handler )
63 {
64 registerHandler = false;
65 }
66 else // no existing handler
67 {
68 registerHandler = true;
69 handler = new wxGSocketIOHandler(socket);
70 }
30c45bdd 71
2804f77d
VZ
72 FD(socket, d) = fd;
73 if (d == FD_INPUT)
74 {
75 handler->AddFlag(wxFDIO_INPUT);
76 }
77 else
78 {
79 handler->AddFlag(wxFDIO_OUTPUT);
80 }
30c45bdd 81
2804f77d
VZ
82 if ( registerHandler )
83 dispatcher->RegisterFD(fd, handler, handler->GetFlags());
84 else
85 dispatcher->ModifyFD(fd, handler, handler->GetFlags());
30c45bdd
VZ
86}
87
2804f77d
VZ
88void GSocketSelectManager::Uninstall_Callback(GSocket *socket,
89 GSocketEvent event)
30c45bdd 90{
2804f77d 91 const SocketDir d = GetDirForEvent(socket, event);
30c45bdd 92
2804f77d
VZ
93 const int fd = FD(socket, d);
94 if ( fd == -1 )
95 return;
30c45bdd 96
2804f77d 97 FD(socket, d) = -1;
30c45bdd 98
2804f77d
VZ
99 const wxFDIODispatcherEntryFlags
100 flag = d == FD_INPUT ? wxFDIO_INPUT : wxFDIO_OUTPUT;
30c45bdd 101
2804f77d
VZ
102 wxFDIODispatcher * const dispatcher = wxFDIODispatcher::Get();
103 if ( !dispatcher )
104 return;
30c45bdd 105
2804f77d
VZ
106 wxGSocketIOHandler *& handler = socket->m_handler;
107 if ( handler )
108 {
109 handler->RemoveFlag(flag);
30c45bdd 110
2804f77d
VZ
111 if ( !handler->GetFlags() )
112 {
113 dispatcher->UnregisterFD(fd);
114 delete handler;
115 socket->m_handler = NULL;
116 }
117 else
118 {
119 dispatcher->ModifyFD(fd, handler, handler->GetFlags());
120 }
121 }
122 else
123 {
124 dispatcher->UnregisterFD(fd);
125 }
30c45bdd
VZ
126}
127
2804f77d 128GSocketManager *wxAppTraits::GetSocketManager()
30c45bdd 129{
2804f77d 130 static GSocketSelectManager s_manager;
30c45bdd 131
2804f77d 132 return &s_manager;
30c45bdd
VZ
133}
134
135#endif // wxUSE_SOCKETS