-bool wxSocketClient::WaitOnConnect(long seconds, long microseconds)
-{
- int ret = _Wait(seconds, microseconds, REQ_CONNECT | REQ_LOST);
-
- if (ret)
- m_connected = TRUE;
-
- return m_connected;
-}
-
-void wxSocketClient::OnRequest(wxRequestEvent evt)
-{
- if (evt == EVT_CONNECT)
- {
- if (m_connected)
- {
-#ifndef __WXGTK__
- SetNotify(m_neededreq & ~REQ_CONNECT);
-#endif
- return;
- }
- m_waitflags = 0x40;
- m_connected = TRUE;
- OldOnNotify(EVT_CONNECT);
-#ifndef __WXGTK__
- DestroyCallbacks();
-#endif
- return;
- }
- wxSocketBase::OnRequest(evt);
-}
-
-/////////////////////////////////////////////////////////////////
-// wxSocketHandler ///////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////
-
-wxSocketHandler *wxSocketHandler::master = NULL;
-#if defined(__WINDOWS__)
-static int win_initialized = 0;
-#endif
-
-// --------------------------------------------------------------
-// --------- wxSocketHandler CONSTRUCTOR ------------------------
-// --------------------------------------------------------------
-#ifdef __WXMAC__
-
-extern "C" int updatestatus(int s) ;
-
-void wxMacSocketOnRequestProc( void *refcon , short event )
-{
- if ( refcon )
- {
- wxSocketBase *sock = (wxSocketBase *) refcon ;
-
- wxSocketBase::wxRequestEvent sk_req;
-
- int canRead ;
- int canWrite ;
- int exception ;
-
- switch (event) {
- case FD_READ:
- sk_req = wxSocketBase::EVT_READ;
- sock->OnRequest(sk_req);
- break;
- case FD_WRITE:
- sk_req = wxSocketBase::EVT_WRITE;
- sock->OnRequest(sk_req);
- break;
- case FD_CLOSE:
- sk_req = wxSocketBase::EVT_LOST;
- sock->OnRequest(sk_req);
- break;
- case FD_ACCEPT:
- sk_req = wxSocketBase::EVT_ACCEPT;
- sock->OnRequest(sk_req);
- break;
- case FD_CONNECT:
- sk_req = wxSocketBase::EVT_CONNECT;
- sock->OnRequest(sk_req);
- break;
- case FD_READY :
- break ;
- }
- updatestatus ( sock->m_fd ) ;
- }
-}
-
-void wxMacSocketHandlerProc( void *refcon , short event )
-{
- wxMacNetEventsReferences[wxMacNetEventsTop] = refcon ;
- wxMacNetEventsEvents[wxMacNetEventsTop] = event ;
-
- // clumsy construct in order to never have a incorrect wxMacNetEventsTop (above limits)
-
- if ( wxMacNetEventsTop + 1 == kwxMacNetEventsMax )
- wxMacNetEventsTop = 0 ;
- else
- wxMacNetEventsTop++ ;
-}
-
-#endif
-#ifdef __WINDOWS__
-
-extern char wxPanelClassName[];
-
-LRESULT APIENTRY _EXPORT wxSocketHandlerWndProc(HWND hWnd, UINT message,
- WPARAM wParam, LPARAM lParam)
-{
- if(message==WM_DESTROY)
- {
- ::SetWindowLong(hWnd, GWL_WNDPROC, (LONG) DefWindowProc);
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- wxSocketHandler *h_sock = (wxSocketHandler *)GetWindowLong(hWnd, GWL_USERDATA);
- wxNode *node = h_sock->smsg_list->Find(message);
- wxSocketBase *sock;
- wxSocketBase::wxRequestEvent sk_req;
- UINT event = WSAGETSELECTEVENT(lParam);
-
- if (!node)
- return DefWindowProc(hWnd, message, wParam, lParam);
-
- sock = (wxSocketBase *)node->Data();
-
- switch (event) {
- case FD_READ:
- sk_req = wxSocketBase::EVT_READ;
- break;
- case FD_WRITE:
- sk_req = wxSocketBase::EVT_WRITE;
- break;
- case FD_CLOSE:
- sk_req = wxSocketBase::EVT_LOST;
- break;
- case FD_ACCEPT:
- sk_req = wxSocketBase::EVT_ACCEPT;
- break;
- case FD_CONNECT:
- sk_req = wxSocketBase::EVT_CONNECT;
- break;
-
- default:
- wxFAIL_MSG("invalid socket event");
- return (LRESULT)0;
- }
-
- sock->OnRequest(sk_req);
-
- return (LRESULT)0;
-}
-
-FARPROC wxSocketSubClassProc = NULL;
-
-#endif
-
-wxSocketHandler::wxSocketHandler()
-{
-#if defined(__WINDOWS__)
- if (!win_initialized)
- {
- WSADATA wsaData;
-
- WSAStartup((1 << 8) | 1, &wsaData);
- win_initialized = 1;
- }
- internal = new wxSockHandlerInternal;
- internal->sockWin = ::CreateWindow(wxPanelClassName, NULL, 0,
- 0, 0, 0, 0, NULL, (HMENU) NULL,
- wxhInstance, 0);
-
- // Subclass the window
- if (!wxSocketSubClassProc)
- wxSocketSubClassProc = MakeProcInstance((FARPROC) wxSocketHandlerWndProc, wxhInstance);
- ::SetWindowLong(internal->sockWin, GWL_WNDPROC, (LONG) wxSocketSubClassProc);
- ::SetWindowLong(internal->sockWin, GWL_USERDATA, (LONG) this);
-
- internal->firstAvailableMsg = 5000;
- smsg_list = new wxList(wxKEY_INTEGER);
-#endif
-
- socks = new wxList;
-
-#ifndef __WINDOWS__
- signal(SIGPIPE, SIG_IGN);
-#endif
-}
-
-// --------------------------------------------------------------
-// --------- wxSocketHandler DESTRUCTOR -------------------------
-// --------------------------------------------------------------
-wxSocketHandler::~wxSocketHandler()