This is recvfrom.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;
/*
* Expand the _syscall2 macro into an inline function/
*/
static inline
_syscall2(long,socketcall,int,call,unsigned long *,args);
static int
syscall_recvfrom( int fd,
void *buf,
int len,
unsigned int flags,
struct sockaddr *from,
int *fromlen )
{
unsigned long args[6];
int ret;
args[0] = (unsigned long) fd;
args[1] = (unsigned long) buf;
args[2] = (unsigned long) len;
args[3] = (unsigned long) flags;
args[4] = (unsigned long) from;
args[5] = (unsigned long) fromlen;
LOCK_ON
ret = socketcall( SYS_RECVFROM, args );
LOCK_OFF
return( ret );
}
/*--------------------------------------------------------------------------
* @@ R E C V F R O M
*-------------------------------------------------------------------------*/
int
recvfrom( int fd,
void *buf,
int len,
unsigned int flags,
struct sockaddr *from,
int *fromlen )
{
int ret, err, st;
st = pthread_once( &io_initialized, fd_init );
if( st != SUCCESS )
return( FAILURE );
if( nonblock_is_set( fd ))
{
ret = syscall_recvfrom( fd, buf, len, flags, from, fromlen );
RETURN( ret );
}
set_fd_nonblock( fd );
while((ret = syscall_recvfrom( fd, buf, len, flags, from, fromlen )) < 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.