ftp.nice.ch/Attic/openStep/implementation/gnustep/sources/alpha-snapshots/pthreads.0.9.2.tgz#/pthreads-0.9.2/socklib/sendto.c

This is sendto.c in view mode; [Download] [Up]

#include <unistd.h>
#include "pthread_socket.h"
#include "pthread_io_delay.h"

extern void fd_init( void );
extern pthread_once_t io_initialized; 

static inline
_syscall2(long,socketcall,int,call,unsigned long *,args); 

static int
syscall_sendto(int fd, 
               const void *msg, 
               int len, 
               unsigned int flags,
               const struct sockaddr *to,
               int tolen )
{
   unsigned long args[6];
   int ret;

   args[0] = (unsigned long) fd;
   args[1] = (unsigned long) msg;
   args[2] = (unsigned long) len;
   args[3] = (unsigned long) flags;
   args[4] = (unsigned long) to;
   args[5] = (unsigned long) tolen;

   LOCK_ON

       ret = socketcall( SYS_SENDTO, args );

   LOCK_OFF

   return( ret );
}

/*--------------------------------------------------------------------------
 * @@          S E N D T O
 *-------------------------------------------------------------------------*/
int 
sendto( int fd, 
        const void *msg, 
        int len, 
        unsigned int flags,
        const struct sockaddr *to,
        int tolen )
{
   int ret, err, st;

   st = pthread_once( &io_initialized, fd_init );
   if( st != SUCCESS )
       return( NOTOK ); 

   if( nonblock_is_set( fd ))
   {
       ret = syscall_sendto( fd, msg, len, flags, to, tolen );
       RETURN( ret );
   }

   set_fd_nonblock( fd );
   while( (ret = syscall_sendto( fd, msg, len, flags, to, tolen )) < OK ) 
   {
       (void) pthread_get_errno_np( NULL, &err );
       if( err != EWOULDBLOCK ) 
           break;

       pthread_delay_np( &delay_interval );
   }

   clear_fd_nonblock( fd );
   return( ret );
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.