+// ---------------------------------------------------------------------------
+// helper struct and functions for socket handling
+// ---------------------------------------------------------------------------
+
+struct GsocketCallbackInfo{
+ void (*proc)(void *);
+ int type;
+ int handle;
+ void* gsock;
+};
+
+// These defines are used here and in gsockpm.cpp
+#define wxSockReadMask 0x01
+#define wxSockWriteMask 0x02
+
+void wxApp::HandleSockets()
+{
+ bool pendingEvent = false;
+
+ // Check whether it's time for Gsocket operation
+ if (m_maxSocketHandles > 0 && m_maxSocketNr > 0)
+ {
+ fd_set readfds = m_readfds;
+ fd_set writefds = m_writefds;
+ struct timeval timeout;
+ int i;
+ struct GsocketCallbackInfo
+ *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo;
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 0;
+ if ( select(m_maxSocketNr, &readfds, &writefds, 0, &timeout) > 0)
+ {
+ for (i = m_lastUsedHandle + 1; i != m_lastUsedHandle;
+ (i < m_maxSocketNr - 1) ? i++ : (i = 0))
+ {
+ if (FD_ISSET(i, &readfds))
+ {
+ int r;
+ for (r = 0; r < m_maxSocketHandles; r++){
+ if(CallbackInfo[r].handle == i &&
+ CallbackInfo[r].type == wxSockReadMask)
+ break;
+ }
+ if (r < m_maxSocketHandles)
+ {
+ CallbackInfo[r].proc(CallbackInfo[r].gsock);
+ pendingEvent = true;
+ }
+ }
+ if (FD_ISSET(i, &writefds))
+ {
+ int r;
+ for (r = 0; r < m_maxSocketHandles; r++)
+ if(CallbackInfo[r].handle == i &&
+ CallbackInfo[r].type == wxSockWriteMask)
+ break;
+ if (r < m_maxSocketHandles)
+ {
+ CallbackInfo[r].proc(CallbackInfo[r].gsock);
+ pendingEvent = true;
+ }
+ }
+ }
+ m_lastUsedHandle = i;
+ }
+ if (pendingEvent)
+ ProcessPendingEvents();
+ }
+}