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 #if defined(__WATCOMC__)
20 #include "wx/wxprec.h"
25 #ifndef __GSOCKET_STANDALONE__
29 #if defined(__VISAGECPP__)
30 #define BSD_SELECT /* use Berkley Sockets select */
33 #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
36 #include <sys/types.h>
41 #include <netinet/in.h>
44 #include <sys/ioctl.h>
50 u_char sun_len
; /* sockaddr len including null */
51 u_char sun_family
; /* AF_UNIX */
52 char sun_path
[108]; /* path name (gag) */
55 #include <sys/socket.h>
61 #include <netinet/in.h>
62 #include <arpa/inet.h>
69 #include <machine/endian.h>
75 #define EBADF SOCEBADF
81 #include <sys/socket.h>
82 #include <sys/ioctl.h>
83 #include <sys/select.h>
85 #define close(a) soclose(a)
86 #define select(a,b,c,d,e) bsdselect(a,b,c,d,e)
87 int _System
bsdselect(int,
92 int _System
soclose(int);
96 #include <sys/select.h>
104 # include <sys/filio.h>
107 # include <bstring.h>
110 # include <strings.h>
117 # define WX_SOCKLEN_T unsigned int
121 # define WX_SOCKLEN_T socklen_t
123 # elif defined(__WXMAC__)
124 # define WX_SOCKLEN_T socklen_t
126 # define WX_SOCKLEN_T int
130 #endif /* SOCKLEN_T */
133 #define SOCKOPTLEN_T WX_SOCKLEN_T
137 * MSW defines this, Unices don't.
139 #ifndef INVALID_SOCKET
140 #define INVALID_SOCKET -1
143 /* UnixWare reportedly needs this for FIONBIO definition */
145 #include <sys/filio.h>
149 * INADDR_BROADCAST is identical to INADDR_NONE which is not defined
150 * on all systems. INADDR_BROADCAST should be fine to indicate an error.
153 #define INADDR_NONE INADDR_BROADCAST
156 #if defined(__VISAGECPP__) || defined(__WATCOMC__)
158 #define MASK_SIGNAL() {
159 #define UNMASK_SIGNAL() }
162 extern "C" { typedef void (*wxSigHandler
)(int); }
164 #define MASK_SIGNAL() \
166 wxSigHandler old_handler = signal(SIGPIPE, SIG_IGN);
168 #define UNMASK_SIGNAL() \
169 signal(SIGPIPE, old_handler); \
174 /* If a SIGPIPE is issued by a socket call on a remotely closed socket,
175 the program will "crash" unless it explicitly handles the SIGPIPE.
176 By using MSG_NOSIGNAL, the SIGPIPE is suppressed. Later, we will
177 use SO_NOSIGPIPE (if available), the BSD equivalent. */
179 # define GSOCKET_MSG_NOSIGNAL MSG_NOSIGNAL
180 #else /* MSG_NOSIGNAL not available (FreeBSD including OS X) */
181 # define GSOCKET_MSG_NOSIGNAL 0
182 #endif /* MSG_NOSIGNAL */
184 #ifndef __GSOCKET_STANDALONE__
185 # include "wx/unix/gsockunx.h"
186 # include "wx/gsocket.h"
188 # include "gsockunx.h"
189 # include "gsocket.h"
193 #endif /* __GSOCKET_STANDALONE__ */
195 /* debugging helpers */
196 #ifdef __GSOCKET_DEBUG__
197 # define GSocket_Debug(args) printf args
199 # define GSocket_Debug(args)
200 #endif /* __GSOCKET_DEBUG__ */
202 /* Table of GUI-related functions. We must call them indirectly because
203 * of wxBase and GUI separation: */
205 static GSocketGUIFunctionsTable
*gs_gui_functions
;
207 class GSocketGUIFunctionsTableNull
: public GSocketGUIFunctionsTable
210 virtual bool OnInit();
211 virtual void OnExit();
212 virtual bool CanUseEventLoop();
213 virtual bool Init_Socket(GSocket
*socket
);
214 virtual void Destroy_Socket(GSocket
*socket
);
215 virtual void Install_Callback(GSocket
*socket
, GSocketEvent event
);
216 virtual void Uninstall_Callback(GSocket
*socket
, GSocketEvent event
);
217 virtual void Enable_Events(GSocket
*socket
);
218 virtual void Disable_Events(GSocket
*socket
);
221 bool GSocketGUIFunctionsTableNull::OnInit()
223 void GSocketGUIFunctionsTableNull::OnExit()
225 bool GSocketGUIFunctionsTableNull::CanUseEventLoop()
227 bool GSocketGUIFunctionsTableNull::Init_Socket(GSocket
*WXUNUSED(socket
))
229 void GSocketGUIFunctionsTableNull::Destroy_Socket(GSocket
*WXUNUSED(socket
))
231 void GSocketGUIFunctionsTableNull::Install_Callback(GSocket
*WXUNUSED(socket
), GSocketEvent
WXUNUSED(event
))
233 void GSocketGUIFunctionsTableNull::Uninstall_Callback(GSocket
*WXUNUSED(socket
), GSocketEvent
WXUNUSED(event
))
235 void GSocketGUIFunctionsTableNull::Enable_Events(GSocket
*WXUNUSED(socket
))
237 void GSocketGUIFunctionsTableNull::Disable_Events(GSocket
*WXUNUSED(socket
))
239 /* Global initialisers */
241 void GSocket_SetGUIFunctions(GSocketGUIFunctionsTable
*guifunc
)
243 gs_gui_functions
= guifunc
;
246 int GSocket_Init(void)
248 if (!gs_gui_functions
)
250 static GSocketGUIFunctionsTableNull table
;
251 gs_gui_functions
= &table
;
253 if ( !gs_gui_functions
->OnInit() )
258 void GSocket_Cleanup(void)
260 if (gs_gui_functions
)
262 gs_gui_functions
->OnExit();
266 /* Constructors / Destructors for GSocket */
272 m_fd
= INVALID_SOCKET
;
273 for (i
=0;i
<GSOCK_MAX_EVENT
;i
++)
280 m_error
= GSOCK_NOERROR
;
283 m_gui_dependent
= NULL
;
284 m_non_blocking
= false;
286 m_timeout
= 10*60*1000;
287 /* 10 minutes * 60 sec * 1000 millisec */
288 m_establishing
= false;
290 assert(gs_gui_functions
);
291 /* Per-socket GUI-specific initialization */
292 m_ok
= gs_gui_functions
->Init_Socket(this);
295 void GSocket::Close()
297 gs_gui_functions
->Disable_Events(this);
298 /* gsockosx.c calls CFSocketInvalidate which closes the socket for us */
299 #if !(defined(__DARWIN__) && (defined(__WXMAC__) || defined(__WXCOCOA__)))
302 m_fd
= INVALID_SOCKET
;
309 /* Check that the socket is really shutdowned */
310 if (m_fd
!= INVALID_SOCKET
)
313 /* Per-socket GUI-specific cleanup */
314 gs_gui_functions
->Destroy_Socket(this);
316 /* Destroy private addresses */
318 GAddress_destroy(m_local
);
321 GAddress_destroy(m_peer
);
325 * Disallow further read/write operations on this socket, close
326 * the fd and disable all callbacks.
328 void GSocket::Shutdown()
334 /* If socket has been created, shutdown it */
335 if (m_fd
!= INVALID_SOCKET
)
341 /* Disable GUI callbacks */
342 for (evt
= 0; evt
< GSOCK_MAX_EVENT
; evt
++)
343 m_cbacks
[evt
] = NULL
;
345 m_detected
= GSOCK_LOST_FLAG
;
348 /* Address handling */
354 * Set or get the local or peer address for this socket. The 'set'
355 * functions return GSOCK_NOERROR on success, an error code otherwise.
356 * The 'get' functions return a pointer to a GAddress object on success,
357 * or NULL otherwise, in which case they set the error code of the
358 * corresponding GSocket.
361 * GSOCK_INVSOCK - the socket is not valid.
362 * GSOCK_INVADDR - the address is not valid.
364 GSocketError
GSocket::SetLocal(GAddress
*address
)
368 /* the socket must be initialized, or it must be a server */
369 if ((m_fd
!= INVALID_SOCKET
&& !m_server
))
371 m_error
= GSOCK_INVSOCK
;
372 return GSOCK_INVSOCK
;
376 if (address
== NULL
|| address
->m_family
== GSOCK_NOFAMILY
)
378 m_error
= GSOCK_INVADDR
;
379 return GSOCK_INVADDR
;
383 GAddress_destroy(m_local
);
385 m_local
= GAddress_copy(address
);
387 return GSOCK_NOERROR
;
390 GSocketError
GSocket::SetPeer(GAddress
*address
)
395 if (address
== NULL
|| address
->m_family
== GSOCK_NOFAMILY
)
397 m_error
= GSOCK_INVADDR
;
398 return GSOCK_INVADDR
;
402 GAddress_destroy(m_peer
);
404 m_peer
= GAddress_copy(address
);
406 return GSOCK_NOERROR
;
409 GAddress
*GSocket::GetLocal()
412 struct sockaddr addr
;
413 WX_SOCKLEN_T size
= sizeof(addr
);
418 /* try to get it from the m_local var first */
420 return GAddress_copy(m_local
);
422 /* else, if the socket is initialized, try getsockname */
423 if (m_fd
== INVALID_SOCKET
)
425 m_error
= GSOCK_INVSOCK
;
429 if (getsockname(m_fd
, &addr
, (WX_SOCKLEN_T
*) &size
) < 0)
431 m_error
= GSOCK_IOERR
;
435 /* got a valid address from getsockname, create a GAddress object */
436 address
= GAddress_new();
439 m_error
= GSOCK_MEMERR
;
443 err
= _GAddress_translate_from(address
, &addr
, size
);
444 if (err
!= GSOCK_NOERROR
)
446 GAddress_destroy(address
);
454 GAddress
*GSocket::GetPeer()
458 /* try to get it from the m_peer var */
460 return GAddress_copy(m_peer
);
465 /* Server specific parts */
467 /* GSocket_SetServer:
468 * Sets up this socket as a server. The local address must have been
469 * set with GSocket_SetLocal() before GSocket_SetServer() is called.
470 * Returns GSOCK_NOERROR on success, one of the following otherwise:
473 * GSOCK_INVSOCK - the socket is in use.
474 * GSOCK_INVADDR - the local address has not been set.
475 * GSOCK_IOERR - low-level error.
477 GSocketError
GSocket::SetServer()
483 /* must not be in use */
484 if (m_fd
!= INVALID_SOCKET
)
486 m_error
= GSOCK_INVSOCK
;
487 return GSOCK_INVSOCK
;
490 /* the local addr must have been set */
493 m_error
= GSOCK_INVADDR
;
494 return GSOCK_INVADDR
;
497 /* Initialize all fields */
501 /* Create the socket */
502 m_fd
= socket(m_local
->m_realfamily
, SOCK_STREAM
, 0);
504 if (m_fd
== INVALID_SOCKET
)
506 m_error
= GSOCK_IOERR
;
510 /* FreeBSD variants can't use MSG_NOSIGNAL, and instead use a socket option */
512 setsockopt(m_fd
, SOL_SOCKET
, SO_NOSIGPIPE
, (const char*)&arg
, sizeof(u_long
));
515 ioctl(m_fd
, FIONBIO
, &arg
);
516 gs_gui_functions
->Enable_Events(this);
518 /* allow a socket to re-bind if the socket is in the TIME_WAIT
519 state after being previously closed.
522 setsockopt(m_fd
, SOL_SOCKET
, SO_REUSEADDR
, (const char*)&arg
, sizeof(u_long
));
524 /* Bind to the local address,
525 * retrieve the actual address bound,
526 * and listen up to 5 connections.
528 if ((bind(m_fd
, m_local
->m_addr
, m_local
->m_len
) != 0) ||
531 (WX_SOCKLEN_T
*) &m_local
->m_len
) != 0) ||
532 (listen(m_fd
, 5) != 0))
535 m_error
= GSOCK_IOERR
;
539 return GSOCK_NOERROR
;
542 /* GSocket_WaitConnection:
543 * Waits for an incoming client connection. Returns a pointer to
544 * a GSocket object, or NULL if there was an error, in which case
545 * the last error field will be updated for the calling GSocket.
547 * Error codes (set in the calling GSocket)
548 * GSOCK_INVSOCK - the socket is not valid or not a server.
549 * GSOCK_TIMEDOUT - timeout, no incoming connections.
550 * GSOCK_WOULDBLOCK - the call would block and the socket is nonblocking.
551 * GSOCK_MEMERR - couldn't allocate memory.
552 * GSOCK_IOERR - low-level error.
554 GSocket
*GSocket::WaitConnection()
556 struct sockaddr from
;
557 WX_SOCKLEN_T fromlen
= sizeof(from
);
564 /* If the socket has already been created, we exit immediately */
565 if (m_fd
== INVALID_SOCKET
|| !m_server
)
567 m_error
= GSOCK_INVSOCK
;
571 /* Create a GSocket object for the new connection */
572 connection
= GSocket_new();
576 m_error
= GSOCK_MEMERR
;
580 /* Wait for a connection (with timeout) */
581 if (Input_Timeout() == GSOCK_TIMEDOUT
)
584 /* m_error set by _GSocket_Input_Timeout */
588 connection
->m_fd
= accept(m_fd
, &from
, (WX_SOCKLEN_T
*) &fromlen
);
590 /* Reenable CONNECTION events */
591 Enable(GSOCK_CONNECTION
);
593 if (connection
->m_fd
== INVALID_SOCKET
)
595 if (errno
== EWOULDBLOCK
)
596 m_error
= GSOCK_WOULDBLOCK
;
598 m_error
= GSOCK_IOERR
;
604 /* Initialize all fields */
605 connection
->m_server
= false;
606 connection
->m_stream
= true;
608 /* Setup the peer address field */
609 connection
->m_peer
= GAddress_new();
610 if (!connection
->m_peer
)
613 m_error
= GSOCK_MEMERR
;
616 err
= _GAddress_translate_from(connection
->m_peer
, &from
, fromlen
);
617 if (err
!= GSOCK_NOERROR
)
623 #if defined(__EMX__) || defined(__VISAGECPP__)
624 ioctl(connection
->m_fd
, FIONBIO
, (char*)&arg
, sizeof(arg
));
626 ioctl(connection
->m_fd
, FIONBIO
, &arg
);
628 gs_gui_functions
->Enable_Events(connection
);
633 bool GSocket::SetReusable()
635 /* socket must not be null, and must not be in use/already bound */
636 if (this && m_fd
== INVALID_SOCKET
) {
643 /* Client specific parts */
646 * For stream (connection oriented) sockets, GSocket_Connect() tries
647 * to establish a client connection to a server using the peer address
648 * as established with GSocket_SetPeer(). Returns GSOCK_NOERROR if the
649 * connection has been successfully established, or one of the error
650 * codes listed below. Note that for nonblocking sockets, a return
651 * value of GSOCK_WOULDBLOCK doesn't mean a failure. The connection
652 * request can be completed later; you should use GSocket_Select()
653 * to poll for GSOCK_CONNECTION | GSOCK_LOST, or wait for the
654 * corresponding asynchronous events.
656 * For datagram (non connection oriented) sockets, GSocket_Connect()
657 * just sets the peer address established with GSocket_SetPeer() as
658 * default destination.
661 * GSOCK_INVSOCK - the socket is in use or not valid.
662 * GSOCK_INVADDR - the peer address has not been established.
663 * GSOCK_TIMEDOUT - timeout, the connection failed.
664 * GSOCK_WOULDBLOCK - connection in progress (nonblocking sockets only)
665 * GSOCK_MEMERR - couldn't allocate memory.
666 * GSOCK_IOERR - low-level error.
668 GSocketError
GSocket::Connect(GSocketStream stream
)
675 /* Enable CONNECTION events (needed for nonblocking connections) */
676 Enable(GSOCK_CONNECTION
);
678 if (m_fd
!= INVALID_SOCKET
)
680 m_error
= GSOCK_INVSOCK
;
681 return GSOCK_INVSOCK
;
686 m_error
= GSOCK_INVADDR
;
687 return GSOCK_INVADDR
;
690 /* Streamed or dgram socket? */
691 m_stream
= (stream
== GSOCK_STREAMED
);
693 m_establishing
= false;
695 /* Create the socket */
696 m_fd
= socket(m_peer
->m_realfamily
,
697 m_stream
? SOCK_STREAM
: SOCK_DGRAM
, 0);
699 if (m_fd
== INVALID_SOCKET
)
701 m_error
= GSOCK_IOERR
;
705 /* FreeBSD variants can't use MSG_NOSIGNAL, and instead use a socket option */
707 setsockopt(m_fd
, SOL_SOCKET
, SO_NOSIGPIPE
, (const char*)&arg
, sizeof(u_long
));
710 #if defined(__EMX__) || defined(__VISAGECPP__)
711 ioctl(m_fd
, FIONBIO
, (char*)&arg
, sizeof(arg
));
713 ioctl(m_fd
, FIONBIO
, &arg
);
716 /* Connect it to the peer address, with a timeout (see below) */
717 ret
= connect(m_fd
, m_peer
->m_addr
, m_peer
->m_len
);
719 /* We only call Enable_Events if we know e aren't shutting down the socket */
723 gs_gui_functions
->Enable_Events(this);
730 /* If connect failed with EINPROGRESS and the GSocket object
731 * is in blocking mode, we select() for the specified timeout
732 * checking for writability to see if the connection request
735 if ((err
== EINPROGRESS
) && (!m_non_blocking
))
737 if (Output_Timeout() == GSOCK_TIMEDOUT
)
740 /* m_error is set in _GSocket_Output_Timeout */
741 return GSOCK_TIMEDOUT
;
746 SOCKOPTLEN_T len
= sizeof(error
);
748 getsockopt(m_fd
, SOL_SOCKET
, SO_ERROR
, (char*) &error
, &len
);
750 gs_gui_functions
->Enable_Events(this);
753 return GSOCK_NOERROR
;
757 /* If connect failed with EINPROGRESS and the GSocket object
758 * is set to nonblocking, we set m_error to GSOCK_WOULDBLOCK
759 * (and return GSOCK_WOULDBLOCK) but we don't close the socket;
760 * this way if the connection completes, a GSOCK_CONNECTION
761 * event will be generated, if enabled.
763 if ((err
== EINPROGRESS
) && (m_non_blocking
))
765 m_establishing
= true;
766 m_error
= GSOCK_WOULDBLOCK
;
767 return GSOCK_WOULDBLOCK
;
770 /* If connect failed with an error other than EINPROGRESS,
771 * then the call to GSocket_Connect has failed.
774 m_error
= GSOCK_IOERR
;
778 return GSOCK_NOERROR
;
781 /* Datagram sockets */
783 /* GSocket_SetNonOriented:
784 * Sets up this socket as a non-connection oriented (datagram) socket.
785 * Before using this function, the local address must have been set
786 * with GSocket_SetLocal(), or the call will fail. Returns GSOCK_NOERROR
787 * on success, or one of the following otherwise.
790 * GSOCK_INVSOCK - the socket is in use.
791 * GSOCK_INVADDR - the local address has not been set.
792 * GSOCK_IOERR - low-level error.
794 GSocketError
GSocket::SetNonOriented()
800 if (m_fd
!= INVALID_SOCKET
)
802 m_error
= GSOCK_INVSOCK
;
803 return GSOCK_INVSOCK
;
808 m_error
= GSOCK_INVADDR
;
809 return GSOCK_INVADDR
;
812 /* Initialize all fields */
816 /* Create the socket */
817 m_fd
= socket(m_local
->m_realfamily
, SOCK_DGRAM
, 0);
819 if (m_fd
== INVALID_SOCKET
)
821 m_error
= GSOCK_IOERR
;
824 #if defined(__EMX__) || defined(__VISAGECPP__)
825 ioctl(m_fd
, FIONBIO
, (char*)&arg
, sizeof(arg
));
827 ioctl(m_fd
, FIONBIO
, &arg
);
829 gs_gui_functions
->Enable_Events(this);
831 /* Bind to the local address,
832 * and retrieve the actual address bound.
834 if ((bind(m_fd
, m_local
->m_addr
, m_local
->m_len
) != 0) ||
837 (WX_SOCKLEN_T
*) &m_local
->m_len
) != 0))
840 m_error
= GSOCK_IOERR
;
844 return GSOCK_NOERROR
;
849 /* Like recv(), send(), ... */
850 int GSocket::Read(char *buffer
, int size
)
856 if (m_fd
== INVALID_SOCKET
|| m_server
)
858 m_error
= GSOCK_INVSOCK
;
862 /* Disable events during query of socket status */
863 Disable(GSOCK_INPUT
);
865 /* If the socket is blocking, wait for data (with a timeout) */
866 if (Input_Timeout() == GSOCK_TIMEDOUT
)
867 /* We no longer return here immediately, otherwise socket events would not be re-enabled! */
872 ret
= Recv_Stream(buffer
, size
);
874 ret
= Recv_Dgram(buffer
, size
);
879 if ((errno
== EWOULDBLOCK
) || (errno
== EAGAIN
))
880 m_error
= GSOCK_WOULDBLOCK
;
882 m_error
= GSOCK_IOERR
;
885 /* Enable events again now that we are done processing */
891 int GSocket::Write(const char *buffer
, int size
)
897 GSocket_Debug(( "GSocket_Write #1, size %d\n", size
));
899 if (m_fd
== INVALID_SOCKET
|| m_server
)
901 m_error
= GSOCK_INVSOCK
;
905 GSocket_Debug(( "GSocket_Write #2, size %d\n", size
));
907 /* If the socket is blocking, wait for writability (with a timeout) */
908 if (Output_Timeout() == GSOCK_TIMEDOUT
)
911 GSocket_Debug(( "GSocket_Write #3, size %d\n", size
));
915 ret
= Send_Stream(buffer
, size
);
917 ret
= Send_Dgram(buffer
, size
);
919 GSocket_Debug(( "GSocket_Write #4, size %d\n", size
));
923 if ((errno
== EWOULDBLOCK
) || (errno
== EAGAIN
))
925 m_error
= GSOCK_WOULDBLOCK
;
926 GSocket_Debug(( "GSocket_Write error WOULDBLOCK\n" ));
930 m_error
= GSOCK_IOERR
;
931 GSocket_Debug(( "GSocket_Write error IOERR\n" ));
934 /* Only reenable OUTPUT events after an error (just like WSAAsyncSelect
935 * in MSW). Once the first OUTPUT event is received, users can assume
936 * that the socket is writable until a read operation fails. Only then
937 * will further OUTPUT events be posted.
939 Enable(GSOCK_OUTPUT
);
943 GSocket_Debug(( "GSocket_Write #5, size %d ret %d\n", size
, ret
));
949 * Polls the socket to determine its status. This function will
950 * check for the events specified in the 'flags' parameter, and
951 * it will return a mask indicating which operations can be
952 * performed. This function won't block, regardless of the
953 * mode (blocking | nonblocking) of the socket.
955 GSocketEventFlags
GSocket::Select(GSocketEventFlags flags
)
957 if (!gs_gui_functions
->CanUseEventLoop())
960 GSocketEventFlags result
= 0;
969 return (GSOCK_LOST_FLAG
& flags
);
971 /* Do not use a static struct, Linux can garble it */
972 tv
.tv_sec
= m_timeout
/ 1000;
973 tv
.tv_usec
= (m_timeout
% 1000) * 1000;
978 FD_SET(m_fd
, &readfds
);
979 if (flags
& GSOCK_OUTPUT_FLAG
|| flags
& GSOCK_CONNECTION_FLAG
)
980 FD_SET(m_fd
, &writefds
);
981 FD_SET(m_fd
, &exceptfds
);
983 /* Check 'sticky' CONNECTION flag first */
984 result
|= (GSOCK_CONNECTION_FLAG
& m_detected
);
986 /* If we have already detected a LOST event, then don't try
987 * to do any further processing.
989 if ((m_detected
& GSOCK_LOST_FLAG
) != 0)
991 m_establishing
= false;
993 return (GSOCK_LOST_FLAG
& flags
);
997 if (select(m_fd
+ 1, &readfds
, &writefds
, &exceptfds
, &tv
) <= 0)
999 /* What to do here? */
1000 return (result
& flags
);
1003 /* Check for readability */
1004 if (FD_ISSET(m_fd
, &readfds
))
1008 int num
= recv(m_fd
, &c
, 1, MSG_PEEK
| GSOCKET_MSG_NOSIGNAL
);
1012 result
|= GSOCK_INPUT_FLAG
;
1016 if (m_server
&& m_stream
)
1018 result
|= GSOCK_CONNECTION_FLAG
;
1019 m_detected
|= GSOCK_CONNECTION_FLAG
;
1021 else if ((errno
!= EWOULDBLOCK
) && (errno
!= EAGAIN
) && (errno
!= EINTR
))
1023 m_detected
= GSOCK_LOST_FLAG
;
1024 m_establishing
= false;
1026 /* LOST event: Abort any further processing */
1027 return (GSOCK_LOST_FLAG
& flags
);
1032 /* Check for writability */
1033 if (FD_ISSET(m_fd
, &writefds
))
1035 if (m_establishing
&& !m_server
)
1038 SOCKOPTLEN_T len
= sizeof(error
);
1040 m_establishing
= false;
1042 getsockopt(m_fd
, SOL_SOCKET
, SO_ERROR
, (char*)&error
, &len
);
1046 m_detected
= GSOCK_LOST_FLAG
;
1048 /* LOST event: Abort any further processing */
1049 return (GSOCK_LOST_FLAG
& flags
);
1053 result
|= GSOCK_CONNECTION_FLAG
;
1054 m_detected
|= GSOCK_CONNECTION_FLAG
;
1059 result
|= GSOCK_OUTPUT_FLAG
;
1063 /* Check for exceptions and errors (is this useful in Unices?) */
1064 if (FD_ISSET(m_fd
, &exceptfds
))
1066 m_establishing
= false;
1067 m_detected
= GSOCK_LOST_FLAG
;
1069 /* LOST event: Abort any further processing */
1070 return (GSOCK_LOST_FLAG
& flags
);
1073 return (result
& flags
);
1080 return flags
& m_detected
;
1087 /* GSocket_SetNonBlocking:
1088 * Sets the socket to non-blocking mode. All IO calls will return
1091 void GSocket::SetNonBlocking(bool non_block
)
1095 GSocket_Debug( ("GSocket_SetNonBlocking: %d\n", (int)non_block
) );
1097 m_non_blocking
= non_block
;
1100 /* GSocket_SetTimeout:
1101 * Sets the timeout for blocking calls. Time is expressed in
1104 void GSocket::SetTimeout(unsigned long millisec
)
1108 m_timeout
= millisec
;
1111 /* GSocket_GetError:
1112 * Returns the last error occurred for this socket. Note that successful
1113 * operations do not clear this back to GSOCK_NOERROR, so use it only
1116 GSocketError WXDLLIMPEXP_NET
GSocket::GetError()
1126 * There is data to be read in the input buffer. If, after a read
1127 * operation, there is still data available, the callback function will
1130 * The socket is available for writing. That is, the next write call
1131 * won't block. This event is generated only once, when the connection is
1132 * first established, and then only if a call failed with GSOCK_WOULDBLOCK,
1133 * when the output buffer empties again. This means that the app should
1134 * assume that it can write since the first OUTPUT event, and no more
1135 * OUTPUT events will be generated unless an error occurs.
1137 * Connection successfully established, for client sockets, or incoming
1138 * client connection, for server sockets. Wait for this event (also watch
1139 * out for GSOCK_LOST) after you issue a nonblocking GSocket_Connect() call.
1141 * The connection is lost (or a connection request failed); this could
1142 * be due to a failure, or due to the peer closing it gracefully.
1145 /* GSocket_SetCallback:
1146 * Enables the callbacks specified by 'flags'. Note that 'flags'
1147 * may be a combination of flags OR'ed toghether, so the same
1148 * callback function can be made to accept different events.
1149 * The callback function must have the following prototype:
1151 * void function(GSocket *socket, GSocketEvent event, char *cdata)
1153 void GSocket::SetCallback(GSocketEventFlags flags
,
1154 GSocketCallback callback
, char *cdata
)
1160 for (count
= 0; count
< GSOCK_MAX_EVENT
; count
++)
1162 if ((flags
& (1 << count
)) != 0)
1164 m_cbacks
[count
] = callback
;
1165 m_data
[count
] = cdata
;
1170 /* GSocket_UnsetCallback:
1171 * Disables all callbacks specified by 'flags', which may be a
1172 * combination of flags OR'ed toghether.
1174 void GSocket::UnsetCallback(GSocketEventFlags flags
)
1180 for (count
= 0; count
< GSOCK_MAX_EVENT
; count
++)
1182 if ((flags
& (1 << count
)) != 0)
1184 m_cbacks
[count
] = NULL
;
1185 m_data
[count
] = NULL
;
1190 GSocketError
GSocket::GetSockOpt(int level
, int optname
,
1191 void *optval
, int *optlen
)
1193 if (getsockopt(m_fd
, level
, optname
, (char*)optval
, (SOCKOPTLEN_T
*)optlen
) == 0)
1195 return GSOCK_NOERROR
;
1197 return GSOCK_OPTERR
;
1200 GSocketError
GSocket::SetSockOpt(int level
, int optname
,
1201 const void *optval
, int optlen
)
1203 if (setsockopt(m_fd
, level
, optname
, (const char*)optval
, optlen
) == 0)
1205 return GSOCK_NOERROR
;
1207 return GSOCK_OPTERR
;
1210 #define CALL_CALLBACK(socket, event) { \
1211 socket->Disable(event); \
1212 if (socket->m_cbacks[event]) \
1213 socket->m_cbacks[event](socket, event, socket->m_data[event]); \
1217 void GSocket::Enable(GSocketEvent event
)
1219 m_detected
&= ~(1 << event
);
1220 gs_gui_functions
->Install_Callback(this, event
);
1223 void GSocket::Disable(GSocketEvent event
)
1225 m_detected
|= (1 << event
);
1226 gs_gui_functions
->Uninstall_Callback(this, event
);
1229 /* _GSocket_Input_Timeout:
1230 * For blocking sockets, wait until data is available or
1231 * until timeout ellapses.
1233 GSocketError
GSocket::Input_Timeout()
1239 /* Linux select() will overwrite the struct on return */
1240 tv
.tv_sec
= (m_timeout
/ 1000);
1241 tv
.tv_usec
= (m_timeout
% 1000) * 1000;
1243 if (!m_non_blocking
)
1246 FD_SET(m_fd
, &readfds
);
1247 ret
= select(m_fd
+ 1, &readfds
, NULL
, NULL
, &tv
);
1250 GSocket_Debug(( "GSocket_Input_Timeout, select returned 0\n" ));
1251 m_error
= GSOCK_TIMEDOUT
;
1252 return GSOCK_TIMEDOUT
;
1256 GSocket_Debug(( "GSocket_Input_Timeout, select returned -1\n" ));
1257 if (errno
== EBADF
) { GSocket_Debug(( "Invalid file descriptor\n" )); }
1258 if (errno
== EINTR
) { GSocket_Debug(( "A non blocked signal was caught\n" )); }
1259 if (errno
== EINVAL
) { GSocket_Debug(( "The highest number descriptor is negative\n" )); }
1260 if (errno
== ENOMEM
) { GSocket_Debug(( "Not enough memory\n" )); }
1261 m_error
= GSOCK_TIMEDOUT
;
1262 return GSOCK_TIMEDOUT
;
1265 return GSOCK_NOERROR
;
1268 /* _GSocket_Output_Timeout:
1269 * For blocking sockets, wait until data can be sent without
1270 * blocking or until timeout ellapses.
1272 GSocketError
GSocket::Output_Timeout()
1278 /* Linux select() will overwrite the struct on return */
1279 tv
.tv_sec
= (m_timeout
/ 1000);
1280 tv
.tv_usec
= (m_timeout
% 1000) * 1000;
1282 GSocket_Debug( ("m_non_blocking has: %d\n", (int)m_non_blocking
) );
1284 if (!m_non_blocking
)
1287 FD_SET(m_fd
, &writefds
);
1288 ret
= select(m_fd
+ 1, NULL
, &writefds
, NULL
, &tv
);
1291 GSocket_Debug(( "GSocket_Output_Timeout, select returned 0\n" ));
1292 m_error
= GSOCK_TIMEDOUT
;
1293 return GSOCK_TIMEDOUT
;
1297 GSocket_Debug(( "GSocket_Output_Timeout, select returned -1\n" ));
1298 if (errno
== EBADF
) { GSocket_Debug(( "Invalid file descriptor\n" )); }
1299 if (errno
== EINTR
) { GSocket_Debug(( "A non blocked signal was caught\n" )); }
1300 if (errno
== EINVAL
) { GSocket_Debug(( "The highest number descriptor is negative\n" )); }
1301 if (errno
== ENOMEM
) { GSocket_Debug(( "Not enough memory\n" )); }
1302 m_error
= GSOCK_TIMEDOUT
;
1303 return GSOCK_TIMEDOUT
;
1305 if ( ! FD_ISSET(m_fd
, &writefds
) ) {
1306 GSocket_Debug(( "GSocket_Output_Timeout is buggy!\n" ));
1309 GSocket_Debug(( "GSocket_Output_Timeout seems correct\n" ));
1314 GSocket_Debug(( "GSocket_Output_Timeout, didn't try select!\n" ));
1317 return GSOCK_NOERROR
;
1320 int GSocket::Recv_Stream(char *buffer
, int size
)
1325 ret
= recv(m_fd
, buffer
, size
, GSOCKET_MSG_NOSIGNAL
);
1326 } while (ret
== -1 && errno
== EINTR
); /* Loop until not interrupted */
1330 int GSocket::Recv_Dgram(char *buffer
, int size
)
1332 struct sockaddr from
;
1333 WX_SOCKLEN_T fromlen
= sizeof(from
);
1337 fromlen
= sizeof(from
);
1341 ret
= recvfrom(m_fd
, buffer
, size
, 0, &from
, (WX_SOCKLEN_T
*) &fromlen
);
1342 } while (ret
== -1 && errno
== EINTR
); /* Loop until not interrupted */
1347 /* Translate a system address into a GSocket address */
1350 m_peer
= GAddress_new();
1353 m_error
= GSOCK_MEMERR
;
1357 err
= _GAddress_translate_from(m_peer
, &from
, fromlen
);
1358 if (err
!= GSOCK_NOERROR
)
1360 GAddress_destroy(m_peer
);
1369 int GSocket::Send_Stream(const char *buffer
, int size
)
1377 ret
= send(m_fd
, (char *)buffer
, size
, GSOCKET_MSG_NOSIGNAL
);
1378 } while (ret
== -1 && errno
== EINTR
); /* Loop until not interrupted */
1385 int GSocket::Send_Dgram(const char *buffer
, int size
)
1387 struct sockaddr
*addr
;
1393 m_error
= GSOCK_INVADDR
;
1397 err
= _GAddress_translate_to(m_peer
, &addr
, &len
);
1398 if (err
!= GSOCK_NOERROR
)
1408 ret
= sendto(m_fd
, (char *)buffer
, size
, 0, addr
, len
);
1409 } while (ret
== -1 && errno
== EINTR
); /* Loop until not interrupted */
1413 /* Frees memory allocated from _GAddress_translate_to */
1419 void GSocket::Detected_Read()
1423 /* Safeguard against straggling call to Detected_Read */
1424 if (m_fd
== INVALID_SOCKET
)
1429 /* If we have already detected a LOST event, then don't try
1430 * to do any further processing.
1432 if ((m_detected
& GSOCK_LOST_FLAG
) != 0)
1434 m_establishing
= false;
1436 CALL_CALLBACK(this, GSOCK_LOST
);
1441 int num
= recv(m_fd
, &c
, 1, MSG_PEEK
| GSOCKET_MSG_NOSIGNAL
);
1445 CALL_CALLBACK(this, GSOCK_INPUT
);
1449 if (m_server
&& m_stream
)
1451 CALL_CALLBACK(this, GSOCK_CONNECTION
);
1455 /* Do not throw a lost event in cases where the socket isn't really lost */
1456 if ((errno
== EWOULDBLOCK
) || (errno
== EAGAIN
) || (errno
== EINTR
))
1458 CALL_CALLBACK(this, GSOCK_INPUT
);
1462 CALL_CALLBACK(this, GSOCK_LOST
);
1469 void GSocket::Detected_Write()
1471 /* If we have already detected a LOST event, then don't try
1472 * to do any further processing.
1474 if ((m_detected
& GSOCK_LOST_FLAG
) != 0)
1476 m_establishing
= false;
1478 CALL_CALLBACK(this, GSOCK_LOST
);
1483 if (m_establishing
&& !m_server
)
1486 SOCKOPTLEN_T len
= sizeof(error
);
1488 m_establishing
= false;
1490 getsockopt(m_fd
, SOL_SOCKET
, SO_ERROR
, (char*)&error
, &len
);
1494 CALL_CALLBACK(this, GSOCK_LOST
);
1499 CALL_CALLBACK(this, GSOCK_CONNECTION
);
1500 /* We have to fire this event by hand because CONNECTION (for clients)
1501 * and OUTPUT are internally the same and we just disabled CONNECTION
1502 * events with the above macro.
1504 CALL_CALLBACK(this, GSOCK_OUTPUT
);
1509 CALL_CALLBACK(this, GSOCK_OUTPUT
);
1513 /* Compatibility functions for GSocket */
1514 GSocket
*GSocket_new(void)
1516 GSocket
*newsocket
= new GSocket();
1517 if(newsocket
->IsOk())
1524 * -------------------------------------------------------------------------
1526 * -------------------------------------------------------------------------
1529 /* CHECK_ADDRESS verifies that the current address family is either
1530 * GSOCK_NOFAMILY or GSOCK_*family*, and if it is GSOCK_NOFAMILY, it
1531 * initalizes it to be a GSOCK_*family*. In other cases, it returns
1532 * an appropiate error code.
1534 * CHECK_ADDRESS_RETVAL does the same but returning 'retval' on error.
1536 #define CHECK_ADDRESS(address, family) \
1538 if (address->m_family == GSOCK_NOFAMILY) \
1539 if (_GAddress_Init_##family(address) != GSOCK_NOERROR) \
1540 return address->m_error; \
1541 if (address->m_family != GSOCK_##family) \
1543 address->m_error = GSOCK_INVADDR; \
1544 return GSOCK_INVADDR; \
1548 #define CHECK_ADDRESS_RETVAL(address, family, retval) \
1550 if (address->m_family == GSOCK_NOFAMILY) \
1551 if (_GAddress_Init_##family(address) != GSOCK_NOERROR) \
1553 if (address->m_family != GSOCK_##family) \
1555 address->m_error = GSOCK_INVADDR; \
1561 GAddress
*GAddress_new(void)
1565 if ((address
= (GAddress
*) malloc(sizeof(GAddress
))) == NULL
)
1568 address
->m_family
= GSOCK_NOFAMILY
;
1569 address
->m_addr
= NULL
;
1575 GAddress
*GAddress_copy(GAddress
*address
)
1579 assert(address
!= NULL
);
1581 if ((addr2
= (GAddress
*) malloc(sizeof(GAddress
))) == NULL
)
1584 memcpy(addr2
, address
, sizeof(GAddress
));
1586 if (address
->m_addr
&& address
->m_len
> 0)
1588 addr2
->m_addr
= (struct sockaddr
*)malloc(addr2
->m_len
);
1589 if (addr2
->m_addr
== NULL
)
1594 memcpy(addr2
->m_addr
, address
->m_addr
, addr2
->m_len
);
1600 void GAddress_destroy(GAddress
*address
)
1602 assert(address
!= NULL
);
1604 if (address
->m_addr
)
1605 free(address
->m_addr
);
1610 void GAddress_SetFamily(GAddress
*address
, GAddressType type
)
1612 assert(address
!= NULL
);
1614 address
->m_family
= type
;
1617 GAddressType
GAddress_GetFamily(GAddress
*address
)
1619 assert(address
!= NULL
);
1621 return address
->m_family
;
1624 GSocketError
_GAddress_translate_from(GAddress
*address
,
1625 struct sockaddr
*addr
, int len
)
1627 address
->m_realfamily
= addr
->sa_family
;
1628 switch (addr
->sa_family
)
1631 address
->m_family
= GSOCK_INET
;
1634 address
->m_family
= GSOCK_UNIX
;
1638 address
->m_family
= GSOCK_INET6
;
1643 address
->m_error
= GSOCK_INVOP
;
1648 if (address
->m_addr
)
1649 free(address
->m_addr
);
1651 address
->m_len
= len
;
1652 address
->m_addr
= (struct sockaddr
*)malloc(len
);
1654 if (address
->m_addr
== NULL
)
1656 address
->m_error
= GSOCK_MEMERR
;
1657 return GSOCK_MEMERR
;
1659 memcpy(address
->m_addr
, addr
, len
);
1661 return GSOCK_NOERROR
;
1664 GSocketError
_GAddress_translate_to(GAddress
*address
,
1665 struct sockaddr
**addr
, int *len
)
1667 if (!address
->m_addr
)
1669 address
->m_error
= GSOCK_INVADDR
;
1670 return GSOCK_INVADDR
;
1673 *len
= address
->m_len
;
1674 *addr
= (struct sockaddr
*)malloc(address
->m_len
);
1677 address
->m_error
= GSOCK_MEMERR
;
1678 return GSOCK_MEMERR
;
1681 memcpy(*addr
, address
->m_addr
, address
->m_len
);
1682 return GSOCK_NOERROR
;
1686 * -------------------------------------------------------------------------
1687 * Internet address family
1688 * -------------------------------------------------------------------------
1691 GSocketError
_GAddress_Init_INET(GAddress
*address
)
1693 address
->m_len
= sizeof(struct sockaddr_in
);
1694 address
->m_addr
= (struct sockaddr
*) malloc(address
->m_len
);
1695 if (address
->m_addr
== NULL
)
1697 address
->m_error
= GSOCK_MEMERR
;
1698 return GSOCK_MEMERR
;
1701 address
->m_family
= GSOCK_INET
;
1702 address
->m_realfamily
= PF_INET
;
1703 ((struct sockaddr_in
*)address
->m_addr
)->sin_family
= AF_INET
;
1704 ((struct sockaddr_in
*)address
->m_addr
)->sin_addr
.s_addr
= INADDR_ANY
;
1706 return GSOCK_NOERROR
;
1709 GSocketError
GAddress_INET_SetHostName(GAddress
*address
, const char *hostname
)
1712 struct in_addr
*addr
;
1714 assert(address
!= NULL
);
1716 CHECK_ADDRESS(address
, INET
);
1718 addr
= &(((struct sockaddr_in
*)address
->m_addr
)->sin_addr
);
1720 /* If it is a numeric host name, convert it now */
1721 #if defined(HAVE_INET_ATON)
1722 if (inet_aton(hostname
, addr
) == 0)
1724 #elif defined(HAVE_INET_ADDR)
1725 if ( (addr
->s_addr
= inet_addr(hostname
)) == (unsigned)-1 )
1728 /* Use gethostbyname by default */
1730 int val
= 1; /* VA doesn't like constants in conditional expressions */
1735 struct in_addr
*array_addr
;
1737 /* It is a real name, we solve it */
1738 if ((he
= gethostbyname(hostname
)) == NULL
)
1740 /* Reset to invalid address */
1741 addr
->s_addr
= INADDR_NONE
;
1742 address
->m_error
= GSOCK_NOHOST
;
1743 return GSOCK_NOHOST
;
1745 array_addr
= (struct in_addr
*) *(he
->h_addr_list
);
1746 addr
->s_addr
= array_addr
[0].s_addr
;
1748 return GSOCK_NOERROR
;
1751 GSocketError
GAddress_INET_SetAnyAddress(GAddress
*address
)
1753 return GAddress_INET_SetHostAddress(address
, INADDR_ANY
);
1756 GSocketError
GAddress_INET_SetHostAddress(GAddress
*address
,
1757 unsigned long hostaddr
)
1759 struct in_addr
*addr
;
1761 assert(address
!= NULL
);
1763 CHECK_ADDRESS(address
, INET
);
1765 addr
= &(((struct sockaddr_in
*)address
->m_addr
)->sin_addr
);
1766 addr
->s_addr
= htonl(hostaddr
);
1768 return GSOCK_NOERROR
;
1771 GSocketError
GAddress_INET_SetPortName(GAddress
*address
, const char *port
,
1772 const char *protocol
)
1775 struct sockaddr_in
*addr
;
1777 assert(address
!= NULL
);
1778 CHECK_ADDRESS(address
, INET
);
1782 address
->m_error
= GSOCK_INVPORT
;
1783 return GSOCK_INVPORT
;
1786 #if defined(__WXPM__) && defined(__EMX__)
1787 se
= getservbyname(port
, (char*)protocol
);
1789 se
= getservbyname(port
, protocol
);
1793 /* the cast to int suppresses compiler warnings about subscript having the
1795 if (isdigit((int)port
[0]))
1799 port_int
= atoi(port
);
1800 addr
= (struct sockaddr_in
*)address
->m_addr
;
1801 addr
->sin_port
= htons(port_int
);
1802 return GSOCK_NOERROR
;
1805 address
->m_error
= GSOCK_INVPORT
;
1806 return GSOCK_INVPORT
;
1809 addr
= (struct sockaddr_in
*)address
->m_addr
;
1810 addr
->sin_port
= se
->s_port
;
1812 return GSOCK_NOERROR
;
1815 GSocketError
GAddress_INET_SetPort(GAddress
*address
, unsigned short port
)
1817 struct sockaddr_in
*addr
;
1819 assert(address
!= NULL
);
1820 CHECK_ADDRESS(address
, INET
);
1822 addr
= (struct sockaddr_in
*)address
->m_addr
;
1823 addr
->sin_port
= htons(port
);
1825 return GSOCK_NOERROR
;
1828 GSocketError
GAddress_INET_GetHostName(GAddress
*address
, char *hostname
, size_t sbuf
)
1832 struct sockaddr_in
*addr
;
1834 assert(address
!= NULL
);
1835 CHECK_ADDRESS(address
, INET
);
1837 addr
= (struct sockaddr_in
*)address
->m_addr
;
1838 addr_buf
= (char *)&(addr
->sin_addr
);
1840 he
= gethostbyaddr(addr_buf
, sizeof(addr
->sin_addr
), AF_INET
);
1843 address
->m_error
= GSOCK_NOHOST
;
1844 return GSOCK_NOHOST
;
1847 strncpy(hostname
, he
->h_name
, sbuf
);
1849 return GSOCK_NOERROR
;
1852 unsigned long GAddress_INET_GetHostAddress(GAddress
*address
)
1854 struct sockaddr_in
*addr
;
1856 assert(address
!= NULL
);
1857 CHECK_ADDRESS_RETVAL(address
, INET
, 0);
1859 addr
= (struct sockaddr_in
*)address
->m_addr
;
1861 return ntohl(addr
->sin_addr
.s_addr
);
1864 unsigned short GAddress_INET_GetPort(GAddress
*address
)
1866 struct sockaddr_in
*addr
;
1868 assert(address
!= NULL
);
1869 CHECK_ADDRESS_RETVAL(address
, INET
, 0);
1871 addr
= (struct sockaddr_in
*)address
->m_addr
;
1872 return ntohs(addr
->sin_port
);
1876 * -------------------------------------------------------------------------
1877 * Unix address family
1878 * -------------------------------------------------------------------------
1881 #ifndef __VISAGECPP__
1882 GSocketError
_GAddress_Init_UNIX(GAddress
*address
)
1884 address
->m_len
= sizeof(struct sockaddr_un
);
1885 address
->m_addr
= (struct sockaddr
*)malloc(address
->m_len
);
1886 if (address
->m_addr
== NULL
)
1888 address
->m_error
= GSOCK_MEMERR
;
1889 return GSOCK_MEMERR
;
1892 address
->m_family
= GSOCK_UNIX
;
1893 address
->m_realfamily
= PF_UNIX
;
1894 ((struct sockaddr_un
*)address
->m_addr
)->sun_family
= AF_UNIX
;
1895 ((struct sockaddr_un
*)address
->m_addr
)->sun_path
[0] = 0;
1897 return GSOCK_NOERROR
;
1900 #define UNIX_SOCK_PATHLEN (sizeof(addr->sun_path)/sizeof(addr->sun_path[0]))
1902 GSocketError
GAddress_UNIX_SetPath(GAddress
*address
, const char *path
)
1904 struct sockaddr_un
*addr
;
1906 assert(address
!= NULL
);
1908 CHECK_ADDRESS(address
, UNIX
);
1910 addr
= ((struct sockaddr_un
*)address
->m_addr
);
1911 strncpy(addr
->sun_path
, path
, UNIX_SOCK_PATHLEN
);
1912 addr
->sun_path
[UNIX_SOCK_PATHLEN
- 1] = '\0';
1914 return GSOCK_NOERROR
;
1917 GSocketError
GAddress_UNIX_GetPath(GAddress
*address
, char *path
, size_t sbuf
)
1919 struct sockaddr_un
*addr
;
1921 assert(address
!= NULL
);
1922 CHECK_ADDRESS(address
, UNIX
);
1924 addr
= (struct sockaddr_un
*)address
->m_addr
;
1926 strncpy(path
, addr
->sun_path
, sbuf
);
1928 return GSOCK_NOERROR
;
1930 #endif /* !defined(__VISAGECPP__) */
1931 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */