]>
Commit | Line | Data |
---|---|---|
51fe4b60 | 1 | ///////////////////////////////////////////////////////////////////////////// |
116de991 VZ |
2 | // Name: src/msw/sockmsw.cpp |
3 | // Purpose: MSW-specific socket code | |
51fe4b60 VZ |
4 | // Authors: Guilhem Lavaux, Guillermo Rodriguez Garcia |
5 | // Created: April 1997 | |
6 | // Copyright: (C) 1999-1997, Guilhem Lavaux | |
7 | // (C) 1999-2000, Guillermo Rodriguez Garcia | |
8 | // (C) 2008 Vadim Zeitlin | |
9 | // RCS_ID: $Id$ | |
10 | // License: wxWindows licence | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
b7ceceb1 | 13 | |
86afa786 VS |
14 | // For compilers that support precompilation, includes "wx.h". |
15 | #include "wx/wxprec.h" | |
16 | ||
17 | #ifdef __BORLANDC__ | |
18 | #pragma hdrstop | |
19 | #endif | |
20 | ||
2804f77d VZ |
21 | #if wxUSE_SOCKETS |
22 | ||
b7ceceb1 DE |
23 | /* including rasasync.h (included from windows.h itself included from |
24 | * wx/setup.h and/or winsock.h results in this warning for | |
25 | * RPCNOTIFICATION_ROUTINE | |
26 | */ | |
27 | #ifdef _MSC_VER | |
1c8681b4 | 28 | # pragma warning(disable:4115) /* named type definition in parentheses */ |
b7ceceb1 DE |
29 | #endif |
30 | ||
60913641 | 31 | #include "wx/private/socket.h" |
e8d9821d | 32 | #include "wx/msw/private.h" // for wxGetInstance() |
2804f77d | 33 | #include "wx/apptrait.h" |
f2c94e8a | 34 | #include "wx/thread.h" |
d8abb95f | 35 | #include "wx/dynlib.h" |
b7ceceb1 | 36 | |
116de991 VZ |
37 | #ifdef __WXWINCE__ |
38 | /* | |
39 | * As WSAAsyncSelect is not present on WinCE, it now uses WSACreateEvent, | |
40 | * WSAEventSelect, WSAWaitForMultipleEvents and WSAEnumNetworkEvents. When | |
41 | * enabling eventhandling for a socket a new thread it created that keeps track | |
42 | * of the events and posts a messageto the hidden window to use the standard | |
43 | * message loop. | |
44 | */ | |
b7ceceb1 | 45 | #include "wx/msw/wince/net.h" |
7ec69821 | 46 | #include "wx/hashmap.h" |
84aa68c4 | 47 | WX_DECLARE_HASH_MAP(int,bool,wxIntegerHash,wxIntegerEqual,SocketHash); |
b7ceceb1 | 48 | |
116de991 VZ |
49 | #ifndef isdigit |
50 | #define isdigit(x) (x > 47 && x < 58) | |
51 | #endif | |
52 | #include "wx/msw/wince/net.h" | |
b7ceceb1 | 53 | |
116de991 | 54 | #endif // __WXWINCE__ |
b7ceceb1 DE |
55 | |
56 | #ifdef _MSC_VER | |
57 | # pragma warning(default:4115) /* named type definition in parentheses */ | |
58 | #endif | |
59 | ||
51fe4b60 | 60 | #define CLASSNAME TEXT("_wxSocket_Internal_Window_Class") |
b7ceceb1 DE |
61 | |
62 | /* implemented in utils.cpp */ | |
32524c8f | 63 | extern "C" WXDLLIMPEXP_BASE HWND |
b7ceceb1 DE |
64 | wxCreateHiddenWindow(LPCTSTR *pclassname, LPCTSTR classname, WNDPROC wndproc); |
65 | ||
51fe4b60 | 66 | /* Maximum number of different wxSocket objects at a given time. |
b7ceceb1 DE |
67 | * This value can be modified at will, but it CANNOT be greater |
68 | * than (0x7FFF - WM_USER + 1) | |
69 | */ | |
70 | #define MAXSOCKETS 1024 | |
71 | ||
72 | #if (MAXSOCKETS > (0x7FFF - WM_USER + 1)) | |
73 | #error "MAXSOCKETS is too big!" | |
74 | #endif | |
75 | ||
dbfb61b3 | 76 | #ifndef __WXWINCE__ |
d8abb95f | 77 | typedef int (PASCAL *WSAAsyncSelect_t)(SOCKET,HWND,u_int,long); |
dbfb61b3 JS |
78 | #else |
79 | /* Typedef the needed function prototypes and the WSANETWORKEVENTS structure | |
80 | */ | |
81 | typedef struct _WSANETWORKEVENTS { | |
82 | long lNetworkEvents; | |
83 | int iErrorCode[10]; | |
84 | } WSANETWORKEVENTS, FAR * LPWSANETWORKEVENTS; | |
d8abb95f VZ |
85 | typedef HANDLE (PASCAL *WSACreateEvent_t)(); |
86 | typedef int (PASCAL *WSAEventSelect_t)(SOCKET,HANDLE,long); | |
87 | typedef int (PASCAL *WSAWaitForMultipleEvents_t)(long,HANDLE,BOOL,long,BOOL); | |
88 | typedef int (PASCAL *WSAEnumNetworkEvents_t)(SOCKET,HANDLE,LPWSANETWORKEVENTS); | |
dbfb61b3 | 89 | #endif //__WXWINCE__ |
b7ceceb1 | 90 | |
51fe4b60 | 91 | LRESULT CALLBACK wxSocket_Internal_WinProc(HWND, UINT, WPARAM, LPARAM); |
c90cc42e | 92 | |
b7ceceb1 DE |
93 | /* Global variables */ |
94 | ||
b7ceceb1 | 95 | static HWND hWin; |
f2c94e8a | 96 | wxCRIT_SECT_DECLARE_MEMBER(gs_critical); |
51fe4b60 | 97 | static wxSocketImplMSW *socketList[MAXSOCKETS]; |
b7ceceb1 | 98 | static int firstAvailable; |
dbfb61b3 JS |
99 | |
100 | #ifndef __WXWINCE__ | |
d8abb95f | 101 | static WSAAsyncSelect_t gs_WSAAsyncSelect = NULL; |
dbfb61b3 | 102 | #else |
84aa68c4 | 103 | static SocketHash socketHash; |
dbfb61b3 JS |
104 | static unsigned int currSocket; |
105 | HANDLE hThread[MAXSOCKETS]; | |
d8abb95f VZ |
106 | static WSACreateEvent_t gs_WSACreateEvent = NULL; |
107 | static WSAEventSelect_t gs_WSAEventSelect = NULL; | |
108 | static WSAWaitForMultipleEvents_t gs_WSAWaitForMultipleEvents = NULL; | |
109 | static WSAEnumNetworkEvents_t gs_WSAEnumNetworkEvents = NULL; | |
dbfb61b3 JS |
110 | /* This structure will be used to pass data on to the thread that handles socket events. |
111 | */ | |
112 | typedef struct thread_data{ | |
7ec69821 WS |
113 | HWND hEvtWin; |
114 | unsigned long msgnumber; | |
115 | unsigned long fd; | |
116 | unsigned long lEvent; | |
dbfb61b3 JS |
117 | }thread_data; |
118 | #endif | |
119 | ||
dbfb61b3 | 120 | #ifdef __WXWINCE__ |
d8abb95f VZ |
121 | /* This thread handles socket events on WinCE using WSAEventSelect() as |
122 | * WSAAsyncSelect is not supported. When an event occurs for the socket, it is | |
123 | * checked what kind of event happend and the correct message gets posted so | |
124 | * that the hidden window can handle it as it would in other MSW builds. | |
dbfb61b3 JS |
125 | */ |
126 | DWORD WINAPI SocketThread(LPVOID data) | |
127 | { | |
7ec69821 WS |
128 | WSANETWORKEVENTS NetworkEvents; |
129 | thread_data* d = (thread_data *)data; | |
130 | ||
131 | HANDLE NetworkEvent = gs_WSACreateEvent(); | |
132 | gs_WSAEventSelect(d->fd, NetworkEvent, d->lEvent); | |
133 | ||
134 | while(socketHash[d->fd] == true) | |
135 | { | |
136 | if ((gs_WSAWaitForMultipleEvents(1, &NetworkEvent, FALSE,INFINITE, FALSE)) == WAIT_FAILED) | |
137 | { | |
138 | printf("WSAWaitForMultipleEvents failed with error %d\n", WSAGetLastError()); | |
139 | return 0; | |
140 | } | |
141 | if (gs_WSAEnumNetworkEvents(d->fd ,NetworkEvent, &NetworkEvents) == SOCKET_ERROR) | |
142 | { | |
143 | printf("WSAEnumNetworkEvents failed with error %d\n", WSAGetLastError()); | |
144 | return 0; | |
145 | } | |
146 | ||
147 | long flags = NetworkEvents.lNetworkEvents; | |
148 | if (flags & FD_READ) | |
149 | ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_READ); | |
150 | if (flags & FD_WRITE) | |
151 | ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_WRITE); | |
152 | if (flags & FD_OOB) | |
153 | ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_OOB); | |
154 | if (flags & FD_ACCEPT) | |
155 | ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_ACCEPT); | |
156 | if (flags & FD_CONNECT) | |
157 | ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_CONNECT); | |
158 | if (flags & FD_CLOSE) | |
159 | ::PostMessage(d->hEvtWin, d->msgnumber,d->fd, FD_CLOSE); | |
160 | ||
161 | } | |
162 | gs_WSAEventSelect(d->fd, NetworkEvent, 0); | |
163 | ExitThread(0); | |
164 | return 0; | |
dbfb61b3 JS |
165 | } |
166 | #endif | |
167 | ||
2804f77d | 168 | // ---------------------------------------------------------------------------- |
51fe4b60 | 169 | // MSW implementation of wxSocketManager |
2804f77d | 170 | // ---------------------------------------------------------------------------- |
dbfb61b3 | 171 | |
51fe4b60 | 172 | class wxSocketMSWManager : public wxSocketManager |
1c6dd11c | 173 | { |
2804f77d VZ |
174 | public: |
175 | virtual bool OnInit(); | |
176 | virtual void OnExit(); | |
177 | ||
51fe4b60 VZ |
178 | virtual wxSocketImpl *CreateSocket(wxSocketBase& wxsocket) |
179 | { | |
180 | return new wxSocketImplMSW(wxsocket); | |
181 | } | |
182 | virtual void Install_Callback(wxSocketImpl *socket, wxSocketNotify event); | |
183 | virtual void Uninstall_Callback(wxSocketImpl *socket, wxSocketNotify event); | |
d8abb95f VZ |
184 | |
185 | private: | |
186 | static wxDynamicLibrary gs_wsock32dll; | |
2804f77d | 187 | }; |
c90cc42e | 188 | |
d8abb95f VZ |
189 | wxDynamicLibrary wxSocketMSWManager::gs_wsock32dll; |
190 | ||
51fe4b60 | 191 | bool wxSocketMSWManager::OnInit() |
b7ceceb1 | 192 | { |
84aa68c4 JS |
193 | static LPCTSTR pclassname = NULL; |
194 | int i; | |
b7ceceb1 | 195 | |
84aa68c4 | 196 | /* Create internal window for event notifications */ |
51fe4b60 | 197 | hWin = wxCreateHiddenWindow(&pclassname, CLASSNAME, wxSocket_Internal_WinProc); |
84aa68c4 JS |
198 | if (!hWin) |
199 | return false; | |
b7ceceb1 | 200 | |
84aa68c4 | 201 | /* Initialize socket list */ |
84aa68c4 JS |
202 | for (i = 0; i < MAXSOCKETS; i++) |
203 | { | |
204 | socketList[i] = NULL; | |
205 | } | |
206 | firstAvailable = 0; | |
b7ceceb1 | 207 | |
d8abb95f VZ |
208 | // we don't link with wsock32.dll (or ws2 in CE case) statically to avoid |
209 | // dependencies on it for all the application using wx even if they don't use | |
210 | // sockets | |
211 | #ifdef __WXWINCE__ | |
212 | #define WINSOCK_DLL_NAME _T("ws2.dll") | |
213 | #else | |
214 | #define WINSOCK_DLL_NAME _T("wsock32.dll") | |
215 | #endif | |
216 | ||
217 | gs_wsock32dll.Load(WINSOCK_DLL_NAME, wxDL_VERBATIM | wxDL_QUIET); | |
218 | if ( !gs_wsock32dll.IsLoaded() ) | |
219 | return false; | |
220 | ||
dbfb61b3 | 221 | #ifndef __WXWINCE__ |
d8abb95f VZ |
222 | wxDL_INIT_FUNC(gs_, WSAAsyncSelect, gs_wsock32dll); |
223 | if ( !gs_WSAAsyncSelect ) | |
224 | return false; | |
dbfb61b3 | 225 | #else |
d8abb95f VZ |
226 | wxDL_INIT_FUNC(gs_, WSAEventSelect, gs_wsock32dll); |
227 | if ( !gs_WSAEventSelect ) | |
228 | return false; | |
1c6dd11c | 229 | |
d8abb95f VZ |
230 | wxDL_INIT_FUNC(gs_, WSACreateEvent, gs_wsock32dll); |
231 | if ( !gs_WSACreateEvent ) | |
232 | return false; | |
84aa68c4 | 233 | |
d8abb95f VZ |
234 | wxDL_INIT_FUNC(gs_, WSAWaitForMultipleEvents, gs_wsock32dll); |
235 | if ( !gs_WSAWaitForMultipleEvents ) | |
236 | return false; | |
84aa68c4 | 237 | |
d8abb95f VZ |
238 | wxDL_INIT_FUNC(gs_, WSAEnumNetworkEvents, gs_wsock32dll); |
239 | if ( !gs_WSAEnumNetworkEvents ) | |
240 | return false; | |
84aa68c4 | 241 | |
d8abb95f VZ |
242 | currSocket = 0; |
243 | #endif // !__WXWINCE__/__WXWINCE__ | |
7ec69821 | 244 | |
51fe4b60 VZ |
245 | // finally initialize WinSock |
246 | WSADATA wsaData; | |
247 | return WSAStartup((1 << 8) | 1, &wsaData) == 0; | |
b7ceceb1 DE |
248 | } |
249 | ||
51fe4b60 | 250 | void wxSocketMSWManager::OnExit() |
b7ceceb1 | 251 | { |
dbfb61b3 | 252 | #ifdef __WXWINCE__ |
1c6dd11c | 253 | /* Delete the threads here */ |
7ec69821 WS |
254 | for(unsigned int i=0; i < currSocket; i++) |
255 | CloseHandle(hThread[i]); | |
dbfb61b3 | 256 | #endif |
b7ceceb1 DE |
257 | /* Destroy internal window */ |
258 | DestroyWindow(hWin); | |
e8d9821d | 259 | UnregisterClass(CLASSNAME, wxGetInstance()); |
b7ceceb1 | 260 | |
51fe4b60 | 261 | WSACleanup(); |
d8abb95f VZ |
262 | |
263 | gs_wsock32dll.Unload(); | |
b7ceceb1 DE |
264 | } |
265 | ||
266 | /* Per-socket GUI initialization / cleanup */ | |
267 | ||
51fe4b60 VZ |
268 | wxSocketImplMSW::wxSocketImplMSW(wxSocketBase& wxsocket) |
269 | : wxSocketImpl(wxsocket) | |
b7ceceb1 | 270 | { |
b7ceceb1 | 271 | /* Allocate a new message number for this socket */ |
f2c94e8a | 272 | wxCRIT_SECT_LOCKER(lock, gs_critical); |
b7ceceb1 | 273 | |
51fe4b60 | 274 | int i = firstAvailable; |
b7ceceb1 DE |
275 | while (socketList[i] != NULL) |
276 | { | |
277 | i = (i + 1) % MAXSOCKETS; | |
278 | ||
279 | if (i == firstAvailable) /* abort! */ | |
280 | { | |
51fe4b60 VZ |
281 | m_msgnumber = 0; // invalid |
282 | return; | |
b7ceceb1 DE |
283 | } |
284 | } | |
51fe4b60 | 285 | socketList[i] = this; |
b7ceceb1 | 286 | firstAvailable = (i + 1) % MAXSOCKETS; |
51fe4b60 | 287 | m_msgnumber = (i + WM_USER); |
f0fbbe23 VZ |
288 | } |
289 | ||
51fe4b60 | 290 | wxSocketImplMSW::~wxSocketImplMSW() |
b7ceceb1 DE |
291 | { |
292 | /* Remove the socket from the list */ | |
f2c94e8a | 293 | wxCRIT_SECT_LOCKER(lock, gs_critical); |
cab9b205 | 294 | |
51fe4b60 | 295 | if ( m_msgnumber ) |
eb97543d | 296 | { |
cab9b205 VZ |
297 | // we need to remove any pending messages for this socket to avoid having |
298 | // them sent to a new socket which could reuse the same message number as | |
299 | // soon as we destroy this one | |
300 | MSG msg; | |
51fe4b60 | 301 | while ( ::PeekMessage(&msg, hWin, m_msgnumber, m_msgnumber, PM_REMOVE) ) |
cab9b205 VZ |
302 | ; |
303 | ||
51fe4b60 | 304 | socketList[m_msgnumber - WM_USER] = NULL; |
cab9b205 | 305 | } |
eb97543d | 306 | //else: the socket has never been created successfully |
b7ceceb1 DE |
307 | } |
308 | ||
309 | /* Windows proc for asynchronous event handling */ | |
310 | ||
51fe4b60 | 311 | LRESULT CALLBACK wxSocket_Internal_WinProc(HWND hWnd, |
b7ceceb1 DE |
312 | UINT uMsg, |
313 | WPARAM wParam, | |
314 | LPARAM lParam) | |
315 | { | |
f2c94e8a VZ |
316 | if ( uMsg < WM_USER || uMsg > (WM_USER + MAXSOCKETS - 1)) |
317 | return DefWindowProc(hWnd, uMsg, wParam, lParam); | |
b7ceceb1 | 318 | |
f2c94e8a | 319 | wxSocketImplMSW *socket; |
5e9238f9 | 320 | wxSocketNotify event = (wxSocketNotify)-1; |
b7ceceb1 | 321 | { |
f2c94e8a VZ |
322 | wxCRIT_SECT_LOCKER(lock, gs_critical); |
323 | ||
324 | socket = socketList[(uMsg - WM_USER)]; | |
5e9238f9 VZ |
325 | if ( !socket ) |
326 | return 0; | |
327 | ||
328 | wxASSERT_MSG( socket->m_fd == (SOCKET)wParam, | |
329 | "mismatch between message and socket?" ); | |
f2c94e8a | 330 | |
5e9238f9 | 331 | switch WSAGETSELECTEVENT(lParam) |
b7ceceb1 | 332 | { |
5e9238f9 VZ |
333 | case FD_READ: |
334 | event = wxSOCKET_INPUT; | |
335 | break; | |
336 | ||
337 | case FD_WRITE: | |
338 | event = wxSOCKET_OUTPUT; | |
339 | break; | |
340 | ||
341 | case FD_ACCEPT: | |
342 | event = wxSOCKET_CONNECTION; | |
343 | break; | |
344 | ||
345 | case FD_CONNECT: | |
346 | event = WSAGETSELECTERROR(lParam) ? wxSOCKET_LOST | |
347 | : wxSOCKET_CONNECTION; | |
348 | break; | |
349 | ||
350 | case FD_CLOSE: | |
351 | event = wxSOCKET_LOST; | |
352 | break; | |
353 | ||
354 | default: | |
355 | wxFAIL_MSG( "unexpected socket notification" ); | |
356 | return 0; | |
b7ceceb1 | 357 | } |
f2c94e8a | 358 | } // unlock gs_critical |
b7ceceb1 | 359 | |
5e9238f9 | 360 | socket->NotifyOnStateChange(event); |
b7ceceb1 | 361 | |
5e9238f9 | 362 | return 0; |
b7ceceb1 DE |
363 | } |
364 | ||
f0fbbe23 | 365 | /* |
b7ceceb1 DE |
366 | * Enable all event notifications; we need to be notified of all |
367 | * events for internal processing, but we will only notify users | |
f0fbbe23 | 368 | * when an appropriate callback function has been installed. |
b7ceceb1 | 369 | */ |
51fe4b60 VZ |
370 | void wxSocketMSWManager::Install_Callback(wxSocketImpl *socket_, |
371 | wxSocketNotify WXUNUSED(event)) | |
b7ceceb1 | 372 | { |
51fe4b60 VZ |
373 | wxSocketImplMSW * const socket = static_cast<wxSocketImplMSW *>(socket_); |
374 | ||
b7ceceb1 DE |
375 | if (socket->m_fd != INVALID_SOCKET) |
376 | { | |
377 | /* We could probably just subscribe to all events regardless | |
378 | * of the socket type, but MS recommends to do it this way. | |
379 | */ | |
380 | long lEvent = socket->m_server? | |
381 | FD_ACCEPT : (FD_READ | FD_WRITE | FD_CONNECT | FD_CLOSE); | |
dbfb61b3 | 382 | #ifndef __WXWINCE__ |
1c8681b4 | 383 | gs_WSAAsyncSelect(socket->m_fd, hWin, socket->m_msgnumber, lEvent); |
dbfb61b3 JS |
384 | #else |
385 | /* | |
386 | * WinCE creates a thread for socket event handling. | |
1c6dd11c | 387 | * All needed parameters get passed through the thread_data structure. |
dbfb61b3 | 388 | */ |
84aa68c4 | 389 | |
7ec69821 WS |
390 | thread_data* d = new thread_data; |
391 | d->lEvent = lEvent; | |
392 | d->hEvtWin = hWin; | |
393 | d->msgnumber = socket->m_msgnumber; | |
394 | d->fd = socket->m_fd; | |
395 | socketHash[socket->m_fd] = true; | |
396 | hThread[currSocket++] = CreateThread(NULL, 0, &SocketThread,(LPVOID)d, 0, NULL); | |
dbfb61b3 | 397 | #endif |
b7ceceb1 DE |
398 | } |
399 | } | |
400 | ||
f0fbbe23 VZ |
401 | /* |
402 | * Disable event notifications (used when shutting down the socket) | |
b7ceceb1 | 403 | */ |
51fe4b60 VZ |
404 | void wxSocketMSWManager::Uninstall_Callback(wxSocketImpl *socket_, |
405 | wxSocketNotify WXUNUSED(event)) | |
b7ceceb1 | 406 | { |
51fe4b60 VZ |
407 | wxSocketImplMSW * const socket = static_cast<wxSocketImplMSW *>(socket_); |
408 | ||
b7ceceb1 DE |
409 | if (socket->m_fd != INVALID_SOCKET) |
410 | { | |
dbfb61b3 | 411 | #ifndef __WXWINCE__ |
1c8681b4 | 412 | gs_WSAAsyncSelect(socket->m_fd, hWin, socket->m_msgnumber, 0); |
dbfb61b3 | 413 | #else |
7ec69821 WS |
414 | //Destroy the thread |
415 | socketHash[socket->m_fd] = false; | |
dbfb61b3 | 416 | #endif |
b7ceceb1 DE |
417 | } |
418 | } | |
419 | ||
51fe4b60 | 420 | // set the wxBase variable to point to our wxSocketManager implementation |
2804f77d | 421 | // |
51fe4b60 | 422 | // see comments in wx/apptrait.h for the explanation of why do we do it |
2804f77d VZ |
423 | // like this |
424 | static struct ManagerSetter | |
425 | { | |
426 | ManagerSetter() | |
427 | { | |
51fe4b60 | 428 | static wxSocketMSWManager s_manager; |
2804f77d VZ |
429 | wxAppTraits::SetDefaultSocketManager(&s_manager); |
430 | } | |
a3cf8dca | 431 | } gs_managerSetter; |
b7ceceb1 | 432 | |
116de991 VZ |
433 | // ============================================================================ |
434 | // wxSocketImpl implementation | |
435 | // ============================================================================ | |
436 | ||
437 | /* static */ | |
438 | wxSocketImpl *wxSocketImpl::Create(wxSocketBase& wxsocket) | |
439 | { | |
440 | return new wxSocketImplMSW(wxsocket); | |
441 | } | |
442 | ||
443 | void wxSocketImplMSW::DoClose() | |
444 | { | |
445 | wxSocketManager::Get()-> | |
446 | Uninstall_Callback(this, wxSOCKET_MAX_EVENT /* unused anyhow */); | |
447 | ||
448 | closesocket(m_fd); | |
449 | } | |
450 | ||
64b1cea0 | 451 | wxSocketError wxSocketImplMSW::GetLastError() const |
116de991 | 452 | { |
2b036c4b | 453 | switch ( WSAGetLastError() ) |
116de991 | 454 | { |
2b036c4b VZ |
455 | case 0: |
456 | return wxSOCKET_NOERROR; | |
116de991 | 457 | |
2b036c4b VZ |
458 | case WSAENOTSOCK: |
459 | return wxSOCKET_INVSOCK; | |
116de991 | 460 | |
2b036c4b | 461 | case WSAEWOULDBLOCK: |
116de991 | 462 | return wxSOCKET_WOULDBLOCK; |
116de991 | 463 | |
2b036c4b VZ |
464 | default: |
465 | return wxSOCKET_IOERR; | |
116de991 | 466 | } |
116de991 VZ |
467 | } |
468 | ||
2804f77d | 469 | #endif // wxUSE_SOCKETS |