1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
4 * Copyright: (c) Guilhem Lavaux
5 * Licence: wxWindows Licence
6 * Authors: David Elliott (C++ conversion, maintainer)
8 * Guillermo Rodriguez Garcia <guille@iies.es>
9 * Purpose: GSocket main Unix and OS/2 file
10 * Licence: The wxWindows licence
12 * -------------------------------------------------------------------------
16 * PLEASE don't put C++ comments here - this is a C source file.
19 #ifndef __GSOCKET_STANDALONE__
23 #if defined(__VISAGECPP__)
24 /* Seems to be needed by Visual Age C++, though I don't see how it manages
25 to not break on including a C++ header into a plain C source file */
27 #define BSD_SELECT /* use Berkley Sockets select */
30 #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
33 #include <sys/types.h>
38 #include <netinet/in.h>
41 #include <sys/ioctl.h>
47 u_char sun_len
; /* sockaddr len including null */
48 u_char sun_family
; /* AF_UNIX */
49 char sun_path
[108]; /* path name (gag) */
52 #include <sys/socket.h>
58 #include <netinet/in.h>
59 #include <arpa/inet.h>
66 #include <machine/endian.h>
72 #define EBADF SOCEBADF
78 #include <sys/socket.h>
79 #include <sys/ioctl.h>
80 #include <sys/select.h>
82 #define close(a) soclose(a)
83 #define select(a,b,c,d,e) bsdselect(a,b,c,d,e)
84 int _System
bsdselect(int,
89 int _System
soclose(int);
93 #include <sys/select.h>
101 # include <sys/filio.h>
104 # include <bstring.h>
107 # include <strings.h>
114 # define SOCKLEN_T unsigned int
118 # define SOCKLEN_T socklen_t
120 # elif defined(__WXMAC__)
121 # define SOCKLEN_T socklen_t
123 # define SOCKLEN_T int
127 #endif /* SOCKLEN_T */
130 #define SOCKOPTLEN_T SOCKLEN_T
134 * MSW defines this, Unices don't.
136 #ifndef INVALID_SOCKET
137 #define INVALID_SOCKET -1
140 /* UnixWare reportedly needs this for FIONBIO definition */
142 #include <sys/filio.h>
146 * INADDR_BROADCAST is identical to INADDR_NONE which is not defined
147 * on all systems. INADDR_BROADCAST should be fine to indicate an error.
150 #define INADDR_NONE INADDR_BROADCAST
153 #define MASK_SIGNAL() \
155 void (*old_handler)(int); \
157 old_handler = signal(SIGPIPE, SIG_IGN);
159 #define UNMASK_SIGNAL() \
160 signal(SIGPIPE, old_handler); \
163 /* If a SIGPIPE is issued by a socket call on a remotely closed socket,
164 the program will "crash" unless it explicitly handles the SIGPIPE.
165 By using MSG_NOSIGNAL, the SIGPIPE is suppressed. Later, we will
166 use SO_NOSIGPIPE (if available), the BSD equivalent. */
168 # define GSOCKET_MSG_NOSIGNAL MSG_NOSIGNAL
169 #else /* MSG_NOSIGNAL not available (FreeBSD including OS X) */
170 # define GSOCKET_MSG_NOSIGNAL 0
171 #endif /* MSG_NOSIGNAL */
173 #ifndef __GSOCKET_STANDALONE__
174 # include "wx/unix/gsockunx.h"
175 # include "wx/gsocket.h"
177 # include "gsockunx.h"
178 # include "gsocket.h"
179 #endif /* __GSOCKET_STANDALONE__ */
181 /* debugging helpers */
182 #ifdef __GSOCKET_DEBUG__
183 # define GSocket_Debug(args) printf args
185 # define GSocket_Debug(args)
186 #endif /* __GSOCKET_DEBUG__ */
188 /* Table of GUI-related functions. We must call them indirectly because
189 * of wxBase and GUI separation: */
191 static GSocketGUIFunctionsTable
*gs_gui_functions
;
193 class GSocketGUIFunctionsTableNull
: public GSocketGUIFunctionsTable
196 virtual bool OnInit();
197 virtual void OnExit();
198 virtual bool CanUseEventLoop();
199 virtual bool Init_Socket(GSocket
*socket
);
200 virtual void Destroy_Socket(GSocket
*socket
);
201 virtual void Install_Callback(GSocket
*socket
, GSocketEvent event
);
202 virtual void Uninstall_Callback(GSocket
*socket
, GSocketEvent event
);
203 virtual void Enable_Events(GSocket
*socket
);
204 virtual void Disable_Events(GSocket
*socket
);
207 bool GSocketGUIFunctionsTableNull::OnInit()
209 void GSocketGUIFunctionsTableNull::OnExit()
211 bool GSocketGUIFunctionsTableNull::CanUseEventLoop()
213 bool GSocketGUIFunctionsTableNull::Init_Socket(GSocket
*socket
)
215 void GSocketGUIFunctionsTableNull::Destroy_Socket(GSocket
*socket
)
217 void GSocketGUIFunctionsTableNull::Install_Callback(GSocket
*socket
, GSocketEvent event
)
219 void GSocketGUIFunctionsTableNull::Uninstall_Callback(GSocket
*socket
, GSocketEvent event
)
221 void GSocketGUIFunctionsTableNull::Enable_Events(GSocket
*socket
)
223 void GSocketGUIFunctionsTableNull::Disable_Events(GSocket
*socket
)
225 /* Global initialisers */
227 void GSocket_SetGUIFunctions(GSocketGUIFunctionsTable
*guifunc
)
229 gs_gui_functions
= guifunc
;
232 int GSocket_Init(void)
234 if (!gs_gui_functions
)
236 static GSocketGUIFunctionsTableNull table
;
237 gs_gui_functions
= &table
;
239 if ( !gs_gui_functions
->OnInit() )
244 void GSocket_Cleanup(void)
246 if (gs_gui_functions
)
248 gs_gui_functions
->OnExit();
252 /* Constructors / Destructors for GSocket */
258 m_fd
= INVALID_SOCKET
;
259 for (i
=0;i
<GSOCK_MAX_EVENT
;i
++)
266 m_error
= GSOCK_NOERROR
;
269 m_gui_dependent
= NULL
;
270 m_non_blocking
= false;
272 m_timeout
= 10*60*1000;
273 /* 10 minutes * 60 sec * 1000 millisec */
274 m_establishing
= false;
276 assert(gs_gui_functions
);
277 /* Per-socket GUI-specific initialization */
278 m_ok
= gs_gui_functions
->Init_Socket(this);
281 void GSocket::Close()
283 gs_gui_functions
->Disable_Events(this);
284 /* gsockosx.c calls CFSocketInvalidate which closes the socket for us */
285 #if !(defined(__DARWIN__) && (defined(__WXMAC__) || defined(__WXCOCOA__)))
288 m_fd
= INVALID_SOCKET
;
295 /* Check that the socket is really shutdowned */
296 if (m_fd
!= INVALID_SOCKET
)
299 /* Per-socket GUI-specific cleanup */
300 gs_gui_functions
->Destroy_Socket(this);
302 /* Destroy private addresses */
304 GAddress_destroy(m_local
);
307 GAddress_destroy(m_peer
);
311 * Disallow further read/write operations on this socket, close
312 * the fd and disable all callbacks.
314 void GSocket::Shutdown()
320 /* If socket has been created, shutdown it */
321 if (m_fd
!= INVALID_SOCKET
)
327 /* Disable GUI callbacks */
328 for (evt
= 0; evt
< GSOCK_MAX_EVENT
; evt
++)
329 m_cbacks
[evt
] = NULL
;
331 m_detected
= GSOCK_LOST_FLAG
;
334 /* Address handling */
340 * Set or get the local or peer address for this socket. The 'set'
341 * functions return GSOCK_NOERROR on success, an error code otherwise.
342 * The 'get' functions return a pointer to a GAddress object on success,
343 * or NULL otherwise, in which case they set the error code of the
344 * corresponding GSocket.
347 * GSOCK_INVSOCK - the socket is not valid.
348 * GSOCK_INVADDR - the address is not valid.
350 GSocketError
GSocket::SetLocal(GAddress
*address
)
354 /* the socket must be initialized, or it must be a server */
355 if ((m_fd
!= INVALID_SOCKET
&& !m_server
))
357 m_error
= GSOCK_INVSOCK
;
358 return GSOCK_INVSOCK
;
362 if (address
== NULL
|| address
->m_family
== GSOCK_NOFAMILY
)
364 m_error
= GSOCK_INVADDR
;
365 return GSOCK_INVADDR
;
369 GAddress_destroy(m_local
);
371 m_local
= GAddress_copy(address
);
373 return GSOCK_NOERROR
;
376 GSocketError
GSocket::SetPeer(GAddress
*address
)
381 if (address
== NULL
|| address
->m_family
== GSOCK_NOFAMILY
)
383 m_error
= GSOCK_INVADDR
;
384 return GSOCK_INVADDR
;
388 GAddress_destroy(m_peer
);
390 m_peer
= GAddress_copy(address
);
392 return GSOCK_NOERROR
;
395 GAddress
*GSocket::GetLocal()
398 struct sockaddr addr
;
399 SOCKLEN_T size
= sizeof(addr
);
404 /* try to get it from the m_local var first */
406 return GAddress_copy(m_local
);
408 /* else, if the socket is initialized, try getsockname */
409 if (m_fd
== INVALID_SOCKET
)
411 m_error
= GSOCK_INVSOCK
;
415 if (getsockname(m_fd
, &addr
, (SOCKLEN_T
*) &size
) < 0)
417 m_error
= GSOCK_IOERR
;
421 /* got a valid address from getsockname, create a GAddress object */
422 address
= GAddress_new();
425 m_error
= GSOCK_MEMERR
;
429 err
= _GAddress_translate_from(address
, &addr
, size
);
430 if (err
!= GSOCK_NOERROR
)
432 GAddress_destroy(address
);
440 GAddress
*GSocket::GetPeer()
444 /* try to get it from the m_peer var */
446 return GAddress_copy(m_peer
);
451 /* Server specific parts */
453 /* GSocket_SetServer:
454 * Sets up this socket as a server. The local address must have been
455 * set with GSocket_SetLocal() before GSocket_SetServer() is called.
456 * Returns GSOCK_NOERROR on success, one of the following otherwise:
459 * GSOCK_INVSOCK - the socket is in use.
460 * GSOCK_INVADDR - the local address has not been set.
461 * GSOCK_IOERR - low-level error.
463 GSocketError
GSocket::SetServer()
469 /* must not be in use */
470 if (m_fd
!= INVALID_SOCKET
)
472 m_error
= GSOCK_INVSOCK
;
473 return GSOCK_INVSOCK
;
476 /* the local addr must have been set */
479 m_error
= GSOCK_INVADDR
;
480 return GSOCK_INVADDR
;
483 /* Initialize all fields */
487 /* Create the socket */
488 m_fd
= socket(m_local
->m_realfamily
, SOCK_STREAM
, 0);
490 if (m_fd
== INVALID_SOCKET
)
492 m_error
= GSOCK_IOERR
;
496 /* FreeBSD variants can't use MSG_NOSIGNAL, and instead use a socket option */
498 setsockopt(m_fd
, SOL_SOCKET
, SO_NOSIGPIPE
, (const char*)&arg
, sizeof(u_long
));
501 ioctl(m_fd
, FIONBIO
, &arg
);
502 gs_gui_functions
->Enable_Events(this);
504 /* allow a socket to re-bind if the socket is in the TIME_WAIT
505 state after being previously closed.
508 setsockopt(m_fd
, SOL_SOCKET
, SO_REUSEADDR
, (const char*)&arg
, sizeof(u_long
));
510 /* Bind to the local address,
511 * retrieve the actual address bound,
512 * and listen up to 5 connections.
514 if ((bind(m_fd
, m_local
->m_addr
, m_local
->m_len
) != 0) ||
517 (SOCKLEN_T
*) &m_local
->m_len
) != 0) ||
518 (listen(m_fd
, 5) != 0))
521 m_error
= GSOCK_IOERR
;
525 return GSOCK_NOERROR
;
528 /* GSocket_WaitConnection:
529 * Waits for an incoming client connection. Returns a pointer to
530 * a GSocket object, or NULL if there was an error, in which case
531 * the last error field will be updated for the calling GSocket.
533 * Error codes (set in the calling GSocket)
534 * GSOCK_INVSOCK - the socket is not valid or not a server.
535 * GSOCK_TIMEDOUT - timeout, no incoming connections.
536 * GSOCK_WOULDBLOCK - the call would block and the socket is nonblocking.
537 * GSOCK_MEMERR - couldn't allocate memory.
538 * GSOCK_IOERR - low-level error.
540 GSocket
*GSocket::WaitConnection()
542 struct sockaddr from
;
543 SOCKLEN_T fromlen
= sizeof(from
);
550 /* If the socket has already been created, we exit immediately */
551 if (m_fd
== INVALID_SOCKET
|| !m_server
)
553 m_error
= GSOCK_INVSOCK
;
557 /* Create a GSocket object for the new connection */
558 connection
= GSocket_new();
562 m_error
= GSOCK_MEMERR
;
566 /* Wait for a connection (with timeout) */
567 if (Input_Timeout() == GSOCK_TIMEDOUT
)
570 /* m_error set by _GSocket_Input_Timeout */
574 connection
->m_fd
= accept(m_fd
, &from
, (SOCKLEN_T
*) &fromlen
);
576 /* Reenable CONNECTION events */
577 Enable(GSOCK_CONNECTION
);
579 if (connection
->m_fd
== INVALID_SOCKET
)
581 if (errno
== EWOULDBLOCK
)
582 m_error
= GSOCK_WOULDBLOCK
;
584 m_error
= GSOCK_IOERR
;
590 /* Initialize all fields */
591 connection
->m_server
= false;
592 connection
->m_stream
= true;
594 /* Setup the peer address field */
595 connection
->m_peer
= GAddress_new();
596 if (!connection
->m_peer
)
599 m_error
= GSOCK_MEMERR
;
602 err
= _GAddress_translate_from(connection
->m_peer
, &from
, fromlen
);
603 if (err
!= GSOCK_NOERROR
)
609 #if defined(__EMX__) || defined(__VISAGECPP__)
610 ioctl(connection
->m_fd
, FIONBIO
, (char*)&arg
, sizeof(arg
));
612 ioctl(connection
->m_fd
, FIONBIO
, &arg
);
614 gs_gui_functions
->Enable_Events(connection
);
619 bool GSocket::SetReusable()
621 /* socket must not be null, and must not be in use/already bound */
622 if (this && m_fd
== INVALID_SOCKET
) {
629 /* Client specific parts */
632 * For stream (connection oriented) sockets, GSocket_Connect() tries
633 * to establish a client connection to a server using the peer address
634 * as established with GSocket_SetPeer(). Returns GSOCK_NOERROR if the
635 * connection has been successfully established, or one of the error
636 * codes listed below. Note that for nonblocking sockets, a return
637 * value of GSOCK_WOULDBLOCK doesn't mean a failure. The connection
638 * request can be completed later; you should use GSocket_Select()
639 * to poll for GSOCK_CONNECTION | GSOCK_LOST, or wait for the
640 * corresponding asynchronous events.
642 * For datagram (non connection oriented) sockets, GSocket_Connect()
643 * just sets the peer address established with GSocket_SetPeer() as
644 * default destination.
647 * GSOCK_INVSOCK - the socket is in use or not valid.
648 * GSOCK_INVADDR - the peer address has not been established.
649 * GSOCK_TIMEDOUT - timeout, the connection failed.
650 * GSOCK_WOULDBLOCK - connection in progress (nonblocking sockets only)
651 * GSOCK_MEMERR - couldn't allocate memory.
652 * GSOCK_IOERR - low-level error.
654 GSocketError
GSocket::Connect(GSocketStream stream
)
661 /* Enable CONNECTION events (needed for nonblocking connections) */
662 Enable(GSOCK_CONNECTION
);
664 if (m_fd
!= INVALID_SOCKET
)
666 m_error
= GSOCK_INVSOCK
;
667 return GSOCK_INVSOCK
;
672 m_error
= GSOCK_INVADDR
;
673 return GSOCK_INVADDR
;
676 /* Streamed or dgram socket? */
677 m_stream
= (stream
== GSOCK_STREAMED
);
679 m_establishing
= false;
681 /* Create the socket */
682 m_fd
= socket(m_peer
->m_realfamily
,
683 m_stream
? SOCK_STREAM
: SOCK_DGRAM
, 0);
685 if (m_fd
== INVALID_SOCKET
)
687 m_error
= GSOCK_IOERR
;
691 /* FreeBSD variants can't use MSG_NOSIGNAL, and instead use a socket option */
693 setsockopt(m_fd
, SOL_SOCKET
, SO_NOSIGPIPE
, (const char*)&arg
, sizeof(u_long
));
696 #if defined(__EMX__) || defined(__VISAGECPP__)
697 ioctl(m_fd
, FIONBIO
, (char*)&arg
, sizeof(arg
));
699 ioctl(m_fd
, FIONBIO
, &arg
);
702 /* Connect it to the peer address, with a timeout (see below) */
703 ret
= connect(m_fd
, m_peer
->m_addr
, m_peer
->m_len
);
705 /* We only call Enable_Events if we know e aren't shutting down the socket */
709 gs_gui_functions
->Enable_Events(this);
716 /* If connect failed with EINPROGRESS and the GSocket object
717 * is in blocking mode, we select() for the specified timeout
718 * checking for writability to see if the connection request
721 if ((err
== EINPROGRESS
) && (!m_non_blocking
))
723 if (Output_Timeout() == GSOCK_TIMEDOUT
)
726 /* m_error is set in _GSocket_Output_Timeout */
727 return GSOCK_TIMEDOUT
;
732 SOCKOPTLEN_T len
= sizeof(error
);
734 getsockopt(m_fd
, SOL_SOCKET
, SO_ERROR
, (char*) &error
, &len
);
736 gs_gui_functions
->Enable_Events(this);
739 return GSOCK_NOERROR
;
743 /* If connect failed with EINPROGRESS and the GSocket object
744 * is set to nonblocking, we set m_error to GSOCK_WOULDBLOCK
745 * (and return GSOCK_WOULDBLOCK) but we don't close the socket;
746 * this way if the connection completes, a GSOCK_CONNECTION
747 * event will be generated, if enabled.
749 if ((err
== EINPROGRESS
) && (m_non_blocking
))
751 m_establishing
= true;
752 m_error
= GSOCK_WOULDBLOCK
;
753 return GSOCK_WOULDBLOCK
;
756 /* If connect failed with an error other than EINPROGRESS,
757 * then the call to GSocket_Connect has failed.
760 m_error
= GSOCK_IOERR
;
764 return GSOCK_NOERROR
;
767 /* Datagram sockets */
769 /* GSocket_SetNonOriented:
770 * Sets up this socket as a non-connection oriented (datagram) socket.
771 * Before using this function, the local address must have been set
772 * with GSocket_SetLocal(), or the call will fail. Returns GSOCK_NOERROR
773 * on success, or one of the following otherwise.
776 * GSOCK_INVSOCK - the socket is in use.
777 * GSOCK_INVADDR - the local address has not been set.
778 * GSOCK_IOERR - low-level error.
780 GSocketError
GSocket::SetNonOriented()
786 if (m_fd
!= INVALID_SOCKET
)
788 m_error
= GSOCK_INVSOCK
;
789 return GSOCK_INVSOCK
;
794 m_error
= GSOCK_INVADDR
;
795 return GSOCK_INVADDR
;
798 /* Initialize all fields */
802 /* Create the socket */
803 m_fd
= socket(m_local
->m_realfamily
, SOCK_DGRAM
, 0);
805 if (m_fd
== INVALID_SOCKET
)
807 m_error
= GSOCK_IOERR
;
810 #if defined(__EMX__) || defined(__VISAGECPP__)
811 ioctl(m_fd
, FIONBIO
, (char*)&arg
, sizeof(arg
));
813 ioctl(m_fd
, FIONBIO
, &arg
);
815 gs_gui_functions
->Enable_Events(this);
817 /* Bind to the local address,
818 * and retrieve the actual address bound.
820 if ((bind(m_fd
, m_local
->m_addr
, m_local
->m_len
) != 0) ||
823 (SOCKLEN_T
*) &m_local
->m_len
) != 0))
826 m_error
= GSOCK_IOERR
;
830 return GSOCK_NOERROR
;
835 /* Like recv(), send(), ... */
836 int GSocket::Read(char *buffer
, int size
)
842 if (m_fd
== INVALID_SOCKET
|| m_server
)
844 m_error
= GSOCK_INVSOCK
;
848 /* Disable events during query of socket status */
849 Disable(GSOCK_INPUT
);
851 /* If the socket is blocking, wait for data (with a timeout) */
852 if (Input_Timeout() == GSOCK_TIMEDOUT
)
853 /* We no longer return here immediately, otherwise socket events would not be re-enabled! */
858 ret
= Recv_Stream(buffer
, size
);
860 ret
= Recv_Dgram(buffer
, size
);
865 if ((errno
== EWOULDBLOCK
) || (errno
== EAGAIN
))
866 m_error
= GSOCK_WOULDBLOCK
;
868 m_error
= GSOCK_IOERR
;
871 /* Enable events again now that we are done processing */
877 int GSocket::Write(const char *buffer
, int size
)
883 GSocket_Debug(( "GSocket_Write #1, size %d\n", size
));
885 if (m_fd
== INVALID_SOCKET
|| m_server
)
887 m_error
= GSOCK_INVSOCK
;
891 GSocket_Debug(( "GSocket_Write #2, size %d\n", size
));
893 /* If the socket is blocking, wait for writability (with a timeout) */
894 if (Output_Timeout() == GSOCK_TIMEDOUT
)
897 GSocket_Debug(( "GSocket_Write #3, size %d\n", size
));
901 ret
= Send_Stream(buffer
, size
);
903 ret
= Send_Dgram(buffer
, size
);
905 GSocket_Debug(( "GSocket_Write #4, size %d\n", size
));
909 if ((errno
== EWOULDBLOCK
) || (errno
== EAGAIN
))
911 m_error
= GSOCK_WOULDBLOCK
;
912 GSocket_Debug(( "GSocket_Write error WOULDBLOCK\n" ));
916 m_error
= GSOCK_IOERR
;
917 GSocket_Debug(( "GSocket_Write error IOERR\n" ));
920 /* Only reenable OUTPUT events after an error (just like WSAAsyncSelect
921 * in MSW). Once the first OUTPUT event is received, users can assume
922 * that the socket is writable until a read operation fails. Only then
923 * will further OUTPUT events be posted.
925 Enable(GSOCK_OUTPUT
);
929 GSocket_Debug(( "GSocket_Write #5, size %d ret %d\n", size
, ret
));
935 * Polls the socket to determine its status. This function will
936 * check for the events specified in the 'flags' parameter, and
937 * it will return a mask indicating which operations can be
938 * performed. This function won't block, regardless of the
939 * mode (blocking | nonblocking) of the socket.
941 GSocketEventFlags
GSocket::Select(GSocketEventFlags flags
)
943 if (!gs_gui_functions
->CanUseEventLoop())
946 GSocketEventFlags result
= 0;
954 /* Do not use a static struct, Linux can garble it */
955 tv
.tv_sec
= m_timeout
/ 1000;
956 tv
.tv_usec
= (m_timeout
% 1000) * 1000;
961 FD_SET(m_fd
, &readfds
);
962 if (flags
& GSOCK_OUTPUT_FLAG
|| flags
& GSOCK_CONNECTION_FLAG
)
963 FD_SET(m_fd
, &writefds
);
964 FD_SET(m_fd
, &exceptfds
);
966 /* Check 'sticky' CONNECTION flag first */
967 result
|= (GSOCK_CONNECTION_FLAG
& m_detected
);
969 /* If we have already detected a LOST event, then don't try
970 * to do any further processing.
972 if ((m_detected
& GSOCK_LOST_FLAG
) != 0)
974 m_establishing
= false;
976 return (GSOCK_LOST_FLAG
& flags
);
980 if (select(m_fd
+ 1, &readfds
, &writefds
, &exceptfds
, &tv
) <= 0)
982 /* What to do here? */
983 return (result
& flags
);
986 /* Check for readability */
987 if (FD_ISSET(m_fd
, &readfds
))
991 int num
= recv(m_fd
, &c
, 1, MSG_PEEK
| GSOCKET_MSG_NOSIGNAL
);
995 result
|= GSOCK_INPUT_FLAG
;
999 if (m_server
&& m_stream
)
1001 result
|= GSOCK_CONNECTION_FLAG
;
1002 m_detected
|= GSOCK_CONNECTION_FLAG
;
1004 else if ((errno
!= EWOULDBLOCK
) && (errno
!= EAGAIN
) && (errno
!= EINTR
))
1006 m_detected
= GSOCK_LOST_FLAG
;
1007 m_establishing
= false;
1009 /* LOST event: Abort any further processing */
1010 return (GSOCK_LOST_FLAG
& flags
);
1015 /* Check for writability */
1016 if (FD_ISSET(m_fd
, &writefds
))
1018 if (m_establishing
&& !m_server
)
1021 SOCKOPTLEN_T len
= sizeof(error
);
1023 m_establishing
= false;
1025 getsockopt(m_fd
, SOL_SOCKET
, SO_ERROR
, (char*)&error
, &len
);
1029 m_detected
= GSOCK_LOST_FLAG
;
1031 /* LOST event: Abort any further processing */
1032 return (GSOCK_LOST_FLAG
& flags
);
1036 result
|= GSOCK_CONNECTION_FLAG
;
1037 m_detected
|= GSOCK_CONNECTION_FLAG
;
1042 result
|= GSOCK_OUTPUT_FLAG
;
1046 /* Check for exceptions and errors (is this useful in Unices?) */
1047 if (FD_ISSET(m_fd
, &exceptfds
))
1049 m_establishing
= false;
1050 m_detected
= GSOCK_LOST_FLAG
;
1052 /* LOST event: Abort any further processing */
1053 return (GSOCK_LOST_FLAG
& flags
);
1056 return (result
& flags
);
1063 return flags
& m_detected
;
1070 /* GSocket_SetNonBlocking:
1071 * Sets the socket to non-blocking mode. All IO calls will return
1074 void GSocket::SetNonBlocking(bool non_block
)
1078 GSocket_Debug( ("GSocket_SetNonBlocking: %d\n", (int)non_block
) );
1080 m_non_blocking
= non_block
;
1083 /* GSocket_SetTimeout:
1084 * Sets the timeout for blocking calls. Time is expressed in
1087 void GSocket::SetTimeout(unsigned long millisec
)
1091 m_timeout
= millisec
;
1094 /* GSocket_GetError:
1095 * Returns the last error occurred for this socket. Note that successful
1096 * operations do not clear this back to GSOCK_NOERROR, so use it only
1099 GSocketError WXDLLIMPEXP_NET
GSocket::GetError()
1109 * There is data to be read in the input buffer. If, after a read
1110 * operation, there is still data available, the callback function will
1113 * The socket is available for writing. That is, the next write call
1114 * won't block. This event is generated only once, when the connection is
1115 * first established, and then only if a call failed with GSOCK_WOULDBLOCK,
1116 * when the output buffer empties again. This means that the app should
1117 * assume that it can write since the first OUTPUT event, and no more
1118 * OUTPUT events will be generated unless an error occurs.
1120 * Connection successfully established, for client sockets, or incoming
1121 * client connection, for server sockets. Wait for this event (also watch
1122 * out for GSOCK_LOST) after you issue a nonblocking GSocket_Connect() call.
1124 * The connection is lost (or a connection request failed); this could
1125 * be due to a failure, or due to the peer closing it gracefully.
1128 /* GSocket_SetCallback:
1129 * Enables the callbacks specified by 'flags'. Note that 'flags'
1130 * may be a combination of flags OR'ed toghether, so the same
1131 * callback function can be made to accept different events.
1132 * The callback function must have the following prototype:
1134 * void function(GSocket *socket, GSocketEvent event, char *cdata)
1136 void GSocket::SetCallback(GSocketEventFlags flags
,
1137 GSocketCallback callback
, char *cdata
)
1143 for (count
= 0; count
< GSOCK_MAX_EVENT
; count
++)
1145 if ((flags
& (1 << count
)) != 0)
1147 m_cbacks
[count
] = callback
;
1148 m_data
[count
] = cdata
;
1153 /* GSocket_UnsetCallback:
1154 * Disables all callbacks specified by 'flags', which may be a
1155 * combination of flags OR'ed toghether.
1157 void GSocket::UnsetCallback(GSocketEventFlags flags
)
1163 for (count
= 0; count
< GSOCK_MAX_EVENT
; count
++)
1165 if ((flags
& (1 << count
)) != 0)
1167 m_cbacks
[count
] = NULL
;
1168 m_data
[count
] = NULL
;
1173 GSocketError
GSocket::GetSockOpt(int level
, int optname
,
1174 void *optval
, int *optlen
)
1176 if (getsockopt(m_fd
, level
, optname
, (char*)optval
, (SOCKOPTLEN_T
*)optlen
) == 0)
1178 return GSOCK_NOERROR
;
1180 return GSOCK_OPTERR
;
1183 GSocketError
GSocket::SetSockOpt(int level
, int optname
,
1184 const void *optval
, int optlen
)
1186 if (setsockopt(m_fd
, level
, optname
, (const char*)optval
, optlen
) == 0)
1188 return GSOCK_NOERROR
;
1190 return GSOCK_OPTERR
;
1193 #define CALL_CALLBACK(socket, event) { \
1194 socket->Disable(event); \
1195 if (socket->m_cbacks[event]) \
1196 socket->m_cbacks[event](socket, event, socket->m_data[event]); \
1200 void GSocket::Enable(GSocketEvent event
)
1202 m_detected
&= ~(1 << event
);
1203 gs_gui_functions
->Install_Callback(this, event
);
1206 void GSocket::Disable(GSocketEvent event
)
1208 m_detected
|= (1 << event
);
1209 gs_gui_functions
->Uninstall_Callback(this, event
);
1212 /* _GSocket_Input_Timeout:
1213 * For blocking sockets, wait until data is available or
1214 * until timeout ellapses.
1216 GSocketError
GSocket::Input_Timeout()
1222 /* Linux select() will overwrite the struct on return */
1223 tv
.tv_sec
= (m_timeout
/ 1000);
1224 tv
.tv_usec
= (m_timeout
% 1000) * 1000;
1226 if (!m_non_blocking
)
1229 FD_SET(m_fd
, &readfds
);
1230 ret
= select(m_fd
+ 1, &readfds
, NULL
, NULL
, &tv
);
1233 GSocket_Debug(( "GSocket_Input_Timeout, select returned 0\n" ));
1234 m_error
= GSOCK_TIMEDOUT
;
1235 return GSOCK_TIMEDOUT
;
1239 GSocket_Debug(( "GSocket_Input_Timeout, select returned -1\n" ));
1240 if (errno
== EBADF
) { GSocket_Debug(( "Invalid file descriptor\n" )); }
1241 if (errno
== EINTR
) { GSocket_Debug(( "A non blocked signal was caught\n" )); }
1242 if (errno
== EINVAL
) { GSocket_Debug(( "The highest number descriptor is negative\n" )); }
1243 if (errno
== ENOMEM
) { GSocket_Debug(( "Not enough memory\n" )); }
1244 m_error
= GSOCK_TIMEDOUT
;
1245 return GSOCK_TIMEDOUT
;
1248 return GSOCK_NOERROR
;
1251 /* _GSocket_Output_Timeout:
1252 * For blocking sockets, wait until data can be sent without
1253 * blocking or until timeout ellapses.
1255 GSocketError
GSocket::Output_Timeout()
1261 /* Linux select() will overwrite the struct on return */
1262 tv
.tv_sec
= (m_timeout
/ 1000);
1263 tv
.tv_usec
= (m_timeout
% 1000) * 1000;
1265 GSocket_Debug( ("m_non_blocking has: %d\n", (int)m_non_blocking
) );
1267 if (!m_non_blocking
)
1270 FD_SET(m_fd
, &writefds
);
1271 ret
= select(m_fd
+ 1, NULL
, &writefds
, NULL
, &tv
);
1274 GSocket_Debug(( "GSocket_Output_Timeout, select returned 0\n" ));
1275 m_error
= GSOCK_TIMEDOUT
;
1276 return GSOCK_TIMEDOUT
;
1280 GSocket_Debug(( "GSocket_Output_Timeout, select returned -1\n" ));
1281 if (errno
== EBADF
) { GSocket_Debug(( "Invalid file descriptor\n" )); }
1282 if (errno
== EINTR
) { GSocket_Debug(( "A non blocked signal was caught\n" )); }
1283 if (errno
== EINVAL
) { GSocket_Debug(( "The highest number descriptor is negative\n" )); }
1284 if (errno
== ENOMEM
) { GSocket_Debug(( "Not enough memory\n" )); }
1285 m_error
= GSOCK_TIMEDOUT
;
1286 return GSOCK_TIMEDOUT
;
1288 if ( ! FD_ISSET(m_fd
, &writefds
) ) {
1289 GSocket_Debug(( "GSocket_Output_Timeout is buggy!\n" ));
1292 GSocket_Debug(( "GSocket_Output_Timeout seems correct\n" ));
1297 GSocket_Debug(( "GSocket_Output_Timeout, didn't try select!\n" ));
1300 return GSOCK_NOERROR
;
1303 int GSocket::Recv_Stream(char *buffer
, int size
)
1308 ret
= recv(m_fd
, buffer
, size
, GSOCKET_MSG_NOSIGNAL
);
1309 } while (ret
== -1 && errno
== EINTR
); /* Loop until not interrupted */
1313 int GSocket::Recv_Dgram(char *buffer
, int size
)
1315 struct sockaddr from
;
1316 SOCKLEN_T fromlen
= sizeof(from
);
1320 fromlen
= sizeof(from
);
1324 ret
= recvfrom(m_fd
, buffer
, size
, 0, &from
, (SOCKLEN_T
*) &fromlen
);
1325 } while (ret
== -1 && errno
== EINTR
); /* Loop until not interrupted */
1330 /* Translate a system address into a GSocket address */
1333 m_peer
= GAddress_new();
1336 m_error
= GSOCK_MEMERR
;
1340 err
= _GAddress_translate_from(m_peer
, &from
, fromlen
);
1341 if (err
!= GSOCK_NOERROR
)
1343 GAddress_destroy(m_peer
);
1352 int GSocket::Send_Stream(const char *buffer
, int size
)
1356 #ifndef __VISAGECPP__
1361 ret
= send(m_fd
, (char *)buffer
, size
, GSOCKET_MSG_NOSIGNAL
);
1362 } while (ret
== -1 && errno
== EINTR
); /* Loop until not interrupted */
1363 #ifndef __VISAGECPP__
1370 int GSocket::Send_Dgram(const char *buffer
, int size
)
1372 struct sockaddr
*addr
;
1378 m_error
= GSOCK_INVADDR
;
1382 err
= _GAddress_translate_to(m_peer
, &addr
, &len
);
1383 if (err
!= GSOCK_NOERROR
)
1389 #ifndef __VISAGECPP__
1394 ret
= sendto(m_fd
, (char *)buffer
, size
, 0, addr
, len
);
1395 } while (ret
== -1 && errno
== EINTR
); /* Loop until not interrupted */
1396 #ifndef __VISAGECPP__
1400 /* Frees memory allocated from _GAddress_translate_to */
1406 void GSocket::Detected_Read()
1410 /* Safeguard against straggling call to Detected_Read */
1411 if (m_fd
== INVALID_SOCKET
)
1416 /* If we have already detected a LOST event, then don't try
1417 * to do any further processing.
1419 if ((m_detected
& GSOCK_LOST_FLAG
) != 0)
1421 m_establishing
= false;
1423 CALL_CALLBACK(this, GSOCK_LOST
);
1428 int num
= recv(m_fd
, &c
, 1, MSG_PEEK
| GSOCKET_MSG_NOSIGNAL
);
1432 CALL_CALLBACK(this, GSOCK_INPUT
);
1436 if (m_server
&& m_stream
)
1438 CALL_CALLBACK(this, GSOCK_CONNECTION
);
1442 /* Do not throw a lost event in cases where the socket isn't really lost */
1443 if ((errno
== EWOULDBLOCK
) || (errno
== EAGAIN
) || (errno
== EINTR
))
1445 CALL_CALLBACK(this, GSOCK_INPUT
);
1449 CALL_CALLBACK(this, GSOCK_LOST
);
1456 void GSocket::Detected_Write()
1458 /* If we have already detected a LOST event, then don't try
1459 * to do any further processing.
1461 if ((m_detected
& GSOCK_LOST_FLAG
) != 0)
1463 m_establishing
= false;
1465 CALL_CALLBACK(this, GSOCK_LOST
);
1470 if (m_establishing
&& !m_server
)
1473 SOCKOPTLEN_T len
= sizeof(error
);
1475 m_establishing
= false;
1477 getsockopt(m_fd
, SOL_SOCKET
, SO_ERROR
, (char*)&error
, &len
);
1481 CALL_CALLBACK(this, GSOCK_LOST
);
1486 CALL_CALLBACK(this, GSOCK_CONNECTION
);
1487 /* We have to fire this event by hand because CONNECTION (for clients)
1488 * and OUTPUT are internally the same and we just disabled CONNECTION
1489 * events with the above macro.
1491 CALL_CALLBACK(this, GSOCK_OUTPUT
);
1496 CALL_CALLBACK(this, GSOCK_OUTPUT
);
1500 /* Compatibility functions for GSocket */
1501 GSocket
*GSocket_new(void)
1503 GSocket
*newsocket
= new GSocket();
1504 if(newsocket
->IsOk())
1511 * -------------------------------------------------------------------------
1513 * -------------------------------------------------------------------------
1516 /* CHECK_ADDRESS verifies that the current address family is either
1517 * GSOCK_NOFAMILY or GSOCK_*family*, and if it is GSOCK_NOFAMILY, it
1518 * initalizes it to be a GSOCK_*family*. In other cases, it returns
1519 * an appropiate error code.
1521 * CHECK_ADDRESS_RETVAL does the same but returning 'retval' on error.
1523 #define CHECK_ADDRESS(address, family) \
1525 if (address->m_family == GSOCK_NOFAMILY) \
1526 if (_GAddress_Init_##family(address) != GSOCK_NOERROR) \
1527 return address->m_error; \
1528 if (address->m_family != GSOCK_##family) \
1530 address->m_error = GSOCK_INVADDR; \
1531 return GSOCK_INVADDR; \
1535 #define CHECK_ADDRESS_RETVAL(address, family, retval) \
1537 if (address->m_family == GSOCK_NOFAMILY) \
1538 if (_GAddress_Init_##family(address) != GSOCK_NOERROR) \
1540 if (address->m_family != GSOCK_##family) \
1542 address->m_error = GSOCK_INVADDR; \
1548 GAddress
*GAddress_new(void)
1552 if ((address
= (GAddress
*) malloc(sizeof(GAddress
))) == NULL
)
1555 address
->m_family
= GSOCK_NOFAMILY
;
1556 address
->m_addr
= NULL
;
1562 GAddress
*GAddress_copy(GAddress
*address
)
1566 assert(address
!= NULL
);
1568 if ((addr2
= (GAddress
*) malloc(sizeof(GAddress
))) == NULL
)
1571 memcpy(addr2
, address
, sizeof(GAddress
));
1573 if (address
->m_addr
&& address
->m_len
> 0)
1575 addr2
->m_addr
= (struct sockaddr
*)malloc(addr2
->m_len
);
1576 if (addr2
->m_addr
== NULL
)
1581 memcpy(addr2
->m_addr
, address
->m_addr
, addr2
->m_len
);
1587 void GAddress_destroy(GAddress
*address
)
1589 assert(address
!= NULL
);
1591 if (address
->m_addr
)
1592 free(address
->m_addr
);
1597 void GAddress_SetFamily(GAddress
*address
, GAddressType type
)
1599 assert(address
!= NULL
);
1601 address
->m_family
= type
;
1604 GAddressType
GAddress_GetFamily(GAddress
*address
)
1606 assert(address
!= NULL
);
1608 return address
->m_family
;
1611 GSocketError
_GAddress_translate_from(GAddress
*address
,
1612 struct sockaddr
*addr
, int len
)
1614 address
->m_realfamily
= addr
->sa_family
;
1615 switch (addr
->sa_family
)
1618 address
->m_family
= GSOCK_INET
;
1621 address
->m_family
= GSOCK_UNIX
;
1625 address
->m_family
= GSOCK_INET6
;
1630 address
->m_error
= GSOCK_INVOP
;
1635 if (address
->m_addr
)
1636 free(address
->m_addr
);
1638 address
->m_len
= len
;
1639 address
->m_addr
= (struct sockaddr
*)malloc(len
);
1641 if (address
->m_addr
== NULL
)
1643 address
->m_error
= GSOCK_MEMERR
;
1644 return GSOCK_MEMERR
;
1646 memcpy(address
->m_addr
, addr
, len
);
1648 return GSOCK_NOERROR
;
1651 GSocketError
_GAddress_translate_to(GAddress
*address
,
1652 struct sockaddr
**addr
, int *len
)
1654 if (!address
->m_addr
)
1656 address
->m_error
= GSOCK_INVADDR
;
1657 return GSOCK_INVADDR
;
1660 *len
= address
->m_len
;
1661 *addr
= (struct sockaddr
*)malloc(address
->m_len
);
1664 address
->m_error
= GSOCK_MEMERR
;
1665 return GSOCK_MEMERR
;
1668 memcpy(*addr
, address
->m_addr
, address
->m_len
);
1669 return GSOCK_NOERROR
;
1673 * -------------------------------------------------------------------------
1674 * Internet address family
1675 * -------------------------------------------------------------------------
1678 GSocketError
_GAddress_Init_INET(GAddress
*address
)
1680 address
->m_len
= sizeof(struct sockaddr_in
);
1681 address
->m_addr
= (struct sockaddr
*) malloc(address
->m_len
);
1682 if (address
->m_addr
== NULL
)
1684 address
->m_error
= GSOCK_MEMERR
;
1685 return GSOCK_MEMERR
;
1688 address
->m_family
= GSOCK_INET
;
1689 address
->m_realfamily
= PF_INET
;
1690 ((struct sockaddr_in
*)address
->m_addr
)->sin_family
= AF_INET
;
1691 ((struct sockaddr_in
*)address
->m_addr
)->sin_addr
.s_addr
= INADDR_ANY
;
1693 return GSOCK_NOERROR
;
1696 GSocketError
GAddress_INET_SetHostName(GAddress
*address
, const char *hostname
)
1699 struct in_addr
*addr
;
1701 assert(address
!= NULL
);
1703 CHECK_ADDRESS(address
, INET
);
1705 addr
= &(((struct sockaddr_in
*)address
->m_addr
)->sin_addr
);
1707 /* If it is a numeric host name, convert it now */
1708 #if defined(HAVE_INET_ATON)
1709 if (inet_aton(hostname
, addr
) == 0)
1711 #elif defined(HAVE_INET_ADDR)
1712 if ( (addr
->s_addr
= inet_addr(hostname
)) == (unsigned)-1 )
1715 /* Use gethostbyname by default */
1717 int val
= 1; /* VA doesn't like constants in conditional expressions */
1722 struct in_addr
*array_addr
;
1724 /* It is a real name, we solve it */
1725 if ((he
= gethostbyname(hostname
)) == NULL
)
1727 /* Reset to invalid address */
1728 addr
->s_addr
= INADDR_NONE
;
1729 address
->m_error
= GSOCK_NOHOST
;
1730 return GSOCK_NOHOST
;
1732 array_addr
= (struct in_addr
*) *(he
->h_addr_list
);
1733 addr
->s_addr
= array_addr
[0].s_addr
;
1735 return GSOCK_NOERROR
;
1738 GSocketError
GAddress_INET_SetAnyAddress(GAddress
*address
)
1740 return GAddress_INET_SetHostAddress(address
, INADDR_ANY
);
1743 GSocketError
GAddress_INET_SetHostAddress(GAddress
*address
,
1744 unsigned long hostaddr
)
1746 struct in_addr
*addr
;
1748 assert(address
!= NULL
);
1750 CHECK_ADDRESS(address
, INET
);
1752 addr
= &(((struct sockaddr_in
*)address
->m_addr
)->sin_addr
);
1753 addr
->s_addr
= htonl(hostaddr
);
1755 return GSOCK_NOERROR
;
1758 GSocketError
GAddress_INET_SetPortName(GAddress
*address
, const char *port
,
1759 const char *protocol
)
1762 struct sockaddr_in
*addr
;
1764 assert(address
!= NULL
);
1765 CHECK_ADDRESS(address
, INET
);
1769 address
->m_error
= GSOCK_INVPORT
;
1770 return GSOCK_INVPORT
;
1773 #if defined(__WXPM__) && defined(__EMX__)
1774 se
= getservbyname(port
, (char*)protocol
);
1776 se
= getservbyname(port
, protocol
);
1780 /* the cast to int suppresses compiler warnings about subscript having the
1782 if (isdigit((int)port
[0]))
1786 port_int
= atoi(port
);
1787 addr
= (struct sockaddr_in
*)address
->m_addr
;
1788 addr
->sin_port
= htons(port_int
);
1789 return GSOCK_NOERROR
;
1792 address
->m_error
= GSOCK_INVPORT
;
1793 return GSOCK_INVPORT
;
1796 addr
= (struct sockaddr_in
*)address
->m_addr
;
1797 addr
->sin_port
= se
->s_port
;
1799 return GSOCK_NOERROR
;
1802 GSocketError
GAddress_INET_SetPort(GAddress
*address
, unsigned short port
)
1804 struct sockaddr_in
*addr
;
1806 assert(address
!= NULL
);
1807 CHECK_ADDRESS(address
, INET
);
1809 addr
= (struct sockaddr_in
*)address
->m_addr
;
1810 addr
->sin_port
= htons(port
);
1812 return GSOCK_NOERROR
;
1815 GSocketError
GAddress_INET_GetHostName(GAddress
*address
, char *hostname
, size_t sbuf
)
1819 struct sockaddr_in
*addr
;
1821 assert(address
!= NULL
);
1822 CHECK_ADDRESS(address
, INET
);
1824 addr
= (struct sockaddr_in
*)address
->m_addr
;
1825 addr_buf
= (char *)&(addr
->sin_addr
);
1827 he
= gethostbyaddr(addr_buf
, sizeof(addr
->sin_addr
), AF_INET
);
1830 address
->m_error
= GSOCK_NOHOST
;
1831 return GSOCK_NOHOST
;
1834 strncpy(hostname
, he
->h_name
, sbuf
);
1836 return GSOCK_NOERROR
;
1839 unsigned long GAddress_INET_GetHostAddress(GAddress
*address
)
1841 struct sockaddr_in
*addr
;
1843 assert(address
!= NULL
);
1844 CHECK_ADDRESS_RETVAL(address
, INET
, 0);
1846 addr
= (struct sockaddr_in
*)address
->m_addr
;
1848 return ntohl(addr
->sin_addr
.s_addr
);
1851 unsigned short GAddress_INET_GetPort(GAddress
*address
)
1853 struct sockaddr_in
*addr
;
1855 assert(address
!= NULL
);
1856 CHECK_ADDRESS_RETVAL(address
, INET
, 0);
1858 addr
= (struct sockaddr_in
*)address
->m_addr
;
1859 return ntohs(addr
->sin_port
);
1863 * -------------------------------------------------------------------------
1864 * Unix address family
1865 * -------------------------------------------------------------------------
1868 #ifndef __VISAGECPP__
1869 GSocketError
_GAddress_Init_UNIX(GAddress
*address
)
1871 address
->m_len
= sizeof(struct sockaddr_un
);
1872 address
->m_addr
= (struct sockaddr
*)malloc(address
->m_len
);
1873 if (address
->m_addr
== NULL
)
1875 address
->m_error
= GSOCK_MEMERR
;
1876 return GSOCK_MEMERR
;
1879 address
->m_family
= GSOCK_UNIX
;
1880 address
->m_realfamily
= PF_UNIX
;
1881 ((struct sockaddr_un
*)address
->m_addr
)->sun_family
= AF_UNIX
;
1882 ((struct sockaddr_un
*)address
->m_addr
)->sun_path
[0] = 0;
1884 return GSOCK_NOERROR
;
1887 #define UNIX_SOCK_PATHLEN (sizeof(addr->sun_path)/sizeof(addr->sun_path[0]))
1889 GSocketError
GAddress_UNIX_SetPath(GAddress
*address
, const char *path
)
1891 struct sockaddr_un
*addr
;
1893 assert(address
!= NULL
);
1895 CHECK_ADDRESS(address
, UNIX
);
1897 addr
= ((struct sockaddr_un
*)address
->m_addr
);
1898 strncpy(addr
->sun_path
, path
, UNIX_SOCK_PATHLEN
);
1899 addr
->sun_path
[UNIX_SOCK_PATHLEN
- 1] = '\0';
1901 return GSOCK_NOERROR
;
1904 GSocketError
GAddress_UNIX_GetPath(GAddress
*address
, char *path
, size_t sbuf
)
1906 struct sockaddr_un
*addr
;
1908 assert(address
!= NULL
);
1909 CHECK_ADDRESS(address
, UNIX
);
1911 addr
= (struct sockaddr_un
*)address
->m_addr
;
1913 strncpy(path
, addr
->sun_path
, sbuf
);
1915 return GSOCK_NOERROR
;
1917 #endif /* !defined(__VISAGECPP__) */
1918 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */