]> git.saurik.com Git - wxWidgets.git/blob - src/msw/gsocket.cpp
Finished review of the first 1,000 lines of grid.h interface header.
[wxWidgets.git] / src / msw / gsocket.cpp
1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket)
3 * Name: src/msw/gsocket.cpp
4 * Copyright: (c) Guilhem Lavaux
5 * Licence: wxWindows Licence
6 * Author: Guillermo Rodriguez Garcia <guille@iies.es>
7 * Purpose: GSocket main MSW file
8 * Licence: The wxWindows licence
9 * CVSID: $Id$
10 * -------------------------------------------------------------------------
11 */
12
13 // For compilers that support precompilation, includes "wx.h".
14 #include "wx/wxprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifdef _MSC_VER
21 /* RPCNOTIFICATION_ROUTINE in rasasync.h (included from winsock.h),
22 * warning: conditional expression is constant.
23 */
24 # pragma warning(disable:4115)
25 /* FD_SET,
26 * warning: named type definition in parentheses.
27 */
28 # pragma warning(disable:4127)
29 /* GAddress_UNIX_GetPath,
30 * warning: unreferenced formal parameter.
31 */
32 # pragma warning(disable:4100)
33
34 #ifdef __WXWINCE__
35 /* windows.h results in tons of warnings at max warning level */
36 # ifdef _MSC_VER
37 # pragma warning(push, 1)
38 # endif
39 # include <windows.h>
40 # ifdef _MSC_VER
41 # pragma warning(pop)
42 # pragma warning(disable:4514)
43 # endif
44 #endif
45
46 #endif /* _MSC_VER */
47
48 #if defined(__CYGWIN__)
49 //CYGWIN gives annoying warning about runtime stuff if we don't do this
50 # define USE_SYS_TYPES_FD_SET
51 # include <sys/types.h>
52 #endif
53
54 #include <winsock.h>
55
56 #include "wx/platform.h"
57
58 #if wxUSE_SOCKETS
59
60 #include "wx/gsocket.h"
61 #include "wx/link.h"
62
63 wxFORCE_LINK_MODULE(gsockmsw)
64
65 #ifdef __WXWINCE__
66 #ifndef isdigit
67 #define isdigit(x) (x > 47 && x < 58)
68 #endif
69 #include "wx/msw/wince/net.h"
70 #endif
71
72 #include <string.h>
73 #include <stdio.h>
74 #include <stdlib.h>
75 #include <stddef.h>
76 #include <ctype.h>
77
78 /* if we use configure for MSW WX_SOCKLEN_T will be already defined */
79 #ifndef WX_SOCKLEN_T
80 # define WX_SOCKLEN_T int
81 #endif
82
83 #if wxUSE_IPV6
84 typedef struct sockaddr_storage wxSockAddr;
85 #else
86 typedef struct sockaddr wxSockAddr;
87 #endif
88
89 bool GSocket_Init()
90 {
91 WSADATA wsaData;
92
93 GSocketManager * const manager = GSocketManager::Get();
94 if ( !manager || !manager->OnInit() )
95 return false;
96
97 /* Initialize WinSocket */
98 return WSAStartup((1 << 8) | 1, &wsaData) == 0;
99 }
100
101 void GSocket_Cleanup()
102 {
103 GSocketManager * const manager = GSocketManager::Get();
104 if ( manager )
105 manager->OnExit();
106
107 /* Cleanup WinSocket */
108 WSACleanup();
109 }
110
111 /* Constructors / Destructors for GSocket */
112
113 GSocket::GSocket()
114 {
115 int i;
116
117 m_fd = INVALID_SOCKET;
118 for (i = 0; i < GSOCK_MAX_EVENT; i++)
119 {
120 m_cbacks[i] = NULL;
121 }
122 m_detected = 0;
123 m_local = NULL;
124 m_peer = NULL;
125 m_error = GSOCK_NOERROR;
126 m_server = false;
127 m_stream = true;
128 m_non_blocking = false;
129 m_timeout.tv_sec = 10 * 60; /* 10 minutes */
130 m_timeout.tv_usec = 0;
131 m_establishing = false;
132 m_reusable = false;
133 m_broadcast = false;
134 m_dobind = true;
135 m_initialRecvBufferSize = -1;
136 m_initialSendBufferSize = -1;
137
138 m_ok = GSocketManager::Get()->Init_Socket(this);
139 }
140
141 void GSocket::Close()
142 {
143 GSocketManager::Get()->Disable_Events(this);
144 closesocket(m_fd);
145 m_fd = INVALID_SOCKET;
146 }
147
148 GSocket::~GSocket()
149 {
150 GSocketManager::Get()->Destroy_Socket(this);
151
152 /* Check that the socket is really shutdowned */
153 if (m_fd != INVALID_SOCKET)
154 Shutdown();
155
156 /* Destroy private addresses */
157 if (m_local)
158 GAddress_destroy(m_local);
159
160 if (m_peer)
161 GAddress_destroy(m_peer);
162 }
163
164 /* GSocket_Shutdown:
165 * Disallow further read/write operations on this socket, close
166 * the fd and disable all callbacks.
167 */
168 void GSocket::Shutdown()
169 {
170 int evt;
171
172 /* If socket has been created, shutdown it */
173 if (m_fd != INVALID_SOCKET)
174 {
175 shutdown(m_fd, 1 /* SD_SEND */);
176 Close();
177 }
178
179 /* Disable GUI callbacks */
180 for (evt = 0; evt < GSOCK_MAX_EVENT; evt++)
181 m_cbacks[evt] = NULL;
182
183 m_detected = GSOCK_LOST_FLAG;
184 }
185
186 /* Address handling */
187
188 /* GSocket_SetLocal:
189 * GSocket_GetLocal:
190 * GSocket_SetPeer:
191 * GSocket_GetPeer:
192 * Set or get the local or peer address for this socket. The 'set'
193 * functions return GSOCK_NOERROR on success, an error code otherwise.
194 * The 'get' functions return a pointer to a GAddress object on success,
195 * or NULL otherwise, in which case they set the error code of the
196 * corresponding GSocket.
197 *
198 * Error codes:
199 * GSOCK_INVSOCK - the socket is not valid.
200 * GSOCK_INVADDR - the address is not valid.
201 */
202 GSocketError GSocket::SetLocal(GAddress *address)
203 {
204 /* the socket must be initialized, or it must be a server */
205 if (m_fd != INVALID_SOCKET && !m_server)
206 {
207 m_error = GSOCK_INVSOCK;
208 return GSOCK_INVSOCK;
209 }
210
211 /* check address */
212 if (address == NULL || address->m_family == GSOCK_NOFAMILY)
213 {
214 m_error = GSOCK_INVADDR;
215 return GSOCK_INVADDR;
216 }
217
218 if (m_local)
219 GAddress_destroy(m_local);
220
221 m_local = GAddress_copy(address);
222
223 return GSOCK_NOERROR;
224 }
225
226 GSocketError GSocket::SetPeer(GAddress *address)
227 {
228 /* check address */
229 if (address == NULL || address->m_family == GSOCK_NOFAMILY)
230 {
231 m_error = GSOCK_INVADDR;
232 return GSOCK_INVADDR;
233 }
234
235 if (m_peer)
236 GAddress_destroy(m_peer);
237
238 m_peer = GAddress_copy(address);
239
240 return GSOCK_NOERROR;
241 }
242
243 GAddress *GSocket::GetLocal()
244 {
245 GAddress *address;
246 wxSockAddr addr;
247 WX_SOCKLEN_T size = sizeof(addr);
248 GSocketError err;
249
250 /* try to get it from the m_local var first */
251 if (m_local)
252 return GAddress_copy(m_local);
253
254 /* else, if the socket is initialized, try getsockname */
255 if (m_fd == INVALID_SOCKET)
256 {
257 m_error = GSOCK_INVSOCK;
258 return NULL;
259 }
260
261 if (getsockname(m_fd, (sockaddr*)&addr, &size) == SOCKET_ERROR)
262 {
263 m_error = GSOCK_IOERR;
264 return NULL;
265 }
266
267 /* got a valid address from getsockname, create a GAddress object */
268 if ((address = GAddress_new()) == NULL)
269 {
270 m_error = GSOCK_MEMERR;
271 return NULL;
272 }
273
274 if ((err = _GAddress_translate_from(address, (sockaddr*)&addr, size)) != GSOCK_NOERROR)
275 {
276 GAddress_destroy(address);
277 m_error = err;
278 return NULL;
279 }
280
281 return address;
282 }
283
284 GAddress *GSocket::GetPeer()
285 {
286 /* try to get it from the m_peer var */
287 if (m_peer)
288 return GAddress_copy(m_peer);
289
290 return NULL;
291 }
292
293 /* Server specific parts */
294
295 /* GSocket_SetServer:
296 * Sets up this socket as a server. The local address must have been
297 * set with GSocket_SetLocal() before GSocket_SetServer() is called.
298 * Returns GSOCK_NOERROR on success, one of the following otherwise:
299 *
300 * Error codes:
301 * GSOCK_INVSOCK - the socket is in use.
302 * GSOCK_INVADDR - the local address has not been set.
303 * GSOCK_IOERR - low-level error.
304 */
305 GSocketError GSocket::SetServer()
306 {
307 u_long arg = 1;
308
309 /* must not be in use */
310 if (m_fd != INVALID_SOCKET)
311 {
312 m_error = GSOCK_INVSOCK;
313 return GSOCK_INVSOCK;
314 }
315
316 /* the local addr must have been set */
317 if (!m_local)
318 {
319 m_error = GSOCK_INVADDR;
320 return GSOCK_INVADDR;
321 }
322
323 /* Initialize all fields */
324 m_server = true;
325 m_stream = true;
326
327 /* Create the socket */
328 m_fd = socket(m_local->m_realfamily, SOCK_STREAM, 0);
329
330 if (m_fd == INVALID_SOCKET)
331 {
332 m_error = GSOCK_IOERR;
333 return GSOCK_IOERR;
334 }
335
336 ioctlsocket(m_fd, FIONBIO, (u_long FAR *) &arg);
337 GSocketManager::Get()->Enable_Events(this);
338
339 /* allow a socket to re-bind if the socket is in the TIME_WAIT
340 state after being previously closed.
341 */
342 if (m_reusable)
343 {
344 setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(arg));
345 }
346
347 /* Bind to the local address,
348 * retrieve the actual address bound,
349 * and listen up to 5 connections.
350 */
351 if ((bind(m_fd, m_local->m_addr, m_local->m_len) != 0) ||
352 (getsockname(m_fd,
353 m_local->m_addr,
354 (WX_SOCKLEN_T *)&m_local->m_len) != 0) ||
355 (listen(m_fd, 5) != 0))
356 {
357 Close();
358 m_error = GSOCK_IOERR;
359 return GSOCK_IOERR;
360 }
361
362 return GSOCK_NOERROR;
363 }
364
365 /* GSocket_WaitConnection:
366 * Waits for an incoming client connection. Returns a pointer to
367 * a GSocket object, or NULL if there was an error, in which case
368 * the last error field will be updated for the calling GSocket.
369 *
370 * Error codes (set in the calling GSocket)
371 * GSOCK_INVSOCK - the socket is not valid or not a server.
372 * GSOCK_TIMEDOUT - timeout, no incoming connections.
373 * GSOCK_WOULDBLOCK - the call would block and the socket is nonblocking.
374 * GSOCK_MEMERR - couldn't allocate memory.
375 * GSOCK_IOERR - low-level error.
376 */
377 GSocket *GSocket::WaitConnection()
378 {
379 GSocket *connection;
380 wxSockAddr from;
381 WX_SOCKLEN_T fromlen = sizeof(from);
382 GSocketError err;
383 u_long arg = 1;
384
385 /* Reenable CONNECTION events */
386 m_detected &= ~GSOCK_CONNECTION_FLAG;
387
388 /* If the socket has already been created, we exit immediately */
389 if (m_fd == INVALID_SOCKET || !m_server)
390 {
391 m_error = GSOCK_INVSOCK;
392 return NULL;
393 }
394
395 /* Create a GSocket object for the new connection */
396 connection = GSocket_new();
397
398 if (!connection)
399 {
400 m_error = GSOCK_MEMERR;
401 return NULL;
402 }
403
404 /* Wait for a connection (with timeout) */
405 if (Input_Timeout() == GSOCK_TIMEDOUT)
406 {
407 delete connection;
408 /* m_error set by _GSocket_Input_Timeout */
409 return NULL;
410 }
411
412 connection->m_fd = accept(m_fd, (sockaddr*)&from, &fromlen);
413
414 if (connection->m_fd == INVALID_SOCKET)
415 {
416 if (WSAGetLastError() == WSAEWOULDBLOCK)
417 m_error = GSOCK_WOULDBLOCK;
418 else
419 m_error = GSOCK_IOERR;
420
421 delete connection;
422 return NULL;
423 }
424
425 /* Initialize all fields */
426 connection->m_server = false;
427 connection->m_stream = true;
428
429 /* Setup the peer address field */
430 connection->m_peer = GAddress_new();
431 if (!connection->m_peer)
432 {
433 delete connection;
434 m_error = GSOCK_MEMERR;
435 return NULL;
436 }
437 err = _GAddress_translate_from(connection->m_peer, (sockaddr*)&from, fromlen);
438 if (err != GSOCK_NOERROR)
439 {
440 GAddress_destroy(connection->m_peer);
441 delete connection;
442 m_error = err;
443 return NULL;
444 }
445
446 ioctlsocket(connection->m_fd, FIONBIO, (u_long FAR *) &arg);
447 GSocketManager::Get()->Enable_Events(connection);
448
449 return connection;
450 }
451
452 /* GSocket_SetReusable:
453 * Simply sets the m_resuable flag on the socket. GSocket_SetServer will
454 * make the appropriate setsockopt() call.
455 * Implemented as a GSocket function because clients (ie, wxSocketServer)
456 * don't have access to the GSocket struct information.
457 * Returns true if the flag was set correctly, false if an error occurred
458 * (ie, if the parameter was NULL)
459 */
460 bool GSocket::SetReusable()
461 {
462 /* socket must not be null, and must not be in use/already bound */
463 if (this && m_fd == INVALID_SOCKET) {
464 m_reusable = true;
465 return true;
466 }
467 return false;
468 }
469
470 /* GSocket_SetBroadcast:
471 * Simply sets the m_broadcast flag on the socket. GSocket_SetServer will
472 * make the appropriate setsockopt() call.
473 * Implemented as a GSocket function because clients (ie, wxSocketServer)
474 * don't have access to the GSocket struct information.
475 * Returns true if the flag was set correctly, false if an error occurred
476 * (ie, if the parameter was NULL)
477 */
478 bool GSocket::SetBroadcast()
479 {
480 /* socket must not be in use/already bound */
481 if (m_fd == INVALID_SOCKET) {
482 m_broadcast = true;
483 return true;
484 }
485 return false;
486 }
487
488 bool GSocket::DontDoBind()
489 {
490 /* socket must not be in use/already bound */
491 if (m_fd == INVALID_SOCKET) {
492 m_dobind = false;
493 return true;
494 }
495 return false;
496 }
497
498 /* Client specific parts */
499
500 /* GSocket_Connect:
501 * For stream (connection oriented) sockets, GSocket_Connect() tries
502 * to establish a client connection to a server using the peer address
503 * as established with GSocket_SetPeer(). Returns GSOCK_NOERROR if the
504 * connection has been successfully established, or one of the error
505 * codes listed below. Note that for nonblocking sockets, a return
506 * value of GSOCK_WOULDBLOCK doesn't mean a failure. The connection
507 * request can be completed later; you should use GSocket_Select()
508 * to poll for GSOCK_CONNECTION | GSOCK_LOST, or wait for the
509 * corresponding asynchronous events.
510 *
511 * For datagram (non connection oriented) sockets, GSocket_Connect()
512 * just sets the peer address established with GSocket_SetPeer() as
513 * default destination.
514 *
515 * Error codes:
516 * GSOCK_INVSOCK - the socket is in use or not valid.
517 * GSOCK_INVADDR - the peer address has not been established.
518 * GSOCK_TIMEDOUT - timeout, the connection failed.
519 * GSOCK_WOULDBLOCK - connection in progress (nonblocking sockets only)
520 * GSOCK_MEMERR - couldn't allocate memory.
521 * GSOCK_IOERR - low-level error.
522 */
523 GSocketError GSocket::Connect(GSocketStream stream)
524 {
525 int ret, err;
526 u_long arg = 1;
527
528 /* Enable CONNECTION events (needed for nonblocking connections) */
529 m_detected &= ~GSOCK_CONNECTION_FLAG;
530
531 if (m_fd != INVALID_SOCKET)
532 {
533 m_error = GSOCK_INVSOCK;
534 return GSOCK_INVSOCK;
535 }
536
537 if (!m_peer)
538 {
539 m_error = GSOCK_INVADDR;
540 return GSOCK_INVADDR;
541 }
542
543 /* Streamed or dgram socket? */
544 m_stream = (stream == GSOCK_STREAMED);
545 m_server = false;
546 m_establishing = false;
547
548 /* Create the socket */
549 m_fd = socket(m_peer->m_realfamily,
550 m_stream? SOCK_STREAM : SOCK_DGRAM, 0);
551
552 if (m_fd == INVALID_SOCKET)
553 {
554 m_error = GSOCK_IOERR;
555 return GSOCK_IOERR;
556 }
557
558 ioctlsocket(m_fd, FIONBIO, (u_long FAR *) &arg);
559 GSocketManager::Get()->Enable_Events(this);
560
561 // If the reuse flag is set, use the applicable socket reuse flag
562 if (m_reusable)
563 {
564 setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(arg));
565 }
566
567 if (m_initialRecvBufferSize >= 0)
568 setsockopt(m_fd, SOL_SOCKET, SO_RCVBUF, (const char*)&m_initialRecvBufferSize, sizeof(m_initialRecvBufferSize));
569 if (m_initialSendBufferSize >= 0)
570 setsockopt(m_fd, SOL_SOCKET, SO_SNDBUF, (const char*)&m_initialSendBufferSize, sizeof(m_initialSendBufferSize));
571
572 // If a local address has been set, then we need to bind to it before calling connect
573 if (m_local && m_local->m_addr)
574 {
575 bind(m_fd, m_local->m_addr, m_local->m_len);
576 }
577
578 /* Connect it to the peer address, with a timeout (see below) */
579 ret = connect(m_fd, m_peer->m_addr, m_peer->m_len);
580
581 if (ret == SOCKET_ERROR)
582 {
583 err = WSAGetLastError();
584
585 /* If connect failed with EWOULDBLOCK and the GSocket object
586 * is in blocking mode, we select() for the specified timeout
587 * checking for writability to see if the connection request
588 * completes.
589 */
590 if ((err == WSAEWOULDBLOCK) && (!m_non_blocking))
591 {
592 err = Connect_Timeout();
593
594 if (err != GSOCK_NOERROR)
595 {
596 Close();
597 /* m_error is set in _GSocket_Connect_Timeout */
598 }
599
600 return (GSocketError) err;
601 }
602
603 /* If connect failed with EWOULDBLOCK and the GSocket object
604 * is set to nonblocking, we set m_error to GSOCK_WOULDBLOCK
605 * (and return GSOCK_WOULDBLOCK) but we don't close the socket;
606 * this way if the connection completes, a GSOCK_CONNECTION
607 * event will be generated, if enabled.
608 */
609 if ((err == WSAEWOULDBLOCK) && (m_non_blocking))
610 {
611 m_establishing = true;
612 m_error = GSOCK_WOULDBLOCK;
613 return GSOCK_WOULDBLOCK;
614 }
615
616 /* If connect failed with an error other than EWOULDBLOCK,
617 * then the call to GSocket_Connect() has failed.
618 */
619 Close();
620 m_error = GSOCK_IOERR;
621 return GSOCK_IOERR;
622 }
623
624 return GSOCK_NOERROR;
625 }
626
627 /* Datagram sockets */
628
629 /* GSocket_SetNonOriented:
630 * Sets up this socket as a non-connection oriented (datagram) socket.
631 * Before using this function, the local address must have been set
632 * with GSocket_SetLocal(), or the call will fail. Returns GSOCK_NOERROR
633 * on success, or one of the following otherwise.
634 *
635 * Error codes:
636 * GSOCK_INVSOCK - the socket is in use.
637 * GSOCK_INVADDR - the local address has not been set.
638 * GSOCK_IOERR - low-level error.
639 */
640 GSocketError GSocket::SetNonOriented()
641 {
642 u_long arg = 1;
643
644 if (m_fd != INVALID_SOCKET)
645 {
646 m_error = GSOCK_INVSOCK;
647 return GSOCK_INVSOCK;
648 }
649
650 if (!m_local)
651 {
652 m_error = GSOCK_INVADDR;
653 return GSOCK_INVADDR;
654 }
655
656 /* Initialize all fields */
657 m_stream = false;
658 m_server = false;
659
660 /* Create the socket */
661 m_fd = socket(m_local->m_realfamily, SOCK_DGRAM, 0);
662
663 if (m_fd == INVALID_SOCKET)
664 {
665 m_error = GSOCK_IOERR;
666 return GSOCK_IOERR;
667 }
668
669 ioctlsocket(m_fd, FIONBIO, (u_long FAR *) &arg);
670 GSocketManager::Get()->Enable_Events(this);
671
672 if (m_reusable)
673 {
674 setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(arg));
675 }
676 if (m_broadcast)
677 {
678 setsockopt(m_fd, SOL_SOCKET, SO_BROADCAST, (const char*)&arg, sizeof(arg));
679 }
680 if (m_dobind)
681 {
682 /* Bind to the local address,
683 * and retrieve the actual address bound.
684 */
685 if ((bind(m_fd, m_local->m_addr, m_local->m_len) != 0) ||
686 (getsockname(m_fd,
687 m_local->m_addr,
688 (WX_SOCKLEN_T *)&m_local->m_len) != 0))
689 {
690 Close();
691 m_error = GSOCK_IOERR;
692 return GSOCK_IOERR;
693 }
694 }
695
696 return GSOCK_NOERROR;
697 }
698
699 /* Generic IO */
700
701 /* Like recv(), send(), ... */
702 int GSocket::Read(char *buffer, int size)
703 {
704 int ret;
705
706 /* Reenable INPUT events */
707 m_detected &= ~GSOCK_INPUT_FLAG;
708
709 if (m_fd == INVALID_SOCKET || m_server)
710 {
711 m_error = GSOCK_INVSOCK;
712 return -1;
713 }
714
715 /* If the socket is blocking, wait for data (with a timeout) */
716 if (Input_Timeout() == GSOCK_TIMEDOUT)
717 {
718 m_error = GSOCK_TIMEDOUT;
719 return -1;
720 }
721
722 /* Read the data */
723 if (m_stream)
724 ret = Recv_Stream(buffer, size);
725 else
726 ret = Recv_Dgram(buffer, size);
727
728 if (ret == SOCKET_ERROR)
729 {
730 if (WSAGetLastError() != WSAEWOULDBLOCK)
731 m_error = GSOCK_IOERR;
732 else
733 m_error = GSOCK_WOULDBLOCK;
734 return -1;
735 }
736
737 return ret;
738 }
739
740 int GSocket::Write(const char *buffer, int size)
741 {
742 int ret;
743
744 if (m_fd == INVALID_SOCKET || m_server)
745 {
746 m_error = GSOCK_INVSOCK;
747 return -1;
748 }
749
750 /* If the socket is blocking, wait for writability (with a timeout) */
751 if (Output_Timeout() == GSOCK_TIMEDOUT)
752 return -1;
753
754 /* Write the data */
755 if (m_stream)
756 ret = Send_Stream(buffer, size);
757 else
758 ret = Send_Dgram(buffer, size);
759
760 if (ret == SOCKET_ERROR)
761 {
762 if (WSAGetLastError() != WSAEWOULDBLOCK)
763 m_error = GSOCK_IOERR;
764 else
765 m_error = GSOCK_WOULDBLOCK;
766
767 /* Only reenable OUTPUT events after an error (just like WSAAsyncSelect
768 * does). Once the first OUTPUT event is received, users can assume
769 * that the socket is writable until a read operation fails. Only then
770 * will further OUTPUT events be posted.
771 */
772 m_detected &= ~GSOCK_OUTPUT_FLAG;
773 return -1;
774 }
775
776 return ret;
777 }
778
779 /* Attributes */
780
781 /* GSocket_SetNonBlocking:
782 * Sets the socket to non-blocking mode. All IO calls will return
783 * immediately.
784 */
785 void GSocket::SetNonBlocking(bool non_block)
786 {
787 m_non_blocking = non_block;
788 }
789
790 /* GSocket_SetTimeout:
791 * Sets the timeout for blocking calls. Time is expressed in
792 * milliseconds.
793 */
794 void GSocket::SetTimeout(unsigned long millis)
795 {
796 m_timeout.tv_sec = (millis / 1000);
797 m_timeout.tv_usec = (millis % 1000) * 1000;
798 }
799
800 /* GSocket_GetError:
801 * Returns the last error occurred for this socket. Note that successful
802 * operations do not clear this back to GSOCK_NOERROR, so use it only
803 * after an error.
804 */
805 GSocketError WXDLLIMPEXP_NET GSocket::GetError()
806 {
807 return m_error;
808 }
809
810 /* Callbacks */
811
812 /* GSOCK_INPUT:
813 * There is data to be read in the input buffer. If, after a read
814 * operation, there is still data available, the callback function will
815 * be called again.
816 * GSOCK_OUTPUT:
817 * The socket is available for writing. That is, the next write call
818 * won't block. This event is generated only once, when the connection is
819 * first established, and then only if a call failed with GSOCK_WOULDBLOCK,
820 * when the output buffer empties again. This means that the app should
821 * assume that it can write since the first OUTPUT event, and no more
822 * OUTPUT events will be generated unless an error occurs.
823 * GSOCK_CONNECTION:
824 * Connection successfully established, for client sockets, or incoming
825 * client connection, for server sockets. Wait for this event (also watch
826 * out for GSOCK_LOST) after you issue a nonblocking GSocket_Connect() call.
827 * GSOCK_LOST:
828 * The connection is lost (or a connection request failed); this could
829 * be due to a failure, or due to the peer closing it gracefully.
830 */
831
832 /* GSocket_SetCallback:
833 * Enables the callbacks specified by 'flags'. Note that 'flags'
834 * may be a combination of flags OR'ed toghether, so the same
835 * callback function can be made to accept different events.
836 * The callback function must have the following prototype:
837 *
838 * void function(GSocket *socket, GSocketEvent event, char *cdata)
839 */
840 void GSocket::SetCallback(GSocketEventFlags flags,
841 GSocketCallback callback, char *cdata)
842 {
843 int count;
844
845 for (count = 0; count < GSOCK_MAX_EVENT; count++)
846 {
847 if ((flags & (1 << count)) != 0)
848 {
849 m_cbacks[count] = callback;
850 m_data[count] = cdata;
851 }
852 }
853 }
854
855 /* GSocket_UnsetCallback:
856 * Disables all callbacks specified by 'flags', which may be a
857 * combination of flags OR'ed toghether.
858 */
859 void GSocket::UnsetCallback(GSocketEventFlags flags)
860 {
861 int count;
862
863 for (count = 0; count < GSOCK_MAX_EVENT; count++)
864 {
865 if ((flags & (1 << count)) != 0)
866 {
867 m_cbacks[count] = NULL;
868 m_data[count] = NULL;
869 }
870 }
871 }
872
873 GSocketError GSocket::GetSockOpt(int level, int optname,
874 void *optval, int *optlen)
875 {
876 if (getsockopt(m_fd, level, optname, (char*)optval, optlen) == 0)
877 {
878 return GSOCK_NOERROR;
879 }
880 return GSOCK_OPTERR;
881 }
882
883 GSocketError GSocket::SetSockOpt(int level, int optname,
884 const void *optval, int optlen)
885 {
886 if (setsockopt(m_fd, level, optname, (char*)optval, optlen) == 0)
887 {
888 return GSOCK_NOERROR;
889 }
890 return GSOCK_OPTERR;
891 }
892
893 /* Internals (IO) */
894
895 /* _GSocket_Input_Timeout:
896 * For blocking sockets, wait until data is available or
897 * until timeout ellapses.
898 */
899 GSocketError GSocket::Input_Timeout()
900 {
901 fd_set readfds;
902
903 if (!m_non_blocking)
904 {
905 FD_ZERO(&readfds);
906 FD_SET(m_fd, &readfds);
907 if (select(0, &readfds, NULL, NULL, &m_timeout) == 0)
908 {
909 m_error = GSOCK_TIMEDOUT;
910 return GSOCK_TIMEDOUT;
911 }
912 }
913 return GSOCK_NOERROR;
914 }
915
916 /* _GSocket_Output_Timeout:
917 * For blocking sockets, wait until data can be sent without
918 * blocking or until timeout ellapses.
919 */
920 GSocketError GSocket::Output_Timeout()
921 {
922 fd_set writefds;
923
924 if (!m_non_blocking)
925 {
926 FD_ZERO(&writefds);
927 FD_SET(m_fd, &writefds);
928 if (select(0, NULL, &writefds, NULL, &m_timeout) == 0)
929 {
930 m_error = GSOCK_TIMEDOUT;
931 return GSOCK_TIMEDOUT;
932 }
933 }
934 return GSOCK_NOERROR;
935 }
936
937 /* _GSocket_Connect_Timeout:
938 * For blocking sockets, wait until the connection is
939 * established or fails, or until timeout ellapses.
940 */
941 GSocketError GSocket::Connect_Timeout()
942 {
943 fd_set writefds;
944 fd_set exceptfds;
945
946 FD_ZERO(&writefds);
947 FD_ZERO(&exceptfds);
948 FD_SET(m_fd, &writefds);
949 FD_SET(m_fd, &exceptfds);
950 if (select(0, NULL, &writefds, &exceptfds, &m_timeout) == 0)
951 {
952 m_error = GSOCK_TIMEDOUT;
953 return GSOCK_TIMEDOUT;
954 }
955 if (!FD_ISSET(m_fd, &writefds))
956 {
957 m_error = GSOCK_IOERR;
958 return GSOCK_IOERR;
959 }
960
961 return GSOCK_NOERROR;
962 }
963
964 int GSocket::Recv_Stream(char *buffer, int size)
965 {
966 return recv(m_fd, buffer, size, 0);
967 }
968
969 int GSocket::Recv_Dgram(char *buffer, int size)
970 {
971 wxSockAddr from;
972 WX_SOCKLEN_T fromlen = sizeof(from);
973 int ret;
974 GSocketError err;
975
976 ret = recvfrom(m_fd, buffer, size, 0, (sockaddr*)&from, &fromlen);
977
978 if (ret == SOCKET_ERROR)
979 return SOCKET_ERROR;
980
981 /* Translate a system address into a GSocket address */
982 if (!m_peer)
983 {
984 m_peer = GAddress_new();
985 if (!m_peer)
986 {
987 m_error = GSOCK_MEMERR;
988 return -1;
989 }
990 }
991 err = _GAddress_translate_from(m_peer, (sockaddr*)&from, fromlen);
992 if (err != GSOCK_NOERROR)
993 {
994 GAddress_destroy(m_peer);
995 m_peer = NULL;
996 m_error = err;
997 return -1;
998 }
999
1000 return ret;
1001 }
1002
1003 int GSocket::Send_Stream(const char *buffer, int size)
1004 {
1005 return send(m_fd, buffer, size, 0);
1006 }
1007
1008 int GSocket::Send_Dgram(const char *buffer, int size)
1009 {
1010 struct sockaddr *addr;
1011 int len, ret;
1012 GSocketError err;
1013
1014 if (!m_peer)
1015 {
1016 m_error = GSOCK_INVADDR;
1017 return -1;
1018 }
1019
1020 err = _GAddress_translate_to(m_peer, &addr, &len);
1021 if (err != GSOCK_NOERROR)
1022 {
1023 m_error = err;
1024 return -1;
1025 }
1026
1027 ret = sendto(m_fd, buffer, size, 0, addr, len);
1028
1029 /* Frees memory allocated by _GAddress_translate_to */
1030 free(addr);
1031
1032 return ret;
1033 }
1034
1035 /* Compatibility functions for GSocket */
1036 GSocket *GSocket_new()
1037 {
1038 GSocket *newsocket = new GSocket();
1039 if(newsocket->IsOk())
1040 return newsocket;
1041 delete newsocket;
1042 return NULL;
1043 }
1044
1045
1046 /*
1047 * -------------------------------------------------------------------------
1048 * GAddress
1049 * -------------------------------------------------------------------------
1050 */
1051
1052 /* CHECK_ADDRESS verifies that the current address family is either
1053 * GSOCK_NOFAMILY or GSOCK_*family*, and if it is GSOCK_NOFAMILY, it
1054 * initalizes it to be a GSOCK_*family*. In other cases, it returns
1055 * an appropiate error code.
1056 *
1057 * CHECK_ADDRESS_RETVAL does the same but returning 'retval' on error.
1058 */
1059 #define CHECK_ADDRESS(address, family) \
1060 { \
1061 if (address->m_family == GSOCK_NOFAMILY) \
1062 if (_GAddress_Init_##family(address) != GSOCK_NOERROR) \
1063 return address->m_error; \
1064 if (address->m_family != GSOCK_##family) \
1065 { \
1066 address->m_error = GSOCK_INVADDR; \
1067 return GSOCK_INVADDR; \
1068 } \
1069 }
1070
1071 #define CHECK_ADDRESS_RETVAL(address, family, retval) \
1072 { \
1073 if (address->m_family == GSOCK_NOFAMILY) \
1074 if (_GAddress_Init_##family(address) != GSOCK_NOERROR) \
1075 return retval; \
1076 if (address->m_family != GSOCK_##family) \
1077 { \
1078 address->m_error = GSOCK_INVADDR; \
1079 return retval; \
1080 } \
1081 }
1082
1083
1084 GAddress *GAddress_new()
1085 {
1086 GAddress *address;
1087
1088 if ((address = (GAddress *) malloc(sizeof(GAddress))) == NULL)
1089 return NULL;
1090
1091 address->m_family = GSOCK_NOFAMILY;
1092 address->m_addr = NULL;
1093 address->m_len = 0;
1094
1095 return address;
1096 }
1097
1098 GAddress *GAddress_copy(GAddress *address)
1099 {
1100 GAddress *addr2;
1101
1102 if ((addr2 = (GAddress *) malloc(sizeof(GAddress))) == NULL)
1103 return NULL;
1104
1105 memcpy(addr2, address, sizeof(GAddress));
1106
1107 if (address->m_addr)
1108 {
1109 addr2->m_addr = (struct sockaddr *) malloc(addr2->m_len);
1110 if (addr2->m_addr == NULL)
1111 {
1112 free(addr2);
1113 return NULL;
1114 }
1115 memcpy(addr2->m_addr, address->m_addr, addr2->m_len);
1116 }
1117
1118 return addr2;
1119 }
1120
1121 void GAddress_destroy(GAddress *address)
1122 {
1123 if (address->m_addr)
1124 free(address->m_addr);
1125
1126 free(address);
1127 }
1128
1129 void GAddress_SetFamily(GAddress *address, GAddressType type)
1130 {
1131 address->m_family = type;
1132 }
1133
1134 GAddressType GAddress_GetFamily(GAddress *address)
1135 {
1136 return address->m_family;
1137 }
1138
1139 GSocketError _GAddress_translate_from(GAddress *address,
1140 struct sockaddr *addr, int len)
1141 {
1142 address->m_realfamily = addr->sa_family;
1143 switch (addr->sa_family)
1144 {
1145 case AF_INET:
1146 address->m_family = GSOCK_INET;
1147 break;
1148 case AF_UNIX:
1149 address->m_family = GSOCK_UNIX;
1150 break;
1151 #if wxUSE_IPV6
1152 case AF_INET6:
1153 address->m_family = GSOCK_INET6;
1154 break;
1155 #endif
1156 default:
1157 {
1158 address->m_error = GSOCK_INVOP;
1159 return GSOCK_INVOP;
1160 }
1161 }
1162
1163 if (address->m_addr)
1164 free(address->m_addr);
1165
1166 address->m_len = len;
1167 address->m_addr = (struct sockaddr *) malloc(len);
1168
1169 if (address->m_addr == NULL)
1170 {
1171 address->m_error = GSOCK_MEMERR;
1172 return GSOCK_MEMERR;
1173 }
1174 memcpy(address->m_addr, addr, len);
1175
1176 return GSOCK_NOERROR;
1177 }
1178
1179 GSocketError _GAddress_translate_to(GAddress *address,
1180 struct sockaddr **addr, int *len)
1181 {
1182 if (!address->m_addr)
1183 {
1184 address->m_error = GSOCK_INVADDR;
1185 return GSOCK_INVADDR;
1186 }
1187
1188 *len = address->m_len;
1189 *addr = (struct sockaddr *) malloc(address->m_len);
1190 if (*addr == NULL)
1191 {
1192 address->m_error = GSOCK_MEMERR;
1193 return GSOCK_MEMERR;
1194 }
1195
1196 memcpy(*addr, address->m_addr, address->m_len);
1197 return GSOCK_NOERROR;
1198 }
1199
1200 /*
1201 * -------------------------------------------------------------------------
1202 * Internet address family
1203 * -------------------------------------------------------------------------
1204 */
1205
1206 GSocketError _GAddress_Init_INET(GAddress *address)
1207 {
1208 address->m_len = sizeof(struct sockaddr_in);
1209 address->m_addr = (struct sockaddr *) malloc(address->m_len);
1210 if (address->m_addr == NULL)
1211 {
1212 address->m_error = GSOCK_MEMERR;
1213 return GSOCK_MEMERR;
1214 }
1215
1216 address->m_family = GSOCK_INET;
1217 address->m_realfamily = AF_INET;
1218 ((struct sockaddr_in *)address->m_addr)->sin_family = AF_INET;
1219 ((struct sockaddr_in *)address->m_addr)->sin_addr.s_addr = INADDR_ANY;
1220
1221 return GSOCK_NOERROR;
1222 }
1223
1224 GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname)
1225 {
1226 struct hostent *he;
1227 struct in_addr *addr;
1228
1229 CHECK_ADDRESS(address, INET);
1230
1231 addr = &(((struct sockaddr_in *)address->m_addr)->sin_addr);
1232
1233 addr->s_addr = inet_addr(hostname);
1234
1235 /* If it is a numeric host name, convert it now */
1236 if (addr->s_addr == INADDR_NONE)
1237 {
1238 struct in_addr *array_addr;
1239
1240 /* It is a real name, we solve it */
1241 if ((he = gethostbyname(hostname)) == NULL)
1242 {
1243 /* addr->s_addr = INADDR_NONE just done by inet_addr() above */
1244 address->m_error = GSOCK_NOHOST;
1245 return GSOCK_NOHOST;
1246 }
1247 array_addr = (struct in_addr *) *(he->h_addr_list);
1248 addr->s_addr = array_addr[0].s_addr;
1249 }
1250 return GSOCK_NOERROR;
1251 }
1252
1253 GSocketError GAddress_INET_SetBroadcastAddress(GAddress *address)
1254 {
1255 return GAddress_INET_SetHostAddress(address, INADDR_BROADCAST);
1256 }
1257
1258 GSocketError GAddress_INET_SetAnyAddress(GAddress *address)
1259 {
1260 return GAddress_INET_SetHostAddress(address, INADDR_ANY);
1261 }
1262
1263 GSocketError GAddress_INET_SetHostAddress(GAddress *address,
1264 unsigned long hostaddr)
1265 {
1266 struct in_addr *addr;
1267
1268 CHECK_ADDRESS(address, INET);
1269
1270 addr = &(((struct sockaddr_in *)address->m_addr)->sin_addr);
1271 addr->s_addr = htonl(hostaddr);
1272
1273 return GSOCK_NOERROR;
1274 }
1275
1276 GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
1277 const char *protocol)
1278 {
1279 struct servent *se;
1280 struct sockaddr_in *addr;
1281
1282 CHECK_ADDRESS(address, INET);
1283
1284 if (!port)
1285 {
1286 address->m_error = GSOCK_INVPORT;
1287 return GSOCK_INVPORT;
1288 }
1289
1290 se = getservbyname(port, protocol);
1291 if (!se)
1292 {
1293 if (isdigit(port[0]))
1294 {
1295 int port_int;
1296
1297 port_int = atoi(port);
1298 addr = (struct sockaddr_in *)address->m_addr;
1299 addr->sin_port = htons((u_short) port_int);
1300 return GSOCK_NOERROR;
1301 }
1302
1303 address->m_error = GSOCK_INVPORT;
1304 return GSOCK_INVPORT;
1305 }
1306
1307 addr = (struct sockaddr_in *)address->m_addr;
1308 addr->sin_port = se->s_port;
1309
1310 return GSOCK_NOERROR;
1311 }
1312
1313 GSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port)
1314 {
1315 struct sockaddr_in *addr;
1316
1317 CHECK_ADDRESS(address, INET);
1318
1319 addr = (struct sockaddr_in *)address->m_addr;
1320 addr->sin_port = htons(port);
1321
1322 return GSOCK_NOERROR;
1323 }
1324
1325 GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname, size_t sbuf)
1326 {
1327 struct hostent *he;
1328 char *addr_buf;
1329 struct sockaddr_in *addr;
1330
1331 CHECK_ADDRESS(address, INET);
1332
1333 addr = (struct sockaddr_in *)address->m_addr;
1334 addr_buf = (char *)&(addr->sin_addr);
1335
1336 he = gethostbyaddr(addr_buf, sizeof(addr->sin_addr), AF_INET);
1337 if (he == NULL)
1338 {
1339 address->m_error = GSOCK_NOHOST;
1340 return GSOCK_NOHOST;
1341 }
1342
1343 strncpy(hostname, he->h_name, sbuf);
1344
1345 return GSOCK_NOERROR;
1346 }
1347
1348 unsigned long GAddress_INET_GetHostAddress(GAddress *address)
1349 {
1350 struct sockaddr_in *addr;
1351
1352 CHECK_ADDRESS_RETVAL(address, INET, 0);
1353
1354 addr = (struct sockaddr_in *)address->m_addr;
1355
1356 return ntohl(addr->sin_addr.s_addr);
1357 }
1358
1359 unsigned short GAddress_INET_GetPort(GAddress *address)
1360 {
1361 struct sockaddr_in *addr;
1362
1363 CHECK_ADDRESS_RETVAL(address, INET, 0);
1364
1365 addr = (struct sockaddr_in *)address->m_addr;
1366 return ntohs(addr->sin_port);
1367 }
1368
1369
1370 #if wxUSE_IPV6
1371 /*
1372 * -------------------------------------------------------------------------
1373 * Internet IPv6 address family
1374 * -------------------------------------------------------------------------
1375 */
1376 #include "ws2tcpip.h"
1377
1378 #ifdef __VISUALC__
1379 #pragma comment(lib,"ws2_32")
1380 #endif // __VISUALC__
1381
1382 GSocketError _GAddress_Init_INET6(GAddress *address)
1383 {
1384 struct in6_addr any_address = IN6ADDR_ANY_INIT;
1385 address->m_len = sizeof(struct sockaddr_in6);
1386 address->m_addr = (struct sockaddr *) malloc(address->m_len);
1387 if (address->m_addr == NULL)
1388 {
1389 address->m_error = GSOCK_MEMERR;
1390 return GSOCK_MEMERR;
1391 }
1392 memset(address->m_addr,0,address->m_len);
1393
1394 address->m_family = GSOCK_INET6;
1395 address->m_realfamily = AF_INET6;
1396 ((struct sockaddr_in6 *)address->m_addr)->sin6_family = AF_INET6;
1397 ((struct sockaddr_in6 *)address->m_addr)->sin6_addr = any_address;
1398
1399 return GSOCK_NOERROR;
1400 }
1401
1402 GSocketError GAddress_INET6_SetHostName(GAddress *address, const char *hostname)
1403 {
1404 CHECK_ADDRESS(address, INET6);
1405
1406 addrinfo hints;
1407 memset( & hints, 0, sizeof( hints ) );
1408 hints.ai_family = AF_INET6;
1409 addrinfo * info = 0;
1410 if ( getaddrinfo( hostname, "0", & hints, & info ) || ! info )
1411 {
1412 address->m_error = GSOCK_NOHOST;
1413 return GSOCK_NOHOST;
1414 }
1415
1416 memcpy( address->m_addr, info->ai_addr, info->ai_addrlen );
1417 freeaddrinfo( info );
1418 return GSOCK_NOERROR;
1419 }
1420
1421 GSocketError GAddress_INET6_SetAnyAddress(GAddress *address)
1422 {
1423 CHECK_ADDRESS(address, INET6);
1424
1425 struct in6_addr addr;
1426 memset( & addr, 0, sizeof( addr ) );
1427 return GAddress_INET6_SetHostAddress(address, addr);
1428 }
1429 GSocketError GAddress_INET6_SetHostAddress(GAddress *address,
1430 struct in6_addr hostaddr)
1431 {
1432 CHECK_ADDRESS(address, INET6);
1433
1434 ((struct sockaddr_in6 *)address->m_addr)->sin6_addr = hostaddr;
1435
1436 return GSOCK_NOERROR;
1437 }
1438
1439 GSocketError GAddress_INET6_SetPortName(GAddress *address, const char *port,
1440 const char *protocol)
1441 {
1442 struct servent *se;
1443 struct sockaddr_in6 *addr;
1444
1445 CHECK_ADDRESS(address, INET6);
1446
1447 if (!port)
1448 {
1449 address->m_error = GSOCK_INVPORT;
1450 return GSOCK_INVPORT;
1451 }
1452
1453 se = getservbyname(port, protocol);
1454 if (!se)
1455 {
1456 if (isdigit((unsigned char) port[0]))
1457 {
1458 int port_int;
1459
1460 port_int = atoi(port);
1461 addr = (struct sockaddr_in6 *)address->m_addr;
1462 addr->sin6_port = htons((u_short) port_int);
1463 return GSOCK_NOERROR;
1464 }
1465
1466 address->m_error = GSOCK_INVPORT;
1467 return GSOCK_INVPORT;
1468 }
1469
1470 addr = (struct sockaddr_in6 *)address->m_addr;
1471 addr->sin6_port = se->s_port;
1472
1473 return GSOCK_NOERROR;
1474 }
1475
1476 GSocketError GAddress_INET6_SetPort(GAddress *address, unsigned short port)
1477 {
1478 struct sockaddr_in6 *addr;
1479
1480 CHECK_ADDRESS(address, INET6);
1481
1482 addr = (struct sockaddr_in6 *)address->m_addr;
1483 addr->sin6_port = htons(port);
1484
1485 return GSOCK_NOERROR;
1486 }
1487
1488 GSocketError GAddress_INET6_GetHostName(GAddress *address, char *hostname, size_t sbuf)
1489 {
1490 struct hostent *he;
1491 char *addr_buf;
1492 struct sockaddr_in6 *addr;
1493
1494 CHECK_ADDRESS(address, INET6);
1495
1496 addr = (struct sockaddr_in6 *)address->m_addr;
1497 addr_buf = (char *)&(addr->sin6_addr);
1498
1499 he = gethostbyaddr(addr_buf, sizeof(addr->sin6_addr), AF_INET6);
1500 if (he == NULL)
1501 {
1502 address->m_error = GSOCK_NOHOST;
1503 return GSOCK_NOHOST;
1504 }
1505
1506 strncpy(hostname, he->h_name, sbuf);
1507
1508 return GSOCK_NOERROR;
1509 }
1510
1511 GSocketError GAddress_INET6_GetHostAddress(GAddress *address,struct in6_addr *hostaddr)
1512 {
1513 CHECK_ADDRESS_RETVAL(address, INET6, GSOCK_INVADDR);
1514 *hostaddr = ( (struct sockaddr_in6 *)address->m_addr )->sin6_addr;
1515 return GSOCK_NOERROR;
1516 }
1517
1518 unsigned short GAddress_INET6_GetPort(GAddress *address)
1519 {
1520 CHECK_ADDRESS_RETVAL(address, INET6, 0);
1521
1522 return ntohs( ((struct sockaddr_in6 *)address->m_addr)->sin6_port );
1523 }
1524
1525 #endif // wxUSE_IPV6
1526
1527 /*
1528 * -------------------------------------------------------------------------
1529 * Unix address family
1530 * -------------------------------------------------------------------------
1531 */
1532
1533 GSocketError _GAddress_Init_UNIX(GAddress *address)
1534 {
1535 address->m_error = GSOCK_INVADDR;
1536 return GSOCK_INVADDR;
1537 }
1538
1539 GSocketError GAddress_UNIX_SetPath(GAddress *address, const char *WXUNUSED(path))
1540 {
1541 address->m_error = GSOCK_INVADDR;
1542 return GSOCK_INVADDR;
1543 }
1544
1545 GSocketError GAddress_UNIX_GetPath(GAddress *address, char *WXUNUSED(path), size_t WXUNUSED(sbuf))
1546 {
1547 address->m_error = GSOCK_INVADDR;
1548 return GSOCK_INVADDR;
1549 }
1550
1551 #endif // wxUSE_SOCKETS