tNetBuf functions now update the "Error" field when an error occurs - 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 322ccf9499188e8f8bf6bd047e326d5fe57cc197
 (DIR) parent b60ede18a023484b718a3eb509d999cba892589c
 (HTM) Author: Ben Webb <ben@salilab.org>
       Date:   Thu, 13 Sep 2001 18:48:33 +0000
       
       NetBuf functions now update the "Error" field when an error occurs
       
       
       Diffstat:
         M src/dopewars.h                      |       1 +
         M src/message.c                       |      33 ++++++++++++++-----------------
       
       2 files changed, 16 insertions(+), 18 deletions(-)
       ---
 (DIR) diff --git a/src/dopewars.h b/src/dopewars.h
       t@@ -276,6 +276,7 @@ struct _NetworkBuffer {
           ConnBuf ReadBuf;       /* New data, waiting for the application */
           ConnBuf WriteBuf;      /* Data waiting to be written to the wire */
           gboolean WaitConnect;  /* TRUE if a non-blocking connect is in progress */
       +   gint Error;            /* If non-NULL, any error from the last operation */
        };
        
        struct PLAYER_T {
 (DIR) diff --git a/src/message.c b/src/message.c
       t@@ -530,7 +530,7 @@ gboolean ReadDataFromWire(NetworkBuffer *NetBuf) {
        /* into the read buffer. Returns FALSE if the connection was closed, or   */
        /* if the read buffer's maximum size was reached.                         */
           ConnBuf *conn;
       -   int CurrentPosition,BytesRead;
       +   int CurrentPosition,BytesRead,Error;
           conn=&NetBuf->ReadBuf;
           CurrentPosition=conn->DataPresent;
           while(1) {
       t@@ -545,10 +545,13 @@ gboolean ReadDataFromWire(NetworkBuffer *NetBuf) {
              BytesRead=recv(NetBuf->fd,&conn->Data[CurrentPosition],
                             conn->Length-CurrentPosition,0);
              if (BytesRead==SOCKET_ERROR) {
       +         Error = GetSocketError();
        #ifdef CYGWIN
       -         if (GetSocketError()==WSAEWOULDBLOCK) break; else return FALSE;
       +         if (Error==WSAEWOULDBLOCK) break;
       +         else { NetBuf->Error = Error; return FALSE; }
        #else
       -         if (GetSocketError()==EAGAIN) break; else return FALSE;
       +         if (Error==EAGAIN) break;
       +         else if (Error!=EINTR) { NetBuf->Error = Error; return FALSE; }
        #endif
              } else if (BytesRead==0) {
                 return FALSE;
       t@@ -1105,8 +1108,6 @@ char *StartConnect(int *fd,gchar *RemoteHost,unsigned RemotePort,
           struct sockaddr_in ClientAddr;
           struct hostent *he;
           static char NoHost[]= N_("Could not find host");
       -   static char NoSocket[]= N_("Could not create network socket");
       -   static char NoConnect[]= N_("Connection refused or no server present");
        
           if ((he=gethostbyname(RemoteHost))==NULL) {
              return NoHost;
       t@@ -1114,7 +1115,6 @@ char *StartConnect(int *fd,gchar *RemoteHost,unsigned RemotePort,
           *fd=socket(AF_INET,SOCK_STREAM,0);
           if (*fd==SOCKET_ERROR) {
              return strerror(errno);
       -/*    return NoSocket;*/
           }
        
           ClientAddr.sin_family=AF_INET;
       t@@ -1132,7 +1132,6 @@ char *StartConnect(int *fd,gchar *RemoteHost,unsigned RemotePort,
        #endif
              CloseSocket(*fd); *fd=-1;
              return strerror(errno);
       -/*    return NoConnect;*/
           } else {
              fcntl(*fd,F_SETFL,O_NONBLOCK);
           }
       t@@ -1140,26 +1139,24 @@ char *StartConnect(int *fd,gchar *RemoteHost,unsigned RemotePort,
        }
        
        char *FinishConnect(int fd) {
       -   static char NoConnect[]= N_("Connection refused or no server present");
       +   int Error;
        #ifdef CYGWIN
       -   if (GetSocketError()!=0) return NoConnect;
       -   else return NULL;
       +   Error = GetSocketError();
       +   if (Error==0) return NULL;
       +   else return strerror(Error);
        #else
       -   int optval;
        #ifdef HAVE_SOCKLEN_T
           socklen_t optlen;
        #else
           int optlen;
        #endif
        
       -   optlen=sizeof(optval);
       -   if (getsockopt(fd,SOL_SOCKET,SO_ERROR,&optval,&optlen)==-1) {
       -      return strerror(errno);
       -/*    return NoConnect;*/
       +   optlen=sizeof(Error);
       +   if (getsockopt(fd,SOL_SOCKET,SO_ERROR,&Error,&optlen)==-1) {
       +      Error = errno;
           }
       -   if (optval==0) return NULL;
       -   else return strerror(optval);
       -/* else return NoConnect;*/
       +   if (Error==0) return NULL;
       +   else return strerror(Error);
        #endif /* CYGWIN */
        }