[comp.sys.apollo] Problem with nonblocking sockets under SR9.7

hucka@caen.engin.umich.edu (Michael Hucka) (07/31/89)

    I'm encountering a problem with sockets which I hope someone more
experienced can help me with.  My experience with sockets is limited, so this
problem may be due to my own error, but after spending hours in the debugger
watching this program, it really seems like a bug in DOMAIN/IX sockets.  It
concerns enabling/disabling blocking mode on sockets in the internet domain,
under SR 9.7.  I've written a small server-like program which creates a
socket and listens on a port for two connections.  The best arrangement for
this program is if it can selectively set the sockets non-blocking for part
of the time, and blocking at other times.

    The problem is that although it can create a socket, accept a connection
and then set the (new) socket non-blocking, trying to set it *back* to
blocking mode just doesn't seem to work.  I've tried both ioctl with FIONBIO
and fcntl with FNDELAY and neither of them seem to have any effect; they
return valid status but the socket ends up staying non-blocking.

    Here are code fragments for the two ways I've tried:

socket_blocking_mode(sock, mode)
int sock, mode;
{
     int flags;		

     flags = (mode ? 0 : 1); 

     if ( ioctl(sock, FIONBIO, &flags) < 0 ) 
	  error();
     else
          return;
}

--------------------- alternate ----------------------------

socket_blocking_mode(sock, mode)
int sock, mode;
{
     int flags;		
     
     /* Set the descriptor status flags to enable/disable blocking I/O.   
      * Note that doing the fcntl call in the form documented in the
      * Unix 4.3BSD Advanced IPC manual, i.e., fcntl(sock, F_SETFL, FNDELAY)
      * doesn't work at all; the third arg is apparently really a flag
      * and so we must first get its current value then bit-or/and with
      * the desired flag.
      */
     if ((flags = fcntl(sock, F_GETFL, 0)) < 0) 
	  error();

     if (mode)
	  flags |= FNDELAY;
     else
	  flags &= ~FNDELAY;

     if (fcntl(sock, F_SETFL, flags) < 0)
          error();
} 

---------------------------

   Can anyone offer suggetions as to what might be going on here?
I have not had the chance to try this under SR10.  Any help or suggestions
will be much appreciated.    

	  Mike Hucka
	  University of Michigan 

-- 
Mike Hucka
Computer Aided Engineering Network, Univ. of Michigan, Ann Arbor MI 48109
ARPA: hucka@caen.engin.umich.edu.
-----------------------------------------------------------------------------