-/* This needs to be before the wx/defs/h inclusion
- * for some reason
- */
-
-#ifdef __WXWINCE__
- /* windows.h results in tons of warnings at max warning level */
-# ifdef _MSC_VER
-# pragma warning(push, 1)
-# endif
-# include <windows.h>
-# ifdef _MSC_VER
-# pragma warning(pop)
-# pragma warning(disable:4514)
-# endif
-#endif
-
-#ifndef __GSOCKET_STANDALONE__
-# include "wx/platform.h"
-# include "wx/setup.h"
-#endif
-
-#if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
-
-#ifndef __GSOCKET_STANDALONE__
-
-#include "wx/msw/gsockmsw.h"
typedef int (PASCAL *WSAEventSelectFunc)(SOCKET,HANDLE,long);
typedef int (PASCAL *WSAWaitForMultipleEventsFunc)(long,HANDLE,BOOL,long,BOOL);
typedef int (PASCAL *WSAEnumNetworkEventsFunc)(SOCKET,HANDLE,LPWSANETWORKEVENTS);
typedef int (PASCAL *WSAEventSelectFunc)(SOCKET,HANDLE,long);
typedef int (PASCAL *WSAWaitForMultipleEventsFunc)(long,HANDLE,BOOL,long,BOOL);
typedef int (PASCAL *WSAEnumNetworkEventsFunc)(SOCKET,HANDLE,LPWSANETWORKEVENTS);
- WSANETWORKEVENTS NetworkEvents;
- thread_data* d = (thread_data *)data;
-
- HANDLE NetworkEvent = gs_WSACreateEvent();
- gs_WSAEventSelect(d->fd, NetworkEvent, d->lEvent);
-
- while(socketHash[d->fd] == true)
- {
- if ((gs_WSAWaitForMultipleEvents(1, &NetworkEvent, FALSE,INFINITE, FALSE)) == WAIT_FAILED)
- {
- printf("WSAWaitForMultipleEvents failed with error %d\n", WSAGetLastError());
- return 0;
- }
- if (gs_WSAEnumNetworkEvents(d->fd ,NetworkEvent, &NetworkEvents) == SOCKET_ERROR)
- {
- printf("WSAEnumNetworkEvents failed with error %d\n", WSAGetLastError());
- return 0;
- }
-
- long flags = NetworkEvents.lNetworkEvents;
- if (flags & FD_READ)
- ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_READ);
- if (flags & FD_WRITE)
- ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_WRITE);
- if (flags & FD_OOB)
- ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_OOB);
- if (flags & FD_ACCEPT)
- ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_ACCEPT);
- if (flags & FD_CONNECT)
- ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_CONNECT);
- if (flags & FD_CLOSE)
- ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_CLOSE);
-
- }
- gs_WSAEventSelect(d->fd, NetworkEvent, 0);
- ExitThread(0);
- return 0;
+ WSANETWORKEVENTS NetworkEvents;
+ thread_data* d = (thread_data *)data;
+
+ HANDLE NetworkEvent = gs_WSACreateEvent();
+ gs_WSAEventSelect(d->fd, NetworkEvent, d->lEvent);
+
+ while(socketHash[d->fd] == true)
+ {
+ if ((gs_WSAWaitForMultipleEvents(1, &NetworkEvent, FALSE,INFINITE, FALSE)) == WAIT_FAILED)
+ {
+ printf("WSAWaitForMultipleEvents failed with error %d\n", WSAGetLastError());
+ return 0;
+ }
+ if (gs_WSAEnumNetworkEvents(d->fd ,NetworkEvent, &NetworkEvents) == SOCKET_ERROR)
+ {
+ printf("WSAEnumNetworkEvents failed with error %d\n", WSAGetLastError());
+ return 0;
+ }
+
+ long flags = NetworkEvents.lNetworkEvents;
+ if (flags & FD_READ)
+ ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_READ);
+ if (flags & FD_WRITE)
+ ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_WRITE);
+ if (flags & FD_OOB)
+ ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_OOB);
+ if (flags & FD_ACCEPT)
+ ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_ACCEPT);
+ if (flags & FD_CONNECT)
+ ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_CONNECT);
+ if (flags & FD_CLOSE)
+ ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_CLOSE);
+
+ }
+ gs_WSAEventSelect(d->fd, NetworkEvent, 0);
+ ExitThread(0);
+ return 0;
- socketList[(socket->m_msgnumber - WM_USER)] = NULL;
+
+ const int msgnum = socket->m_msgnumber;
+ if ( msgnum )
+ {
+ // we need to remove any pending messages for this socket to avoid having
+ // them sent to a new socket which could reuse the same message number as
+ // soon as we destroy this one
+ MSG msg;
+ while ( ::PeekMessage(&msg, hWin, msgnum, msgnum, PM_REMOVE) )
+ ;
+
+ socketList[msgnum - WM_USER] = NULL;
+ }
+ //else: the socket has never been created successfully
+
- thread_data* d = new thread_data;
- d->lEvent = lEvent;
- d->hEvtWin = hWin;
- d->msgnumber = socket->m_msgnumber;
- d->fd = socket->m_fd;
- socketHash[socket->m_fd] = true;
- hThread[currSocket++] = CreateThread(NULL, 0, &SocketThread,(LPVOID)d, 0, NULL);
+ thread_data* d = new thread_data;
+ d->lEvent = lEvent;
+ d->hEvtWin = hWin;
+ d->msgnumber = socket->m_msgnumber;
+ d->fd = socket->m_fd;
+ socketHash[socket->m_fd] = true;
+ hThread[currSocket++] = CreateThread(NULL, 0, &SocketThread,(LPVOID)d, 0, NULL);
-#else /* !wxUSE_SOCKETS */
-
-/*
- * Translation unit shouldn't be empty, so include this typedef to make the
- * compiler (VC++ 6.0, for example) happy
- */
-typedef void (*wxDummy)();
+// set the wxBase variable to point to our GSocketManager implementation
+//
+// see comments in wx/msw/apptbase.h for the explanation of why do we do it
+// like this
+static struct ManagerSetter
+{
+ ManagerSetter()
+ {
+ static GSocketMSWManager s_manager;
+ wxAppTraits::SetDefaultSocketManager(&s_manager);
+ }
+} gs_managerSetter;