sock.c File Reference

#include "nsd.h"

Defines

#define INADDR_NONE   -1

Functions

int Ns_SockRecv (SOCKET sock, void *buf, int toread, int timeout)
int Ns_SockSend (SOCKET sock, void *buf, int towrite, int timeout)
int Ns_SockWait (SOCKET sock, int what, int seconds)
int Ns_SockWaitEx (SOCKET sock, int what, int ms)
SOCKET Ns_SockListen (char *address, int port)
SOCKET Ns_SockListenEx (char *address, int port, int backlog)
SOCKET Ns_SockAccept (SOCKET lsock, struct sockaddr *saPtr, int *lenPtr)
SOCKET Ns_BindSock (struct sockaddr_in *saPtr)
SOCKET Ns_SockBind (struct sockaddr_in *saPtr)
SOCKET Ns_SockConnect (char *host, int port)
SOCKET Ns_SockConnect2 (char *host, int port, char *lhost, int lport)
SOCKET Ns_SockAsyncConnect (char *host, int port)
SOCKET Ns_SockAsyncConnect2 (char *host, int port, char *lhost, int lport)
SOCKET Ns_SockTimedConnect (char *host, int port, int timeout)
SOCKET Ns_SockTimedConnect2 (char *host, int port, char *lhost, int lport, int timeout)
int Ns_SockSetNonBlocking (SOCKET sock)
int Ns_SockSetBlocking (SOCKET sock)
int Ns_GetSockAddr (struct sockaddr_in *saPtr, char *host, int port)
int Ns_SockPipe (SOCKET socks[2])
int Ns_SockCloseLater (SOCKET sock)
void Ns_ClearSockErrno (void)
int Ns_GetSockErrno (void)
void Ns_SetSockErrno (int err)
char * Ns_SockStrError (int err)
int ns_poll (struct pollfd *fds, unsigned long int nfds, int timeout)
int NsPoll (struct pollfd *pfds, int nfds, Ns_Time *timeoutPtr)

Define Documentation

#define INADDR_NONE   -1


Function Documentation

SOCKET Ns_BindSock ( struct sockaddr_in *  saPtr  ) 

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

Ns_SockBind --

Create a TCP socket and bind it to the passed-in address.

Results: A socket or -1 on error.

Side effects: Will set SO_REUSEADDR on the socket.

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

void Ns_ClearSockErrno ( void   ) 

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

Ns_SockErrno --

Errno/GetLastError utility routines.

Results: See code.

Side effects: May set last error.

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

int Ns_GetSockAddr ( struct sockaddr_in *  saPtr,
char *  host,
int  port 
)

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

Ns_GetSockAddr --

Take a host/port and fill in a sockaddr_in structure appropriately. Host may be an IP address or a DNS name.

Results: NS_OK/NS_ERROR

Side effects: May perform DNS query.

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

int Ns_GetSockErrno ( void   ) 

int ns_poll ( struct pollfd fds,
unsigned long int  nfds,
int  timeout 
)

Poll the file descriptors described by the NFDS structures starting at FDS. If TIMEOUT is nonzero and not -1, allow TIMEOUT milliseconds for an event to occur; if TIMEOUT is -1, block until an event occurs. Returns the number of file descriptors with events, zero if timed out, or -1 for errors.

void Ns_SetSockErrno ( int  err  ) 

SOCKET Ns_SockAccept ( SOCKET  lsock,
struct sockaddr *  saPtr,
int *  lenPtr 
)

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

Ns_SockAccept --

Accept a TCP socket, setting close on exec.

Results: A socket or -1 on error.

Side effects: None.

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

SOCKET Ns_SockAsyncConnect ( char *  host,
int  port 
)

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

Ns_SockAsyncConnect --

Like Ns_SockConnect, but uses a nonblocking socket.

Results: A socket, or -1 on error.

Side effects: None.

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

SOCKET Ns_SockAsyncConnect2 ( char *  host,
int  port,
char *  lhost,
int  lport 
)

SOCKET Ns_SockBind ( struct sockaddr_in *  saPtr  ) 

int Ns_SockCloseLater ( SOCKET  sock  ) 

SOCKET Ns_SockConnect ( char *  host,
int  port 
)

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

Ns_SockConnect --

Open a TCP connection to a host/port.

Results: A socket, or -1 on error.

Side effects: None.

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

SOCKET Ns_SockConnect2 ( char *  host,
int  port,
char *  lhost,
int  lport 
)

SOCKET Ns_SockListen ( char *  address,
int  port 
)

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

Ns_SockListen, Ns_SockListenEx --

Listen for connections with default backlog.

Results: A socket or -1 on error.

Side effects: None.

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

SOCKET Ns_SockListenEx ( char *  address,
int  port,
int  backlog 
)

int Ns_SockPipe ( SOCKET  socks[2]  ) 

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

Ns_SockPipe --

Create a pair of unix-domain sockets.

Results: See socketpair(2)

Side effects: None.

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

int Ns_SockRecv ( SOCKET  sock,
void *  buf,
int  toread,
int  timeout 
)

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

NsSockRecv --

Timed recv() from a non-blocking socket.

Results: # bytes read

Side effects: May wait for given timeout.

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

int Ns_SockSend ( SOCKET  sock,
void *  buf,
int  towrite,
int  timeout 
)

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

Ns_SockSend --

Timed send() to a non-blocking socket. NOTE: This may not write all of the data you send it!

Results: Number of bytes written, -1 for error

Side effects: May wait given timeout.

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

int Ns_SockSetBlocking ( SOCKET  sock  ) 

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

Ns_SockSetBlocking --

Set a socket blocking.

Results: NS_OK/NS_ERROR

Side effects: None.

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

int Ns_SockSetNonBlocking ( SOCKET  sock  ) 

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

Ns_SockSetNonBlocking --

Set a socket nonblocking.

Results: NS_OK/NS_ERROR

Side effects: None.

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

char* Ns_SockStrError ( int  err  ) 

SOCKET Ns_SockTimedConnect ( char *  host,
int  port,
int  timeout 
)

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

Ns_SockTimedConnect --

Like Ns_SockConnect, but with an optional timeout in seconds.

Results: A socket, or -1 on error.

Side effects: None.

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

SOCKET Ns_SockTimedConnect2 ( char *  host,
int  port,
char *  lhost,
int  lport,
int  timeout 
)

int Ns_SockWait ( SOCKET  sock,
int  what,
int  seconds 
)

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

Ns_SockWait --

Wait for I/O.

Results: NS_OK, NS_TIMEOUT, or NS_ERROR.

Side effects: None.

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

int Ns_SockWaitEx ( SOCKET  sock,
int  what,
int  ms 
)

int NsPoll ( struct pollfd pfds,
int  nfds,
Ns_Time *  timeoutPtr 
)

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

NsPoll --

Poll file descriptors using an absolute timeout and restarting after any interrupts which may be received.

Results: See poll(2) man page.

Side effects: See poll(2) man page.

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

Clear revents.

Determine relative time from absolute time and continue polling if any interrupts are received.

Poll errors are not tolerated in AOLserver as they must indicate a code error which if ignored could lead to data lose and/or endless polling loops and error messages.


Generated on Tue Sep 4 19:58:56 2007 by  doxygen 1.5.1