index previous next 

file name: socket.hpp, socket.cpp
classification: simulation
contents: pSOS style functions for accessing sockets
use: provide an easy to use interface to sockets
 

Note: socket.cpp contains two implementations, one for Linux and pSOS (if DOS_SIM is not defined), and one for DOS. The DOS version uses a queue to simulate the socket, so the behaviour is slightly different (more like a datagram socket than like a stream socket). The descriptions below are for the UNIX version (the DOS version is only needed for debugging; it is best if you can assume that the sockets are always empty in DOS).
 

global items used if DOS_SIM is not defined:

 
global items defined:

enum ESocketError: Here you can find all error codes that are returned by the socket functions.

enum ESocketMode: For specifying the mode of some calls (timeout or waiting until successful).

enum ESocketType: For specifying the type of the socket (stream or datagram).
 

local items defined in the implementation file:

int Convert (ESocketType type): Converts an enum of type ESocketType into the corresponding define .

void SetSocketOptions (int family, int sid): If the family is AF_UNIX,  the function returns at once. If it is AF_INET, then options SO_REUSEADDR and TCP_NODELAY are set.

#define ADDRTYPE: The type of the address structure used by the socket system calls. Whereas Linux provides both UNIX and Internet sockets and therefore uses the type sockaddr for both, pSOS just provides internet sockets and thus always expects the type sockaddr_in.

#define DATATYPE: The type of the data that is send to or received from the socket. Linux expects the pointer to the data buffer to have the type void*, whereas pSOS expects the type char*. The macro does not include the '*', it is just set to void or char.
 

socket functions:

INT32 s_accept (INT32 sid, INT32 *accsid): The function accepts a new connection from socket sid and copies the new socket ID into accsid. The function returns

INT32 s_create (const ACSocketAddress *addr, ESocketType type, INT32 *sid): Creates a socket, binds the address to it. Sets some socket options through function SetSocketOptions(). Listens to the socket if it is of type SStream. Parameter sid will contain the socket ID. If addr or sid is NULL, an assert fails. The function returns INT32 s_delete (INT32 sid, const ACSocketAddress *addr = NULL): Closes the socket. If addr is not NULL and if its address family is AF_UNIX, the socket is unlinked as well. The function always returns SOkay.
Note: the code for unlinking the socket is only available if PSOS_SIM is not defined, because in pSOS UNIX sockets are not supported.

INT32 s_ident (const ACSocketAddress *addr, ESocketType type, INT32 *sid): Creates a socket. Sets some socket options through function SetSocketOptions(). If the socket type is SStream, it connects the socket to the address specified by addr. Parameter sid will contain the socket ID. If addr or sid is NULL, an assert fails. The function returns

INT32 s_receive (INT32 sid, ESocketMode mode, double timeout, void *data, INT32 *len): Reads at most len bytes into the buffer pointed to by data. If mode==SNoTimeout, the call blocks until data can be read. To make a non-blocking call, set mode==STimeout and specify the timeout in parameter timeout (in seconds, with a resolution of microseconds; timeout==0 means polling). len is modified to represent the real size that was read. If data or len is NULL, an assert fails. The function returns INT32 s_send (INT32 sid, const void *data, INT32 len): The function sends len bytes from the buffer specified by data over the socket sid, which is assumed to be of type SStream. If data is NULL, an assert fails. The function returns INT32 s_send (INT32 sid, const ACSocketAddress *addr, const void *data, INT32 len): The function sends len bytes from the buffer specified by data over the socket sid, which is assumed to be of type SDatagram and to have address addr. If data or addr is NULL, an assert fails. The function returns
last modified: Fri Feb 5 18:56:34 1999