tTidy-up of functions for getting network errors under Windows and Unix. - vaccinewars - be a doctor and try to vaccinate the world
 (HTM) git clone git://src.adamsgaard.dk/vaccinewars
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 145766dd9aca986d4f7ddcd0f6224e940ef692f3
 (DIR) parent 2aa4bafdef44d5998a737aaf213a4ec4db2c7d2e
 (HTM) Author: Ben Webb <ben@salilab.org>
       Date:   Tue, 16 Jul 2002 12:40:31 +0000
       
       Tidy-up of functions for getting network errors under Windows and Unix.
       
       
       Diffstat:
         M src/network.c                       |      30 ++++++++++++------------------
       
       1 file changed, 12 insertions(+), 18 deletions(-)
       ---
 (DIR) diff --git a/src/network.c b/src/network.c
       t@@ -968,18 +968,20 @@ void QueueMessageForSend(NetworkBuffer *NetBuf, gchar *data)
          CommitWriteBuffer(NetBuf, conn, addpt, addlen);
        }
        
       +static void SetNetworkError(LastError **error) {
       +#ifdef CYGWIN
       +  SetError(error, ET_WINSOCK, WSAGetLastError(), NULL);
       +#else
       +  SetError(error, ET_HERRNO, h_errno, NULL);
       +#endif
       +}
       +
        static struct hostent *LookupHostname(const gchar *host, LastError **error)
        {
          struct hostent *he;
        
       -  if ((he = gethostbyname(host)) == NULL) {
       -#ifdef CYGWIN
       -    if (error)
       -      SetError(error, ET_WINSOCK, WSAGetLastError(), NULL);
       -#else
       -    if (error)
       -      SetError(error, ET_HERRNO, h_errno, NULL);
       -#endif
       +  if ((he = gethostbyname(host)) == NULL && error) {
       +    SetNetworkError(error);
          }
          return he;
        }
       t@@ -1508,11 +1510,7 @@ int CreateTCPSocket(LastError **error)
          fd = socket(AF_INET, SOCK_STREAM, 0);
        
          if (fd == SOCKET_ERROR && error) {
       -#ifdef CYGWIN
       -    SetError(error, ET_WINSOCK, WSAGetLastError(), NULL);
       -#else
       -    SetError(error, ET_ERRNO, errno, NULL);
       -#endif
       +    SetNetworkError(error);
          }
        
          return fd;
       t@@ -1542,11 +1540,7 @@ gboolean BindTCPSocket(int sock, const gchar *addr, unsigned port,
              bind(sock, (struct sockaddr *)&bindaddr, sizeof(struct sockaddr));
        
          if (retval == SOCKET_ERROR && error) {
       -#ifdef CYGWIN
       -    SetError(error, ET_WINSOCK, WSAGetLastError(), NULL);
       -#else
       -    SetError(error, ET_ERRNO, errno, NULL);
       -#endif
       +    SetNetworkError(error);
          }
        
          return (retval != SOCKET_ERROR);