Oberon || Library || Module Index || Search Engine || Definition || Module


Ulm's Oberon Library:
UnixSockets


NAME

UnixSockets - general interface for UNIX sockets

SYNOPSIS

TYPE Socket = POINTER TO SocketRec;
TYPE SocketRec = RECORD (Networks.SocketRec) END;


PROCEDURE Open(VAR s: Streams.Stream; addressFamily: INTEGER; type: INTEGER; address: ARRAY OF BYTE; bind: BOOLEAN; bindto: ARRAY OF BYTE; bufmode: Streams.BufMode; errors: RelatedEvents.Object) : BOOLEAN; PROCEDURE OpenL(VAR s: Streams.Stream; addressFamily: INTEGER; type: INTEGER; address: ARRAY OF BYTE; len: SysTypes.Size; bind: BOOLEAN; bindto: ARRAY OF BYTE; bindtolen: SysTypes.Size; bufmode: Streams.BufMode; errors: RelatedEvents.Object) : BOOLEAN;

PROCEDURE CreateOpenCondition(VAR condition: Conditions.Condition; addressFamily: INTEGER; type: INTEGER; address: ARRAY OF BYTE; bind: BOOLEAN; bindto: ARRAY OF BYTE); PROCEDURE CreateOpenConditionL(VAR condition: Conditions.Condition; addressFamily: INTEGER; type: INTEGER; address: ARRAY OF BYTE; len: SysTypes.Size; bind: BOOLEAN; bindto: ARRAY OF BYTE; bindtolen: SysTypes.Size); PROCEDURE TestAndOpen(VAR s: Streams.Stream; condition: Conditions.Condition; bufmode: Streams.BufMode; errors: RelatedEvents.Object) : BOOLEAN; PROCEDURE Drop(condition: Conditions.Condition);

PROCEDURE Listen(VAR socket: Socket; addressFamily: INTEGER; type: INTEGER; port: ARRAY OF BYTE; errors: RelatedEvents.Object) : BOOLEAN; PROCEDURE ListenL(VAR socket: Socket; addressFamily: INTEGER; type: INTEGER; port: ARRAY OF BYTE; len: SysTypes.Size; errors: RelatedEvents.Object) : BOOLEAN; PROCEDURE Accept(socket: Socket; VAR s: Streams.Stream; bufmode: Streams.BufMode; VAR peer: ARRAY OF BYTE) : BOOLEAN; PROCEDURE Release(socket: Socket);

PROCEDURE CreateAcceptCondition(VAR condition: Conditions.Condition; socket: Socket);

PROCEDURE GetName(socket: Socket; VAR address: ARRAY OF BYTE; errors: RelatedEvents.Object) : BOOLEAN;

DESCRIPTION

UnixSockets provides an interface for SysSockets which is used by socket-specific extensions (e.g. IPv4TCPSockets and UnixDomainSockets).

Socket streams are opened either by connecting to an already existing socket or by accepting a new connection on a port where other sockets may connect to. Both variants of opening a socket stream are supported in blocking (Open and Accept) and non-blocking form (CreateOpenCondition/TestAndOpen and CreateAcceptCondition).

Address families are enumerated in SysSockets. Usually, three address families supported only:

SysSockets.afUNIX
UNIX domain sockets -- supported by UnixDomainSockets
SysSockets.afINET
IPv4 sockets -- supported by IPv4TCPSockets
SysSockets.afINET6
IPv6 sockets
The underlying system calls which get address parameters have an additional parameter that specifies the exact length of the address in bytes. This length is constant for IPv4 or IPv6 domain sockets but not for UNIX domain sockets where it depends on the length of the path.

The type parameter specifies the socket type. SysSockets.stream is to be used for stream sockets. Other possible types are SysSockets.dgram, SysSockets.rdm, and SysSockets.seqpacket.

All procedures which accept an address as ARRAY OF BYTE are offered in two variants: one which implicitly takes LEN of the dynamic array to calculate the length (Open, CreateOpenCondition, and Listen) and one which has an explicit length parameter (OpenL, CreateOpenConditionL, and ListenL).

All connecting procedures (Open, OpenL, CreateOpenCondition, and CreateOpenConditionL) accept an optional address in bindto where the socket is to be bound locally. The bind parameter is to be set to TRUE to take the address of bindto, otherwise a default address selected by the underlying operating system is taken. This specification is mainly useful for services running on virtual IP addresses. In case of OpenL and CreateOpenConditionL, the parameter bindtolen specifies the length of bindto.

Drop may be used to get rid of conditions created by CreateOpenCondition or CreateOpenConditionL which have not yet been successfully opened using TestAndOpen.

Some socket options are set that override less useful defaults of the underlying operating system:

CreateOpenCondition creates a condition which allows to wait for the connection to address to be established or until the try to connect fails. When the condition returned by CreateOpenCondition evaluates to TRUE, TestAndOpen is to be used to test for success, and if successful, to open the established connection as stream. Open serves as shorthand notation for CreateOpenCondition, followed by Tasks.WaitFor, and TestAndOpen.

Listen creates a port where other parties may connect to. CreateAcceptCondition allows to wait for incoming connections which may be opened by Accept. Release allows to close a port if no more connections are to be accepted.

GetName returns the address of a socket. This is useful when a special address was used which asked the UNIX kernel to choose an address.

DIAGNOSTICS

Creating a condition is always successful, Release ignores any errors, and all other operations return FALSE in case of errors. UnixSockets does not generate itself error events but propagates those of SysSockets. Accept relates its error events to socket, all other error events are related to errors.

SEE ALSO

IPv4TCPSockets
high-level interface for IPv4 TCP sockets
Networks
general abstraction for network connections
SysSockets
interfaces socket related system calls
UnixDomainSockets
high-level interface for UNIX domain sockets

Edited by: borchert, last change: 2005/01/21, revision: 1.5, converted to HTML: 2005/01/21

Oberon || Library || Module Index || Search Engine || Definition || Module