Oberon || Library || Module Index || Search Engine || Definition || Module
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;
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:
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.
Oberon || Library || Module Index || Search Engine || Definition || Module