<NONE>

Sonya Rikhtverchik (rikhtver@OpenMarket.com)
Wed, 09 Jul 1997 10:50:39 -0400

Message-Id: <199707091450.KAA02321@u4-138.openmarket.com>
To: fastcgi-developers@OpenMarket.com
Date: Wed, 09 Jul 1997 10:50:39 -0400
From: Sonya Rikhtverchik <rikhtver@OpenMarket.com>
Subject: <NONE>


------- Forwarded Message

Received: (from majordom@localhost) by relay.openmarket.com (8.6.10/8.6.6) id 
MAA11718; Mon, 7 Jul 1997 12:20:47 -0400
Date: Mon, 7 Jul 1997 12:20:47 -0400
From: owner-fastcgi-developers@OpenMarket.com
Message-Id: <199707071620.MAA11718@relay.openmarket.com>
To: owner-fastcgi-developers@OpenMarket.com
Subject: BOUNCE fastcgi-developers@OpenMarket.com:   According to Jonathan Roy:
  

>From rikhtver@OpenMarket.com  Mon Jul  7 12:20:39 1997
Received: from relay1.UU.NET (relay1.UU.NET [192.48.96.5]) by 
relay.openmarket.com (8.6.10/8.6.6) with ESMTP id MAA11679 for 
<fastcgi-developers@OpenMarket.com>; Mon, 7 Jul 1997 12:20:38 -0400
Received: from berlin.atlantic.net by relay1.UU.NET with ESMTP 
	(peer crosschecked as: berlin.atlantic.net [204.215.255.12])
	id QQcxeg00440; Mon, 7 Jul 1997 10:37:51 -0400 (EDT)
Received: from rio.atlantic.net (chip@rio.atlantic.net [204.215.255.3]) by 
berlin.atlantic.net (8.8.6/8.8.5) with ESMTP id KAA02977; Mon, 7 Jul 1997 
10:51:52 -0400
Received: (from chip@localhost) by rio.atlantic.net (8.8.6/8.8.5) id KAA03328; 
Mon, 7 Jul 1997 10:37:39 -0400
From: Chip Salzenberg <chip@rio.atlantic.net>
Message-Id: <199707071437.KAA03328@rio.atlantic.net>
Subject: Solaris patch for FCGI-0.30
To: roy@atlantic.net (Jonathan Roy)
Date: Mon, 7 Jul 1997 10:37:39 -0400 (EDT)
Cc: zoot@jobtrak.com, nb@jobtrak.com, fastcgi-developers@OpenMarket.com
Reply-To: chip@pobox.com
In-Reply-To: <3.0.1.32.19970707094333.006a0a58@mail.atlantic.net> from 
"Jonathan Roy" at Jul 7, 97 09:43:33 am
Content-Type: text

According to Jonathan Roy:
> At 09:13 PM 7/6/97 -0700, suit wrote:
> >i couldn't find the solaris accept() patch on the mailing-list archive
> >on the fastcgi.com web site.  did it get lost?  their archiving doesn't seem
> >very complete - the last message is from June17th.
> 
>   I can't seem to find them.

