X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a324a7bccf4bda8f4f2bf09daee8104cae953cee..926076161327c12d8535c72235f91cee6d316281:/src/unix/gsocket.c diff --git a/src/unix/gsocket.c b/src/unix/gsocket.c index 7456ccf635..74ac09de4c 100644 --- a/src/unix/gsocket.c +++ b/src/unix/gsocket.c @@ -3,31 +3,18 @@ * Name: gsocket.c * Purpose: GSocket main Unix file * CVSID: $Id$ - * Log: $Log$ - * Log: Revision 1.1 1999/07/22 17:51:54 GL - * Log: Added GSocket for Unix (only GTK for the moment) - * Log: Updated wxSocket to use GSocket API - * Log: Added a progress bar to client.cpp - * Log: Added CopyTo to wxMemoryOutputStream to copy the internal buffer to a specified buffer. - * Log: Various changes/fixes to the high-level protocols FTP/HTTP - * Log: Various Unicode fixes - * Log: Removed sckint.* - * Log: - * Log: Revision 1.2 1999/07/18 15:52:34 guilhem - * Log: * Copyright, etc. - * Log: * ------------------------------------------------------------------------- */ #include #include +#include #ifdef vms #include #else #include #endif #include -#include #include #include #include @@ -39,7 +26,7 @@ #include #ifdef sun -#include + #include #endif #ifdef sgi @@ -47,10 +34,24 @@ #endif #include +#include +#include #include #include "gsockunx.h" +#ifndef SOCKLEN_T + +#ifdef __GLIBC__ +# if __GLIBC__ == 2 +# define SOCKLEN_T socklen_t +# endif +#else +# define SOCKLEN_T int +#endif + +#endif + /* Constructors / Destructors */ GSocket *GSocket_new() @@ -82,11 +83,11 @@ void GSocket_destroy(GSocket *socket) { assert(socket != NULL); - _GSocket_GUI_Destroy(socket); - if (socket->m_fd != -1) GSocket_Shutdown(socket); + _GSocket_GUI_Destroy(socket); + if (socket->m_local) GAddress_destroy(socket->m_local); @@ -116,7 +117,9 @@ void GSocket_Shutdown(GSocket *socket) GSocketError GSocket_SetLocal(GSocket *socket, GAddress *address) { - if (socket == NULL || (socket->m_fd != -1 && !socket->m_server)) + assert(socket != NULL); + + if ((socket->m_fd != -1 && !socket->m_server)) return GSOCK_INVSOCK; if (address == NULL || address->m_family == GSOCK_NOFAMILY) @@ -132,8 +135,7 @@ GSocketError GSocket_SetLocal(GSocket *socket, GAddress *address) GSocketError GSocket_SetPeer(GSocket *socket, GAddress *address) { - if (socket == NULL) - return GSOCK_INVSOCK; + assert(socket != NULL); if (address == NULL || address->m_family == GSOCK_NOFAMILY) { socket->m_error = GSOCK_INVADDR; @@ -152,7 +154,7 @@ GAddress *GSocket_GetLocal(GSocket *socket) { GAddress *address; struct sockaddr addr; - socklen_t size; + SOCKLEN_T size; assert(socket != NULL); @@ -193,7 +195,8 @@ GAddress *GSocket_GetPeer(GSocket *socket) GSocket_SetServer() setup the socket as a server. It uses the "Local" field of GSocket. "Local" must be set by GSocket_SetLocal() before GSocket_SetServer() is called. GSOCK_INVSOCK if socket has been initialized. - In the other cases, it returns GSOCK_INVADDR. + In case, you haven't yet defined the local address, it returns GSOCK_INVADDR. + In the other cases it returns GSOCK_IOERR. */ GSocketError GSocket_SetServer(GSocket *sck) { @@ -717,10 +720,13 @@ void _GAddress_translate_from(GAddress *address, struct sockaddr *addr, int len) case AF_UNIX: address->m_family = GSOCK_UNIX; break; +#ifdef AF_INET6 case AF_INET6: address->m_family = GSOCK_INET6; break; +#endif default: + /* TODO error */ } @@ -801,7 +807,8 @@ GSocketError GAddress_INET_SetHostAddress(GAddress *address, return GSOCK_NOERROR; } -GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port) +GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port, + const char *protocol) { struct servent *se; struct sockaddr_in *addr; @@ -815,7 +822,7 @@ GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port) } /* TODO: TCP or UDP */ - se = getservbyname(port, "tcp"); + se = getservbyname(port, protocol); if (!se) { if (isdigit(port[0])) { int port_int;