1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/gsocketiohandler.cpp
3 // Purpose: implementation of wxFDIOHandler for GSocket
4 // Author: Angel Vidal, Lukasz Michalski
8 // Copyright: (c) 2006 Angel vidal
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
25 #include "wx/private/gsocketiohandler.h"
26 #include "wx/unix/private.h"
27 #include "wx/gsocket.h"
28 #include "wx/unix/gsockunx.h"
30 // ============================================================================
32 // ============================================================================
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 wxGSocketIOHandler::wxGSocketIOHandler(GSocket
* socket
)
45 void wxGSocketIOHandler::OnReadWaiting(int fd
)
47 m_socket
->Detected_Read();
50 void wxGSocketIOHandler::OnWriteWaiting(int fd
)
52 m_socket
->Detected_Write();
55 void wxGSocketIOHandler::OnExceptionWaiting(int fd
)
57 m_socket
->Detected_Read();
60 int wxGSocketIOHandler::GetFlags() const
66 void wxGSocketIOHandler::RemoveFlag(wxSelectDispatcherEntryFlags flag
)
71 void wxGSocketIOHandler::AddFlag(wxSelectDispatcherEntryFlags flag
)
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
85 bool GSocketGUIFunctionsTableConcrete::OnInit()
90 void GSocketGUIFunctionsTableConcrete::OnExit()
94 bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket
*socket
)
98 socket
->m_gui_dependent
= (char *)malloc(sizeof(int)*2);
99 m_id
= (int *)(socket
->m_gui_dependent
);
107 void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket
*socket
)
109 free(socket
->m_gui_dependent
);
112 void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket
*socket
,
115 int *m_id
= (int *)(socket
->m_gui_dependent
);
118 if (socket
->m_fd
== -1)
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 wxGSocketIOHandler
* handler
= (wxGSocketIOHandler
*)(wxSelectDispatcher::Get().FindHandler(socket
->m_fd
));
133 handler
= new wxGSocketIOHandler(socket
);
138 m_id
[0] = socket
->m_fd
;
139 handler
->AddFlag(wxSelectInput
);
143 m_id
[1] = socket
->m_fd
;
144 handler
->AddFlag(wxSelectOutput
);
147 wxSelectDispatcher::Get().RegisterFD(socket
->m_fd
,handler
,handler
->GetFlags());
150 void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket
*socket
,
153 int *m_id
= (int *)(socket
->m_gui_dependent
);
158 case GSOCK_LOST
: /* fall-through */
159 case GSOCK_INPUT
: c
= 0; break;
160 case GSOCK_OUTPUT
: c
= 1; break;
161 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
165 wxGSocketIOHandler
* handler
= NULL
;
170 handler
= (wxGSocketIOHandler
*)wxSelectDispatcher::Get().UnregisterFD(m_id
[c
], wxSelectInput
);
172 handler
->RemoveFlag(wxSelectInput
);
176 handler
= (wxGSocketIOHandler
*)wxSelectDispatcher::Get().UnregisterFD(m_id
[c
], wxSelectOutput
);
178 handler
->RemoveFlag(wxSelectOutput
);
180 if (handler
&& handler
->GetFlags() == 0)
187 void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket
*socket
)
189 Install_Callback(socket
, GSOCK_INPUT
);
190 Install_Callback(socket
, GSOCK_OUTPUT
);
193 void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket
*socket
)
195 Uninstall_Callback(socket
, GSOCK_INPUT
);
196 Uninstall_Callback(socket
, GSOCK_OUTPUT
);
199 #endif // wxUSE_SOCKETS