Mea culpa.  After I created the patch for FCGI-0.30, I wanted to leave
it running for a while, and then I forgot about it.  :(  Here it is.

Index: os_unix.c
*************** static int numWrPosted = 0;
*** 112,115 ****
- --- 112,186 ----
  static int volatile maxFd = -1;
  
+ 
+ /*
+  *----------------------------------------------------------------------
+  *
+  * AcquireLock --
+  *
+  *      On platforms that implement concurrent calls to accept
+  *      on a shared listening socket, returns 0.  On other platforms,
+  *      acquires an exclusive lock across all processes sharing a
+  *      listening socket.  If "blocking" parameter is true, blocks
+  *      until the lock has been acquired, otherwise does not.
+  *
+  * Results:
+  *      0 for successful call, -1 in case of system error.
+  *
+  * Side effects:
+  *      This process now has the exclusive lock.
+  *
+  *----------------------------------------------------------------------
+  */
+ static int AcquireLock(int blocking)
+ {
+ #ifdef USE_LOCKING
+     struct flock lock;
+     lock.l_type = F_WRLCK;
+     lock.l_start = 0;
+     lock.l_whence = SEEK_SET;
+     lock.l_len = 0;
+ 
+     while (fcntl(FCGI_LISTENSOCK_FILENO,
+                  blocking ? F_SETLKW : F_SETLK, &lock) < 0) {
+         if (errno != EINTR)
+             return -1;
+     }
+ #endif /* USE_LOCKING */
+     return 0;
+ }
+ 
+ /*
+  *----------------------------------------------------------------------
+  *
+  * ReleaseLock --
+  *
+  *      On platforms that implement concurrent calls to accept
+  *      on a shared listening socket, does nothing.  On other platforms,
+  *	releases an exclusive lock acquired by AcquireLock.
+  *
+  * Results:
+  *      0 for successful call, -1 in case of system error (fatal).
+  *
+  * Side effects:
+  *      This process no longer holds the lock.
+  *
+  *----------------------------------------------------------------------
+  */
+ static int ReleaseLock(void)
+ {
+ #ifdef USE_LOCKING
+     struct flock lock;
+     lock.l_type = F_UNLCK;
+     lock.l_start = 0;
+     lock.l_whence = SEEK_SET;
+     lock.l_len = 0;
+ 
+     if(fcntl(FCGI_LISTENSOCK_FILENO, F_SETLK, &lock) < 0) {
+         return -1;
+     }
+ #endif /* USE_LOCKING */
+     return 0;
+ }
+ 
  /*
   * fcgiSocket will hold the socket file descriptor if the call to
*************** static int ClientAddrOK(struct sockaddr_
*** 888,960 ****
      return result;
  }
- - 
- - 
- - /*
- -  *----------------------------------------------------------------------
- -  *
- -  * AcquireLock --
- -  *
- -  *      On platforms that implement concurrent calls to accept
- -  *      on a shared listening ipcFd, returns 0.  On other platforms,
- -  *	acquires an exclusive lock across all processes sharing a
- -  *      listening ipcFd, blocking until the lock has been acquired.
- -  *
- -  * Results:
- -  *      0 for successful call, -1 in case of system error (fatal).
- -  *
- -  * Side effects:
- -  *      This process now has the exclusive lock.
- -  *
- -  *----------------------------------------------------------------------
- -  */
- - static int AcquireLock(void)
- - {
- - #ifdef USE_LOCKING
- -     struct flock lock;
- -     lock.l_type = F_WRLCK;
- -     lock.l_start = 0;
- -     lock.l_whence = SEEK_SET;
- -     lock.l_len = 0;
- - 
- -     if(fcntl(FCGI_LISTENSOCK_FILENO, F_SETLKW, &lock) < 0) {
- -         return -1;
- -     }
- - #endif /* USE_LOCKING */
- -     return 0;
- - }
- - 
- - /*
- -  *----------------------------------------------------------------------
- -  *
- -  * ReleaseLock --
- -  *
- -  *      On platforms that implement concurrent calls to accept
- -  *      on a shared listening ipcFd, does nothing.  On other platforms,
- -  *	releases an exclusive lock acquired by AcquireLock.
- -  *
- -  * Results:
- -  *      0 for successful call, -1 in case of system error (fatal).
- -  *
- -  * Side effects:
- -  *      This process no longer holds the lock.
- -  *
- -  *----------------------------------------------------------------------
- -  */
- - static int ReleaseLock(void)
- - {
- - #ifdef USE_LOCKING
- -     struct flock lock;
- -     lock.l_type = F_UNLCK;
- -     lock.l_start = 0;
- -     lock.l_whence = SEEK_SET;
- -     lock.l_len = 0;
- - 
- -     if(fcntl(FCGI_LISTENSOCK_FILENO, F_SETLK, &lock) < 0) {
- -         return -1;
- -     }
- - #endif /* USE_LOCKING */
- -     return 0;
- - }
- - 
  
  /*
- --- 959,962 ----
*************** int OS_FcgiIpcAccept(char *clientAddrLis
*** 984,988 ****
      
      for(;;) {
!         if(AcquireLock() < 0) {
  	    return -1;
  	}
- --- 986,990 ----
      
      for(;;) {
!         if(AcquireLock(TRUE) < 0) {
  	    return -1;
  	}
*************** int OS_IsFcgi()
*** 1068,1085 ****
      int flags, flags1 ;
    
- -     fcgiClilen = sizeof(fcgiSa);
- -     
      /*
!      * Put the file descriptor into non-blocking mode.
       */
!     flags = fcntl(FCGI_LISTENSOCK_FILENO, F_GETFL, 0);
!     flags |= O_NONBLOCK;
!     if( (fcntl(FCGI_LISTENSOCK_FILENO, F_SETFL, flags)) == -1 ) {
          /*
           * XXX: The reason for the assert is that this call is not
!          *      supposed to return an error unless the 
!          *      FCGI_LISTENSOCK_FILENO is closed.  If it is closed
!          *      then we have an unexpected error which should cause 
!          *      the assert to pop.  The same is true for the following
           *      asserts in this function.
           */
- --- 1070,1098 ----
      int flags, flags1 ;
    
      /*
!      * Lock the file descriptor.
       */
!     if(AcquireLock(FALSE) == -1) {
!         /*
!          * If errno == EWOULDBLOCK then this is a valid FastCGI listener 
!          * socket that is already locked because there's an accept() pending.
!          * NOTE: HP-UX can return EAGAIN; Irix can return EACCES.
!          */
!         if(errno == EWOULDBLOCK
! #if (EAGAIN != EWOULDBLOCK)
!            || errno == EAGAIN
! #endif
!            || errno == EACCES)
!         {
!             isFastCGI = TRUE;
!             return isFastCGI;
!         }
! 
          /*
           * XXX: The reason for the assert is that this call is not
!          *      supposed to return errors other than EWOULDBLOCK unless
!          *      the FCGI_LISTENSOCK_FILENO is closed.  If it is closed
!          *      then we have an unexpected error which should cause the
!          *      assert to pop.  The same is true for the following
           *      asserts in this function.
           */
*************** int OS_IsFcgi()
*** 1088,1097 ****
  
      /*
       * Perform an accept() on the file descriptor.  If this is not a
       * listener socket we will get an error.  Typically this will be
       * ENOTSOCK but it differs from platform to platform.
       */
!     fcgiSocket = accept(FCGI_LISTENSOCK_FILENO, (struct sockaddr *) 
&fcgiSa.un,
!                         &fcgiClilen);
      if(fcgiSocket >= 0) {
          /*
- --- 1101,1120 ----
  
      /*
+      * Put the file descriptor into non-blocking mode.
+      */
+     flags = fcntl(FCGI_LISTENSOCK_FILENO, F_GETFL, 0);
+     flags |= O_NONBLOCK;
+     if( (fcntl(FCGI_LISTENSOCK_FILENO, F_SETFL, flags)) == -1 ) {
+         assert(errno == 0);
+     }
+ 
+     /*
       * Perform an accept() on the file descriptor.  If this is not a
       * listener socket we will get an error.  Typically this will be
       * ENOTSOCK but it differs from platform to platform.
       */
!     fcgiClilen = sizeof(fcgiSa);
!     fcgiSocket = accept(FCGI_LISTENSOCK_FILENO,
!                         (struct sockaddr *) &fcgiSa.un, &fcgiClilen);
      if(fcgiSocket >= 0) {
          /*
*************** int OS_IsFcgi()
*** 1113,1125 ****
           * If errno == EWOULDBLOCK then this is a valid FastCGI listener 
           * socket without any connection pending at this time.
! 	 *
! 	 * NOTE: hp-ux can also return EAGAIN for listener sockets in
! 	 * non-blocking mode when no connections are present.
           */
  #if (EAGAIN != EWOULDBLOCK)
!         if((errno == EWOULDBLOCK) || (errno == EAGAIN)) {
! #else
!         if(errno == EWOULDBLOCK) {
  #endif
  	    isFastCGI = TRUE;
          } else {
- --- 1136,1147 ----
           * If errno == EWOULDBLOCK then this is a valid FastCGI listener 
           * socket without any connection pending at this time.
!          * NOTE: HP-UX can return EAGAIN; Irix can return EACCES.
           */
+         if(errno == EWOULDBLOCK
  #if (EAGAIN != EWOULDBLOCK)
!            || errno == EAGAIN
  #endif
+            || errno == EACCES)
+         {
  	    isFastCGI = TRUE;
          } else {
*************** int OS_IsFcgi()
*** 1135,1138 ****
- --- 1157,1166 ----
          assert(errno == 0);
      }
+ 
+     /*
+      * Unlock the file descriptor.
+      */
+     (void)ReleaseLock();
+ 
      return isFastCGI;
  }

- -- 
Chip Salzenberg         - a.k.a. -           <chip@pobox.com>
 (as character touches fingertips while hypnotizing a girl)
      "Here is the church; here is the steeple;
       now open the door and go - to - sleeple."  // MST3K

------- End of Forwarded Message