[Spread-cvs] cvs commit: spread/daemon Readme.txt alarm.c arch.h arch.c auth-pword-client.c data_link.c session.c sp.c

jonathan at spread.org jonathan at spread.org
Mon Feb 4 21:37:40 EST 2002


jonathan    02/02/04 21:37:40

  Modified:    daemon   Readme.txt alarm.c arch.h arch.c
                        auth-pword-client.c data_link.c session.c sp.c
  Log:
  Changed errno handling to be portable to Windows. New macro defines:
  sock_errno
  sock_set_errno
  sock_strerror
  
  All use of errno, strerror for sockets changed to sock_errno, sock_strerror.
  Setting of errno now uses sock_set_errno function.
  
  Added sock_strerror function for windows that returns strings for WSA errors.
  
  Moved #include <errno.h> to only be included on unix if it is only needed
  for sockets errno. (left it in log.c for stdio).
  
  Revision  Changes    Path
  1.15      +5 -0      spread/daemon/Readme.txt
  
  Index: Readme.txt
  ===================================================================
  RCS file: /storage/cvsroot/spread/daemon/Readme.txt,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Readme.txt	4 Feb 2002 22:35:09 -0000	1.14
  +++ Readme.txt	5 Feb 2002 02:37:38 -0000	1.15
  @@ -58,7 +58,12 @@
         Thanks to Marc Zyngier for discovering the problem and writing and 
         testing a patch for it.
      c) Raise the FD_SETSIZE for windows to 1024 by #defining it in arch.h.
  +   d) Enhanced error handling to support WSAGetLastError, and define a
  +      sock_strerror() function to return nice error strings on windows.
   4) Included improved NetBSD makefile and warning fix from Patrick Welche.
  +5) Generalize the errno handling to support windows errors and other 
  +   odd cases. Also see fix 3d. Thanks to Marc Zyngier, Tim Peters, and
  +   David Holmer for help with this.
   
   December 11, 2001 Ver 3.16.1  
   ------------------------
  
  
  
  1.2       +5 -4      spread/daemon/alarm.c
  
  Index: alarm.c
  ===================================================================
  RCS file: /storage/cvsroot/spread/daemon/alarm.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- alarm.c	21 Aug 2001 14:28:21 -0000	1.1
  +++ alarm.c	5 Feb 2002 02:37:39 -0000	1.2
  @@ -35,6 +35,7 @@
   #include <stdlib.h>
   #include <string.h>
   #include <time.h>
  +#include <errno.h>
   
   #ifdef HAVE_GOOD_VARGS
   #include <stdarg.h>
  @@ -83,7 +84,7 @@
   
   	if ( EXIT & mask )
   	{
  -	    perror("errno say:");
  +	    printf("Exit caused by Alarm(EXIT)\n");
               exit( 0 );
   	}
   }
  @@ -118,7 +119,7 @@
           }
   	if ( EXIT & mask )
   	{
  -	    perror("errno say:");
  +	    printf("Exit caused by Alarm(EXIT)\n");
   	    exit( 0 );
   	}
   }
  @@ -139,11 +140,11 @@
           FILE *newfile;
           newfile = freopen(filename, "a", stdout);
           if ( NULL == newfile ) {
  -                perror("failed to open file for stdout");
  +                printf("failed to open file (%s) for stdout. Error: %d\n", filename, errno);
           }
           newfile = freopen(filename, "a", stderr);
           if ( NULL == newfile ) {
  -                perror("failed to open file for stderr");
  +                printf("failed to open file (%s) for stderr. Error: %d\n", filename, errno);
           }
           setvbuf(stderr, (char *)0, _IONBF, 0);
           setvbuf(stdout, (char *)0, _IONBF, 0);
  
  
  
  1.9       +85 -0     spread/daemon/arch.h
  
  Index: arch.h
  ===================================================================
  RCS file: /storage/cvsroot/spread/daemon/arch.h,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- arch.h	4 Feb 2002 22:35:08 -0000	1.8
  +++ arch.h	5 Feb 2002 02:37:39 -0000	1.9
  @@ -47,6 +47,10 @@
    *      #define         HAVE_LRAND48 ( exists if true )
    *      #define         HAVE_STDINT_H   ( exists if true --currently glibc2.1 needs it )
    *      typedef         {sys dependent type} sockopt_len_t;
  + *      #define         ERR_TIMEDOUT    EAGAIN
  + *      #define         sock_errno { errno or WSAGetLastError() for windows }
  + *      #define         sock_strerror { strerror or sock_strerror for windows }
  + *      #define         sock_set_errno { sock_unix_set_errno or WSASetLastError for windows }
    */
   
   #ifdef _AIX
  @@ -150,6 +154,9 @@
   #define         HAVE_LRAND48
   typedef         unsigned long  sockopt_len_t;
   #define         ERR_TIMEDOUT    ETIMEDOUT
  +#define         sock_errno      errno
  +#define         sock_strerror   strerror
  +#define         sock_set_errno  sock_unix_set_errno
   #endif /* ARCH_POWER_AIX */
   
   #ifdef ARCH_ALPHA_LINUX
  @@ -168,6 +175,9 @@
   /* this define is needed for glibc2.1 but should be turned off for glibc2.0 and earlier. */
   #define         HAVE_STDINT_H
   #define         ERR_TIMEDOUT    ETIMEDOUT
  +#define         sock_errno      errno
  +#define         sock_strerror   strerror
  +#define         sock_set_errno  sock_unix_set_errno
   #endif /* ARCH_ALPHA_LINUX */
   
   #ifdef ARCH_IA64_LINUX
  @@ -186,6 +196,9 @@
   /* this define is needed for glibc2.1 but should be turned off for glibc2.0 and earlier. */
   #define         HAVE_STDINT_H
   #define         ERR_TIMEDOUT    ETIMEDOUT
  +#define         sock_errno      errno
  +#define         sock_strerror   strerror
  +#define         sock_set_errno  sock_unix_set_errno
   #endif /* ARCH_ALPHA_LINUX */
   
   #ifdef ARCH_PC_BSDI
  @@ -202,6 +215,9 @@
      typedef         int       socklen_t;
   */
   #define         ERR_TIMEDOUT    ETIMEDOUT
  +#define         sock_errno      errno
  +#define         sock_strerror   strerror
  +#define         sock_set_errno  sock_unix_set_errno
   #endif /* ARCH_PC_BSDI */
   
   #ifdef ARCH_PC_OPENBSD
  @@ -219,6 +235,9 @@
     typedef         u_int32_t   socklen_t;
   */
   #define         ERR_TIMEDOUT    ETIMEDOUT
  +#define         sock_errno      errno
  +#define         sock_strerror   strerror
  +#define         sock_set_errno  sock_unix_set_errno
   #endif /* ARCH_PC_OPENBSD */
   
   #ifdef ARCH_PC_FREEBSD4
  @@ -236,6 +255,9 @@
     typedef         u_int32_t   socklen_t;
   */
   #define         ERR_TIMEDOUT    ETIMEDOUT
  +#define         sock_errno      errno
  +#define         sock_strerror   strerror
  +#define         sock_set_errno  sock_unix_set_errno
   #endif /* ARCH_PC_FREEBSD */
   
   #ifdef ARCH_PC_FREEBSD3
  @@ -251,6 +273,9 @@
   typedef         int     sockopt_len_t;
   typedef         u_int32_t   socklen_t;
   #define         ERR_TIMEDOUT    ETIMEDOUT
  +#define         sock_errno      errno
  +#define         sock_strerror   strerror
  +#define         sock_set_errno  sock_unix_set_errno
   #endif /* ARCH_PC_FREEBSD3 */
   
   #ifdef ARCH_PC_LINUX
  @@ -269,6 +294,9 @@
   /* this define is needed for glibc2.1 but should be turned off for glibc2.0 and earlier. */
   #define         HAVE_STDINT_H
   #define         ERR_TIMEDOUT    ETIMEDOUT
  +#define         sock_errno      errno
  +#define         sock_strerror   strerror
  +#define         sock_set_errno  sock_unix_set_errno
   #endif /* ARCH_PC_LINUX */
   
   #ifdef ARCH_PPC_DARWIN
  @@ -283,6 +311,9 @@
   typedef         int sockopt_len_t;
   typedef         int socklen_t;
   #define         ERR_TIMEDOUT    ETIMEDOUT
  +#define         sock_errno      errno
  +#define         sock_strerror   strerror
  +#define         sock_set_errno  sock_unix_set_errno
   #endif  /* ARCH_PPC_DARWIN */
   
   
  @@ -303,6 +334,9 @@
   /* this define is needed for solaris 5.[67] but maybe should be turned off for earlier. */
   #define         HAVE_SYS_INTTYPES_H
   #define         ERR_TIMEDOUT    ETIMEDOUT
  +#define         sock_errno      errno
  +#define         sock_strerror   strerror
  +#define         sock_set_errno  sock_unix_set_errno
   #endif
   
   #ifdef	ARCH_SPARC_SOLARIS
  @@ -321,6 +355,9 @@
   #endif /* NEED_SOCKLEN_T */
   #define         HAVE_SYS_INTTYPES_H
   #define         ERR_TIMEDOUT    ETIMEDOUT
  +#define         sock_errno      errno
  +#define         sock_strerror   strerror
  +#define         sock_set_errno  sock_unix_set_errno
   #endif /* ARCH_SUN_UNIX */
   
   #ifdef ARCH_SPARC_LINUX
  @@ -335,6 +372,9 @@
   typedef         int     sockopt_len_t;
   typedef         int     socklen_t;
   #define         ERR_TIMEDOUT    ETIMEDOUT
  +#define         sock_errno      errno
  +#define         sock_strerror   strerror
  +#define         sock_set_errno  sock_unix_set_errno
   #endif /* ARCH_SPARC_LINUX */
   
   #ifdef	ARCH_SPARC_SUNOS
  @@ -349,6 +389,9 @@
   /* This size is for packing several messages into one packet */
   #define         ARCH_SCATTER_SIZE       64
   #define         ERR_TIMEDOUT    ETIMEDOUT
  +#define         sock_errno      errno
  +#define         sock_strerror   strerror
  +#define         sock_set_errno  sock_unix_set_errno
   #endif /* ARCH_SPARC_SUNOS */
   
   #ifdef ARCH_SGI_IRIX
  @@ -366,6 +409,9 @@
   typedef         int     sockopt_len_t;
   typedef         int     socklen_t;
   #define         ERR_TIMEDOUT    ETIMEDOUT
  +#define         sock_errno      errno
  +#define         sock_strerror   strerror
  +#define         sock_set_errno  sock_unix_set_errno
   #endif /* ARCH_SGI_UNIX */
   
   #ifdef ARCH_ALL_NETBSD
  @@ -399,6 +445,9 @@
   #define         HAVE_STDINT_H
   typedef         int sockopt_len_t;
   #define         ERR_TIMEDOUT    ETIMEDOUT
  +#define         sock_errno      errno
  +#define         sock_strerror   strerror
  +#define         sock_set_errno  sock_unix_set_errno
   #endif  /* ARCH_ALL_NETBSD */
    
   #ifdef ARCH_PC_WIN95 
  @@ -412,6 +461,9 @@
   /* This size is for packing several messages into one packet */
   #define         ARCH_SCATTER_SIZE       64
   #define         ERR_TIMEDOUT    EAGAIN
  +#define         sock_errno      WSAGetLastError()
  +#define         sock_strerror   sock_strerror
  +#define         sock_set_errno  WSASetLastError
   #define         MAXPATHLEN      _MAX_PATH
   #define         snprintf        _snprintf
   #define         alloca          _alloca
  @@ -421,6 +473,19 @@
    * can be raised by defining a larger constant before including windows.h winsock.h
    */
   #define         FD_SETSIZE      1024
  +/* Use winsock constants since we are dealing with sockets 
  + * Note: If we ever need file IO with errno's we will have conflicts
  + * since the WSA version and the basic E versions may not have the same
  + * number. Right now we don't need the E versions for windows so we just
  + * use the WSA versions.
  + */
  +#undef EINTR
  +#undef EAGAIN
  +#undef EWOULDBLOCK
  +#define EWOULDBLOCK WSAEWOULDBLOCK
  +#define EINTR       WSAEINTR
  +#define EAGAIN      WSAEWOULDBLOCK
  +
   #endif /* ARCH_PC_WIN95 */
   
   /* to grab UINT32_MAX definitions if they exist */
  @@ -437,7 +502,27 @@
   #define get_rand rand
   #endif
   
  +/* Figure out which version of EAGAIN or EWOULDBLOCK this OS uses.
  + * End up with both constants defined.
  + */
  +#ifndef ARCH_PC_WIN95
  +#include <errno.h>
  +#endif
  +
  +#ifdef EWOULDBLOCK
  +#  ifndef EAGAIN
  +#    define EAGAIN EWOULDBLOCK
  +#  endif
  +#else
  +#  ifdef EAGAIN
  +#    define EWOULDBLOCK EAGAIN
  +#  else
  +#    error Neither EAGAIN nor EWOULDBLOCK exist
  +#  endif
  +#endif
   
  +/* Define the unix sock_unix_set_errno macro */
  +#define sock_unix_set_errno(errno_to_set) (errno = (errno_to_set) )
   
   #ifdef  INTSIZE64
   
  
  
  
  1.2       +55 -0     spread/daemon/arch.c
  
  Index: arch.c
  ===================================================================
  RCS file: /storage/cvsroot/spread/daemon/arch.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- arch.c	21 Aug 2001 14:28:21 -0000	1.1
  +++ arch.c	5 Feb 2002 02:37:39 -0000	1.2
  @@ -34,6 +34,10 @@
   #include "arch.h"
   #include <stdlib.h>
   
  +#ifdef ARCH_PC_WIN95
  +#include <winsock.h>
  +#endif
  +
   #ifdef ARCH_SPARC_SUNOS
   /* return value only valid until next call to strerror */
   
  @@ -46,6 +50,57 @@
           msg = buf;
   
           return(msg);
  +}
  +
  +#endif
  +
  +#ifdef ARCH_PC_WIN95
  +/* return value only valid until next call to sock_strerror */
  +
  +char    *sock_strerror(int err)
  +{
  +        switch( err ) {
  +        case WSANOTINITIALISED:
  +            return "WSANOTINITIALISED: A successful WSAStartup() must occur before using this function.";
  +        case WSAENETDOWN:
  +            return "WSAENETDOWN: The network subsystem has failed.";
  +        case WSAEACCES:
  +            return "WSAEACCES: The requested address is a broadcast address, but the appropriate flag was not set. Call setsockopt with the SO_BROADCAST parameter to allow the use of the broadcast address.";
  +        case WSAEINTR:
  +            return "WSAEINTR: A blocking Windows Sockets 1.1 call was canceled through WSACancelBlockingCall.";
  +        case WSAEINPROGRESS:
  +            return "WSAEINPROGRESS: A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.";
  +        case WSAEFAULT:
  +            return "WSAEFAULT: The buf parameter is not completely contained in a valid part of the user address space." ;
  +        case WSAENETRESET:
  +            return "WSAENETRESET: The connection has been broken due to the keep-alive activity detecting a failure while the operation was in progress.";
  +        case WSAENOBUFS:
  +            return "WSAENOBUFS: No buffer space is available.";
  +        case WSAENOTCONN:
  +            return "WSAENOTCONN: The socket is not connected.";
  +        case WSAENOTSOCK:
  +            return "WSAENOTSOCK: The descriptor is not a socket.";
  +        case WSAEOPNOTSUPP:
  +            return "WSAEOPNOTSUPP: MSG_OOB was specified, but the socket is not stream-style such as type SOCK_STREAM, out-of-band data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only receive operations.";
  +        case WSAESHUTDOWN:
  +            return "WSAESHUTDOWN The socket has been shut down; it is not possible to send on a socket after shutdown has been invoked with how set to SD_SEND or SD_BOTH.";
  +        case WSAEWOULDBLOCK:
  +            return "WSAEWOULDBLOCK: The socket is marked as nonblocking and the requested operation would block.";
  +        case WSAEMSGSIZE:
  +            return "WSAEMSGSIZE: The socket is message oriented, and the message is larger than the maximum supported by the underlying transport.";
  +        case WSAEHOSTUNREACH:
  +            return "WSAEHOSTUNREACH: The remote host cannot be reached from this host at this time.";
  +        case WSAEINVAL:
  +            return "WSAEINVAL: The socket has not been bound with bind, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled.";
  +        case WSAECONNABORTED:
  +            return "WSAECONNABORTED: The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable.";
  +        case WSAECONNRESET:
  +            return "WSAECONNRESET: The virtual circuit was reset by the remote side executing a hard or abortive close. For UPD sockets, the remote host was unable to deliver a previously sent UDP datagram and responded with a Port Unreachable ICMP packet. The application should close the socket as it is no longer usable.";
  +        case WSAETIMEDOUT:
  +            return "WSAETIMEDOUT: The connection has been dropped, because of a network failure or because the system on the other end went down without notice.";
  +        default:
  +            return "Unknown WSA error!";
  +
   }
   
   #endif
  
  
  
  1.3       +4 -4      spread/daemon/auth-pword-client.c
  
  Index: auth-pword-client.c
  ===================================================================
  RCS file: /storage/cvsroot/spread/daemon/auth-pword-client.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- auth-pword-client.c	3 Feb 2002 21:08:48 -0000	1.2
  +++ auth-pword-client.c	5 Feb 2002 02:37:39 -0000	1.3
  @@ -65,18 +65,18 @@
       user_p = data_p;
   
       /* Send username and password */
  -    while(((ret = send( fd, user_p->username, MAX_PWORD_USERNAME, 0 )) == -1) && ((errno == EINTR) || (errno == EAGAIN)))
  +    while(((ret = send( fd, user_p->username, MAX_PWORD_USERNAME, 0 )) == -1) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)))
           ;
       if( ret != (MAX_PWORD_USERNAME) )
       {
  -        printf("pword_authenticate: unable to send username %d %d: %s\n", ret, MAX_PWORD_USERNAME, strerror(errno));
  +        printf("pword_authenticate: unable to send username %d %d: %s\n", ret, MAX_PWORD_USERNAME, sock_strerror(sock_errno));
           return( 0 );
       }
  -    while(((ret = send( fd, user_p->password, MAX_PWORD_PASSWORD, 0 )) == -1) && ((errno == EINTR) || (errno == EAGAIN)))
  +    while(((ret = send( fd, user_p->password, MAX_PWORD_PASSWORD, 0 )) == -1) && ((errno == EINTR) || (errno == EAGAIN) || (sock_errno == EWOULDBLOCK)))
           ;
       if( ret != (MAX_PWORD_PASSWORD) )
       {
  -        printf("pword_authenticate: unable to send password %d %d: %s\n", ret, MAX_PWORD_PASSWORD, strerror(errno));
  +        printf("pword_authenticate: unable to send password %d %d: %s\n", ret, MAX_PWORD_PASSWORD, sock_strerror(sock_errno));
           return( 0 );
       }
   
  
  
  
  1.5       +2 -2      spread/daemon/data_link.c
  
  Index: data_link.c
  ===================================================================
  RCS file: /storage/cvsroot/spread/daemon/data_link.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- data_link.c	16 Oct 2001 15:58:42 -0000	1.4
  +++ data_link.c	5 Feb 2002 02:37:39 -0000	1.5
  @@ -45,13 +45,13 @@
   #include        <sys/time.h>
   #include        <unistd.h>
   
  +#include        <errno.h>
   #else	/* ARCH_PC_WIN95 */
   
   #include	<winsock.h>
   
   #endif	/* ARCH_PC_WIN95 */
   
  -#include <errno.h>
   #include <string.h>
   #include <assert.h>
   #include "data_link.h"
  @@ -220,7 +220,7 @@
   #endif	/* ARCH_SCATTER_NONE */
   		if(ret < 0) {
   			/* delay for a short while */
  -                        send_errormsg = strerror(errno);
  +                        send_errormsg = sock_strerror(sock_errno);
   			Alarm( DATA_LINK, "DL_send: delaying after failure in send to %d.%d.%d.%d, ret is %d\n", 
   				IP1(address), IP2(address), IP3(address), IP4(address), ret);
   			select( 0, 0, 0, 0, (struct timeval *)&select_delay );
  
  
  
  1.7       +6 -6      spread/daemon/session.c
  
  Index: session.c
  ===================================================================
  RCS file: /storage/cvsroot/spread/daemon/session.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- session.c	3 Feb 2002 19:28:10 -0000	1.6
  +++ session.c	5 Feb 2002 02:37:39 -0000	1.7
  @@ -36,11 +36,11 @@
   #include <string.h>
   #include <stdlib.h>
   #include <stdio.h>
  -#include <errno.h>
   #include <assert.h>
   
   #ifndef ARCH_PC_WIN95
   
  +#include <errno.h>
   #include <unistd.h>
   #include <sys/types.h>
   #include <sys/socket.h>
  @@ -582,7 +582,7 @@
                   on = 1;
                   ret = setsockopt( Sessions[MAX_SESSIONS].mbox, IPPROTO_TCP, TCP_NODELAY, (void *)&on, 4);
                   if (ret < 0) 
  -                        Alarm(PRINT, "Setting TCP_NODELAY failed with  error: %s\n", strerror(errno));
  +                        Alarm(PRINT, "Setting TCP_NODELAY failed with  error: %s\n", sock_strerror(sock_errno));
                   else
                           Alarm( SESSION, "Setting TCP_NODELAY on socket %d\n", Sessions[MAX_SESSIONS].mbox );
           }
  @@ -1200,12 +1200,12 @@
                           return;
                   } else {
                           /* error reading */
  -                        if ( (errno == EINTR) || (errno == EAGAIN) || (errno == EWOULDBLOCK) ) {
  +                        if ( (ret == -1) && ( (sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK) ) ) {
                                   ioctl_cmd = 0;
                                   ioctl( Sessions[ses].mbox, FIONBIO, &ioctl_cmd);        
                                   return;
                           }
  -                        Alarm( SESSION, "Sess_read: failed receiving header on session %d: ret %d: error: %s \n", mbox, ret, strerror(errno) );
  +                        Alarm( SESSION, "Sess_read: failed receiving header on session %d: ret %d: error: %s \n", mbox, ret, sock_strerror(sock_errno) );
                           Sess_kill( mbox );
                           ioctl_cmd = 0;
                           ioctl( Sessions[ses].mbox, FIONBIO, &ioctl_cmd);        
  @@ -1285,12 +1285,12 @@
                           ioctl( Sessions[ses].mbox, FIONBIO, &ioctl_cmd);        
                           return;
                   } else {
  -                        if ( (errno == EINTR) || (errno == EAGAIN) || (errno == EWOULDBLOCK) ) {
  +                        if ( (ret == -1) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) ) {
                                   ioctl_cmd = 0;
                                   ioctl( Sessions[ses].mbox, FIONBIO, &ioctl_cmd);        
                                   return;
                           }
  -			Alarm( SESSION, "Sess_read: failed receiving message on session %d, ret is %d: error: %s\n", mbox, ret, strerror(errno) );
  +			Alarm( SESSION, "Sess_read: failed receiving message on session %d, ret is %d: error: %s\n", mbox, ret, sock_strerror(sock_errno) );
   			Alarm( SESSION, "Sess_read: failed recv msg more info: len read: %d, remain: %d, to_read: %d, pkt_index: %d, b_index: %d, scat_nums: %d\n",Sessions[ses].read.total_bytes, remain, to_read, packet_index, byte_index, scat->num_elements );
   			Sess_kill( mbox );
                           ioctl_cmd = 0;
  
  
  
  1.3       +52 -52    spread/daemon/sp.c
  
  Index: sp.c
  ===================================================================
  RCS file: /storage/cvsroot/spread/daemon/sp.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- sp.c	22 Aug 2001 17:44:24 -0000	1.2
  +++ sp.c	5 Feb 2002 02:37:39 -0000	1.3
  @@ -33,12 +33,12 @@
   
   #include "arch.h"
   #include <string.h>
  -#include <errno.h>
   #include <stdio.h>
   #include "mutex.h"
   
   #ifndef	ARCH_PC_WIN95
   
  +#include <errno.h>
   #include <sys/time.h>
   #include <sys/types.h>
   #include <sys/socket.h>
  @@ -192,25 +192,25 @@
                   FD_ZERO(&fixed_rset);
                   FD_SET(s, &fixed_rset);
                   rset = fixed_rset;
  -                while( ((num_ready = select(s+1, &rset, NULL, NULL, (struct timeval *)&wait_time)) == -1) && ((errno == EINTR) || (errno == EAGAIN)) )
  +                while( ((num_ready = select(s+1, &rset, NULL, NULL, (struct timeval *)&wait_time)) == -1) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                   {
                           temp_time = E_get_time();
                           if (E_compare_time(temp_time, target_time) < 0 ) {
                                   wait_time = E_sub_time(target_time, temp_time);
                           } else {
                                   printf("recv_nointr_timeout: Timed out when interrupted\n");
  -                                errno = ERR_TIMEDOUT;
  +                                sock_set_errno( ERR_TIMEDOUT );
                                   return(-1);
                           }
                           rset = fixed_rset;
                   }
                   if ( !num_ready ) {
                           printf("recv_nointr_timeout: Timed out\n");
  -                        errno = ERR_TIMEDOUT;
  +                        sock_set_errno( ERR_TIMEDOUT );
                           return(-1);
                   } 
           }
  -        while( ((ret = recv( s, buf, len, flags)) == -1) && ((errno == EINTR) || (errno == EAGAIN)) )
  +        while( ((ret = recv( s, buf, len, flags)) == -1) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                   ;
           if ( E_compare_time(Zero_timeout, *time_out) < 0 )
           {
  @@ -460,7 +460,7 @@
                   on = 1;
                   ret = setsockopt( s, IPPROTO_TCP, TCP_NODELAY, (void *)&on, 4);
                   if (ret < 0) 
  -                        Alarm(PRINT, "Setting TCP_NODELAY failed with  error: %s\n", strerror(errno));
  +                        Alarm(PRINT, "Setting TCP_NODELAY failed with  error: %s\n", sock_strerror(sock_errno));
                   else 
                           Alarm( SESSION, "SP_connect: set TCP_NODELAY for socket %d\n", s);
   
  @@ -472,7 +472,7 @@
                    * done more then once. The while is so we can use 'break' 
                    */
   		while( ((ret = connect( s, (struct sockaddr *)&inet_addr, sizeof(inet_addr) ) ) == -1) 
  -                       && ((errno == EINTR) || (errno == EAGAIN)))
  +                       && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                   {
                           fd_set  rset, wset;
                           sp_time tout;
  @@ -490,13 +490,13 @@
                           {
                                   /* timeout */
                                   close(s);
  -                                errno = ERR_TIMEDOUT;
  +                                sock_set_errno( ERR_TIMEDOUT );
                                   ret = -1;
                                   break;
                           }
                           if (err < 0)
                           {
  -                                Alarm( SESSION, "SP_connect: connect interrupted and error in select wait: %s\n", strerror(errno));
  +                                Alarm( SESSION, "SP_connect: connect interrupted and error in select wait: %s\n", sock_strerror(sock_errno));
                                   ret = -1;
                                   break;
                           }
  @@ -510,14 +510,14 @@
                                   }
                                   if (err)
                                   {
  -                                        errno = err;
  +                                        sock_set_errno( err );
                                           ret = -1;
                                   } else {
                                           ret = 0;
                                   }
                                   break;
                           } else {
  -                                Alarm( SESSION, "SP_connect: connect interrupted--but socket not selected ret= %d: %s\n", err, strerror(errno));
  +                                Alarm( SESSION, "SP_connect: connect interrupted--but socket not selected ret= %d: %s\n", err, sock_strerror(sock_errno));
                                   ret = -1;
                                   break;
                           }
  @@ -559,7 +559,7 @@
   		unix_addr.sun_family = AF_UNIX;
   		sprintf( unix_addr.sun_path, "/tmp/%d", port );
   		while( ((ret = connect( s, (struct sockaddr *)&unix_addr, sizeof(unix_addr) )) == -1)
  -                       && ((errno == EINTR) || (errno == EAGAIN)) )
  +                       && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                   {
                           fd_set  rset, wset;
                           sp_time tout;
  @@ -576,13 +576,13 @@
                           {
                                   /* timeout */
                                   close(s);
  -                                errno = ETIMEDOUT;
  +                                sock_set_errno( ETIMEDOUT );
                                   ret = -1;
                                   break;
                           }
                           if (err < 0)
                           {
  -                                Alarm( SESSION, "SP_connect: uniz connect interrupted and error in select wait: %s\n", strerror(errno));
  +                                Alarm( SESSION, "SP_connect: uniz connect interrupted and error in select wait: %s\n", sock_strerror(sock_errno));
                                   ret = -1;
                                   break;
                           }
  @@ -596,7 +596,7 @@
                                   }
                                   if (err)
                                   {
  -                                        errno = err;
  +                                        sock_set_errno( err );
                                           ret = -1;
                                   } else {
                                           ret = 0;
  @@ -604,7 +604,7 @@
                                   break;
                           } else {
                                   Alarm( SESSION, "SP_connect: unix connect interrupted--but socket not selected ret= %d: %s\n",
  -                                       err, strerror(errno));
  +                                       err, sock_strerror(sock_errno));
                                   ret = -1;
                                   break;
                           }
  @@ -614,7 +614,7 @@
   	}
   	if( ret < 0 )
   	{
  -		Alarm( SESSION, "SP_connect: unable to connect mailbox %d: %s\n", s, strerror(errno));
  +		Alarm( SESSION, "SP_connect: unable to connect mailbox %d: %s\n", s, sock_strerror(sock_errno));
   		close( s );
   		return( COULD_NOT_CONNECT );
   	}
  @@ -648,11 +648,11 @@
                   memcpy( &conn[5], private_name, len );
           }
   	conn[4] = len;
  -	while(((ret = send( s, conn, len+5, 0 )) == -1) && ((errno == EINTR) || (errno == EAGAIN)))
  +	while(((ret = send( s, conn, len+5, 0 )) == -1) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                   ;
   	if( ret != len+5 )
   	{
  -		Alarm( SESSION, "SP_connect: unable to send name %d %d: %s\n", ret, len+5, strerror(errno));
  +		Alarm( SESSION, "SP_connect: unable to send name %d %d: %s\n", ret, len+5, sock_strerror(sock_errno));
   		close( s );
   		return( CONNECTION_CLOSED );
   	}
  @@ -661,13 +661,13 @@
           ret = recv_nointr_timeout( s, &auth_list_len, 1, 0, &time_out); 
           if ( ret <= 0 )
           {
  -		Alarm( SESSION, "SP_connect: unable to read auth_list_len %d: %s\n", ret, strerror(errno));
  +		Alarm( SESSION, "SP_connect: unable to read auth_list_len %d: %s\n", ret, sock_strerror(sock_errno));
   		close( s );
   		return( CONNECTION_CLOSED );
           }
           if ( auth_list_len > (MAX_AUTH_NAME * MAX_AUTH_METHODS) )
           {
  -		Alarm( SESSION, "SP_connect: illegal value in auth_list_len %d: %s\n", auth_list_len, strerror(errno));
  +		Alarm( SESSION, "SP_connect: illegal value in auth_list_len %d: %s\n", auth_list_len, sock_strerror(sock_errno));
   		close( s );
   		return( CONNECTION_CLOSED );
           } 
  @@ -682,7 +682,7 @@
                   ret = recv_nointr_timeout( s, auth_list, auth_list_len, 0, &time_out);
                   if ( ret <= 0 )
                   {
  -                        Alarm( SESSION, "SP_connect: unable to read auth_list %d: %s\n", ret, strerror(errno));
  +                        Alarm( SESSION, "SP_connect: unable to read auth_list %d: %s\n", ret, sock_strerror(sock_errno));
                           close( s );
                           return( CONNECTION_CLOSED );
                   }
  @@ -716,11 +716,11 @@
                           return( REJECT_AUTH );
                   }
           }
  -	while(((ret = send( s, auth_choice, MAX_AUTH_NAME * MAX_AUTH_METHODS, 0 )) == -1) && ((errno == EINTR) || (errno == EAGAIN)))
  +	while(((ret = send( s, auth_choice, MAX_AUTH_NAME * MAX_AUTH_METHODS, 0 )) == -1) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                   ;
   	if( ret != (MAX_AUTH_NAME * MAX_AUTH_METHODS) )
   	{
  -		Alarm( SESSION, "SP_connect: unable to send auth_name %d %d: %s\n", ret, MAX_AUTH_NAME * MAX_AUTH_METHODS, strerror(errno));
  +		Alarm( SESSION, "SP_connect: unable to send auth_name %d %d: %s\n", ret, MAX_AUTH_NAME * MAX_AUTH_METHODS, sock_strerror(sock_errno));
   		close( s );
   		return( CONNECTION_CLOSED );
   	}
  @@ -751,12 +751,12 @@
   	l=0;
           ret = recv_nointr_timeout( s, &l, 1, 0, &time_out);
   #if 0
  -	while(((ret = recv( s, &l, 1, 0)) == -1) && ((errno == EINTR) || (errno == EAGAIN)))
  +	while(((ret = recv( s, &l, 1, 0)) == -1) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                   ;
   #endif
   	if( ret <= 0 )
   	{
  -		Alarm( SESSION, "SP_connect: unable to read answer %d: %s\n", ret, strerror(errno));
  +		Alarm( SESSION, "SP_connect: unable to read answer %d: %s\n", ret, sock_strerror(sock_errno));
   		close( s );
   		return( CONNECTION_CLOSED );
   	}
  @@ -768,12 +768,12 @@
   	}
           ret = recv_nointr_timeout( s, &l, 1, 0, &time_out);
   #if 0
  -	while(((ret = recv( s, &l, 1, 0)) == -1 ) && ((errno == EINTR) || (errno == EAGAIN)) )
  +	while(((ret = recv( s, &l, 1, 0)) == -1) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                   ;
   #endif
   	if( ret <= 0 )
   	{
  -		Alarm( SESSION, "SP_connect: unable to read version %d: %s\n", ret, strerror(errno));
  +		Alarm( SESSION, "SP_connect: unable to read version %d: %s\n", ret, sock_strerror(sock_errno));
   		close( s );
   		return( CONNECTION_CLOSED );
   	}
  @@ -781,12 +781,12 @@
   
           ret = recv_nointr_timeout( s, &l, 1, 0, &time_out);
   #if 0
  -	while(((ret = recv( s, &l, 1, 0)) == -1 ) && ((errno == EINTR) || (errno == EAGAIN)) )
  +	while(((ret = recv( s, &l, 1, 0)) == -1) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                   ;
   #endif
   	if( ret <= 0 )
   	{
  -		Alarm( SESSION, "SP_connect: unable to read subversion %d: %s\n", ret, strerror(errno));
  +		Alarm( SESSION, "SP_connect: unable to read subversion %d: %s\n", ret, sock_strerror(sock_errno));
   		close( s );
   		return( CONNECTION_CLOSED );
   	}
  @@ -794,12 +794,12 @@
   
           ret = recv_nointr_timeout( s, &l, 1, 0, &time_out);
   #if 0
  -	while(((ret = recv( s, &l, 1, 0)) == -1 ) && ((errno == EINTR) || (errno == EAGAIN)) )
  +	while(((ret = recv( s, &l, 1, 0)) == -1) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                   ;
   #endif
   	if( ret <= 0 )
   	{
  -		Alarm( SESSION, "SP_connect: unable to read patch version %d: %s\n", ret, strerror(errno));
  +		Alarm( SESSION, "SP_connect: unable to read patch version %d: %s\n", ret, sock_strerror(sock_errno));
   		close( s );
   		return( CONNECTION_CLOSED );
   	}
  @@ -823,24 +823,24 @@
   
           ret = recv_nointr_timeout( s, &l, 1, 0, &time_out);
   #if 0
  -	while(((ret = recv( s, &l, 1, 0)) == -1 ) && ((errno == EINTR) || (errno == EAGAIN)) )
  +	while(((ret = recv( s, &l, 1, 0)) == -1) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                   ;
   #endif
   	if( ret <= 0 )
   	{
  -		Alarm( SESSION, "SP_connect: unable to read size of group %d: %s\n", ret, strerror(errno));
  +		Alarm( SESSION, "SP_connect: unable to read size of group %d: %s\n", ret, sock_strerror(sock_errno));
                   close( s );
   		return( CONNECTION_CLOSED );
   	}
   	len = l;
           ret = recv_nointr_timeout( s, private_group, len, 0, &time_out);
   #if 0
  -	while(((ret = recv( s, private_group, len, 0 )) == -1 ) && ((errno == EINTR) || (errno == EAGAIN)) )
  +	while(((ret = recv( s, private_group, len, 0 )) == -1 ) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                   ;
   #endif
   	if( ret <= 0 )
   	{
  -		Alarm( SESSION, "SP_connect: unable to read private group %d:  %s\n", ret, strerror(errno));
  +		Alarm( SESSION, "SP_connect: unable to read private group %d:  %s\n", ret, sock_strerror(sock_errno));
   		close( s );
   		return( CONNECTION_CLOSED );
   	}
  @@ -1055,11 +1055,11 @@
   
   	Mutex_lock( &Mbox_mutex[mbox&MAX_MUTEX_MASK][0] );
   	while(((ret=send( mbox, head_buf, sizeof(message_header)+MAX_GROUP_NAME*num_groups, 0 )) == -1) 
  -              && ((errno == EINTR) || (errno == EAGAIN)) )
  +              && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                   ;
   	if( ret <=0 )
   	{
  -		Alarm( SESSION, "SP_internal_multicast: error %d sending header and groups on mailbox %d: %s \n", ret, mbox, strerror(errno));
  +		Alarm( SESSION, "SP_internal_multicast: error %d sending header and groups on mailbox %d: %s \n", ret, mbox, sock_strerror(sock_errno));
   		Mutex_unlock( &Mbox_mutex[mbox&MAX_MUTEX_MASK][0] );
   		SP_kill( mbox );
   		return( CONNECTION_CLOSED );
  @@ -1067,11 +1067,11 @@
   	for( len=0, i=0; i < scat_mess->num_elements; len+=ret, i++ )
   	{
   		while(((ret=send( mbox, scat_mess->elements[i].buf, scat_mess->elements[i].len, 0 )) == -1)
  -                      && ((errno == EINTR) || (errno == EAGAIN)) )
  +                      && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                           ;
   		if( ret < 0 )
   		{
  -			Alarm( SESSION, "SP_internal_multicast: error %d sending message data on mailbox %d: %s \n", ret, mbox, strerror(errno));
  +			Alarm( SESSION, "SP_internal_multicast: error %d sending message data on mailbox %d: %s \n", ret, mbox, sock_strerror(sock_errno));
   			Mutex_unlock( &Mbox_mutex[mbox&MAX_MUTEX_MASK][0] );
   			SP_kill( mbox );
   			return( CONNECTION_CLOSED );
  @@ -1168,11 +1168,11 @@
                   for( len=0, remain = sizeof(message_header); remain > 0;  len += ret, remain -= ret )
                   {
                           while(((ret = recv( mbox, &buf_ptr[len], remain, 0 )) == -1 )
  -                              && ((errno == EINTR) || (errno == EAGAIN)) )
  +                              && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                                   ;
                           if( ret <=0 )
                           {
  -                                Alarm( SESSION, "SP_scat_receive: failed receiving header on session %d (ret: %d len: %d): %s\n", mbox, ret, len, strerror(errno) );
  +                                Alarm( SESSION, "SP_scat_receive: failed receiving header on session %d (ret: %d len: %d): %s\n", mbox, ret, len, sock_strerror(sock_errno) );
                                   Mutex_unlock( &Mbox_mutex[mbox & MAX_MUTEX_MASK][1] );
   
                                   SP_kill( mbox );
  @@ -1270,11 +1270,11 @@
                   buf_ptr = (char *)&old_type;
                   for( len=0; remain > 0; len += ret, remain -= ret )
                   {
  -                        while(((ret = recv( mbox, &buf_ptr[len], remain, 0 )) == -1 ) && ((errno == EINTR) || (errno == EAGAIN)) )
  +                        while(((ret = recv( mbox, &buf_ptr[len], remain, 0 )) == -1 ) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                                   ;
                           if( ret <=0 )
                           {
  -                                Alarm( SESSION, "SP_scat_receive: failed receiving old_type for reject on session %d, ret is %d: %s\n", mbox, ret, strerror(errno));
  +                                Alarm( SESSION, "SP_scat_receive: failed receiving old_type for reject on session %d, ret is %d: %s\n", mbox, ret, sock_strerror(sock_errno));
                                   Mutex_unlock( &Mbox_mutex[mbox & MAX_MUTEX_MASK][1] );
                                   SP_kill( mbox );
                                   return( CONNECTION_CLOSED );
  @@ -1299,11 +1299,11 @@
   
   	for( len=0; remain > 0; len += ret, remain -= ret )
   	{
  -		while(((ret = recv( mbox, &buf_ptr[len], remain, 0 )) == -1 ) && ((errno == EINTR) || (errno == EAGAIN)) )
  +		while(((ret = recv( mbox, &buf_ptr[len], remain, 0 )) == -1 ) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                           ;
   		if( ret <=0 )
   		{
  -			Alarm( SESSION, "SP_scat_receive: failed receiving groups on session %d, ret is %d: %s\n", mbox, ret, strerror(errno));
  +			Alarm( SESSION, "SP_scat_receive: failed receiving groups on session %d, ret is %d: %s\n", mbox, ret, sock_strerror(sock_errno));
   			Mutex_unlock( &Mbox_mutex[mbox & MAX_MUTEX_MASK][1] );
   
   			SP_kill( mbox );
  @@ -1318,12 +1318,12 @@
   		{
   			to_read = remain;
   			if( to_read > sizeof( dummy_buf ) ) to_read = sizeof( dummy_buf );
  -			while(((ret = recv( mbox, dummy_buf, to_read, 0 )) == -1 ) && ((errno == EINTR) || (errno == EAGAIN)) )
  +			while(((ret = recv( mbox, dummy_buf, to_read, 0 )) == -1 ) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                                   ;
   			if( ret <=0 )
   			{
   				Alarm( SESSION, "SP_scat_receive: failed receiving groups overflow on session %d, ret is %d: %s\n", 
  -                                       mbox, ret, strerror(errno) );
  +                                       mbox, ret, sock_strerror(sock_errno) );
   				Mutex_unlock( &Mbox_mutex[mbox & MAX_MUTEX_MASK][1] );
   				SP_kill( mbox );
   				return( CONNECTION_CLOSED );
  @@ -1371,12 +1371,12 @@
   		to_read = scat_mess->elements[scat_index].len - byte_index;
   		if( to_read > remain ) to_read = remain;
   		while(((ret = recv( mbox, &scat_mess->elements[scat_index].buf[byte_index], to_read, 0 )) == -1 )
  -                      && ((errno == EINTR) || (errno == EAGAIN)) )
  +                      && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                           ;
   		if( ret <=0 )
   		{
   			Alarm( SESSION, "SP_scat_receive: failed receiving message on session %d, ret is %d: %s\n", 
  -                               mbox, ret, strerror(errno) );
  +                               mbox, ret, sock_strerror(sock_errno) );
   			Mutex_unlock( &Mbox_mutex[mbox & MAX_MUTEX_MASK][1] );
   			SP_kill( mbox );
   			return( CONNECTION_CLOSED );
  @@ -1451,12 +1451,12 @@
   		{
   			to_read = remain;
   			if( to_read > sizeof( dummy_buf ) ) to_read = sizeof( dummy_buf );
  -			while(((ret = recv( mbox, dummy_buf, to_read, 0 )) == -1 ) && ((errno == EINTR) || (errno == EAGAIN)) )
  +			while(((ret = recv( mbox, dummy_buf, to_read, 0 )) == -1 ) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                                   ;
   			if( ret <=0 )
   			{
   				Alarm( SESSION, "SP_scat_receive: failed receiving overflow on session %d, ret is %d: %s\n", 
  -                                       mbox, ret, strerror(errno) );
  +                                       mbox, ret, sock_strerror(sock_errno) );
   				Mutex_unlock( &Mbox_mutex[mbox & MAX_MUTEX_MASK][1] );
   				SP_kill( mbox );
   				return( CONNECTION_CLOSED );
  
  
  





More information about the Spread-cvs mailing list