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 // License: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
24 #include "wx/private/gsocketiohandler.h"
25 #include "wx/unix/private.h"
26 #include "wx/gsocket.h"
27 #include "wx/unix/gsockunx.h"
29 // ============================================================================
31 // ============================================================================
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 wxGSocketIOHandler::wxGSocketIOHandler(GSocket
* socket
)
44 void wxGSocketIOHandler::OnReadWaiting()
46 m_socket
->Detected_Read();
49 void wxGSocketIOHandler::OnWriteWaiting()
51 m_socket
->Detected_Write();
54 void wxGSocketIOHandler::OnExceptionWaiting()
56 m_socket
->Detected_Read();
59 int wxGSocketIOHandler::GetFlags() const
65 void wxGSocketIOHandler::RemoveFlag(wxFDIODispatcherEntryFlags flag
)
70 void wxGSocketIOHandler::AddFlag(wxFDIODispatcherEntryFlags flag
)
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
84 bool GSocketGUIFunctionsTableConcrete::OnInit()
89 void GSocketGUIFunctionsTableConcrete::OnExit()
93 bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket
*socket
)
97 socket
->m_gui_dependent
= (char *)malloc(sizeof(int)*2);
98 m_id
= (int *)(socket
->m_gui_dependent
);
106 void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket
*socket
)
108 free(socket
->m_gui_dependent
);
111 void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket
*socket
,
114 int *m_id
= (int *)(socket
->m_gui_dependent
);
115 const int fd
= socket
->m_fd
;
123 case GSOCK_LOST
: /* fall-through */
124 case GSOCK_INPUT
: c
= 0; break;
125 case GSOCK_OUTPUT
: c
= 1; break;
126 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
130 wxSelectDispatcher
* const dispatcher
= wxSelectDispatcher::Get();
135 handler
= (wxGSocketIOHandler
*)dispatcher
->FindHandler(fd
);
138 handler
= new wxGSocketIOHandler(socket
);
144 handler
->AddFlag(wxFDIO_INPUT
);
149 handler
->AddFlag(wxFDIO_OUTPUT
);
152 dispatcher
->RegisterFD(fd
, handler
, handler
->GetFlags());
155 void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket
*socket
,
158 int *m_id
= (int *)(socket
->m_gui_dependent
);
163 case GSOCK_LOST
: /* fall-through */
164 case GSOCK_INPUT
: c
= 0; break;
165 case GSOCK_OUTPUT
: c
= 1; break;
166 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
176 const wxFDIODispatcherEntryFlags flag
= c
== 0 ? wxFDIO_INPUT
: wxFDIO_OUTPUT
;
178 wxSelectDispatcher
* const dispatcher
= wxSelectDispatcher::Get();
182 wxGSocketIOHandler
* const
183 handler
= (wxGSocketIOHandler
*)dispatcher
->UnregisterFD(fd
, flag
);
186 handler
->RemoveFlag(flag
);
188 if ( !handler
->GetFlags() )
193 void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket
*socket
)
195 Install_Callback(socket
, GSOCK_INPUT
);
196 Install_Callback(socket
, GSOCK_OUTPUT
);
199 void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket
*socket
)
201 Uninstall_Callback(socket
, GSOCK_INPUT
);
202 Uninstall_Callback(socket
, GSOCK_OUTPUT
);
205 #endif // wxUSE_SOCKETS