This is bind.c in view mode; [Download] [Up]
#include "pthread_socket.h" #include "pthread_io_delay.h" static inline _syscall2(long,socketcall,int,call,unsigned long *,args); static int syscall_bind( int fd, struct sockaddr *my_addr, int addrlen ) { unsigned long args[3]; args[0] = (unsigned long) fd; args[1] = (unsigned long) my_addr; args[2] = (unsigned long) addrlen; return( socketcall( SYS_BIND, args ) ); } /*-------------------------------------------------------------------------- * @@ B I N D *-------------------------------------------------------------------------*/ int bind( int fd, struct sockaddr *my_addr, int addrlen ) { int ret; int flags, blocking; flags = fcntl( fd, F_GETFL, 0 ); if( flags == NOTOK ) return( NOTOK ); /* * If the file was opened for normal, blocking I/O, we use fcntl() * to make it non-blocking so our thread can execute its delay poll(). * If, however, the caller has specified non-blocking, then she is * expecting an immediate return. Hence, execute the call only once. */ blocking = (flags & O_NONBLOCK); if( !blocking ) { if( fcntl(fd, F_SETFL, flags | O_NONBLOCK) < OK ) return( NOTOK ); } else { ret = syscall_bind( fd, my_addr, addrlen ); RETURN( ret ); } /* * Attempt the bind. */ while( (ret = syscall_bind( fd, my_addr, addrlen )) < OK ) { if( ret != -EWOULDBLOCK ) { SET_ERRNO(ret); ret = NOTOK; break; } pthread_delay_np( &delay_interval ); } if( !blocking ) { if( fcntl( fd, F_SETFL, flags ) < OK ) { pthread_set_errno_np( errno ); ret = NOTOK; } } return( ret ); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.