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


Ulm's Oberon Library:
StreamConditions


NAME

StreamConditions - wait until a stream becomes ready for input or output

SYNOPSIS

CONST read = 0; write = 1; (* operations *)
TYPE Operation = SHORTINT; (* read or write *)
TYPE CreateConditionMessage =
   RECORD
      (Streams.Message)
      (* in-parameters *)
      operation: Operation; (* read or write *)
      (* out-parameters *)
      condition: Conditions.Condition; (* return value *)
      stream: Streams.Stream; (* message processed for this stream *)
      msgProcessed: BOOLEAN; (* initially FALSE; has to be set to TRUE *)
   END;
TYPE TestConditionMessage =
   RECORD
      (Streams.Message)
      (* in-parameters *)
      operation: Operation; (* read or write *)
      errors: RelatedEvents.Object; (* relate errors to this object *)
      (* out-parameters *)
      wouldblock: BOOLEAN;
      msgProcessed: BOOLEAN;
   END;


CONST msgFailed = 0; CONST invalidOp = 1; CONST errorcodes = 2; TYPE ErrorEvent = POINTER TO ErrorEventRec; TYPE ErrorEventRec = RECORD (Events.EventRec) errorcode: SHORTINT; END; VAR errormsg: ARRAY errorcodes OF Events.Message; VAR error: Events.EventType;

PROCEDURE Create(VAR condition: Conditions.Condition; s: Streams.Stream; operation: Operation);

DESCRIPTION

StreamConditions creates conditions which allow to wait until a stream is ready for reading or waiting, i.e. a read or wait operation would not cause the current process or task to be blocked.

Stream conditions must be supported by the underlying stream implementation. StreamConditions uses stream messages to communicate with the stream implementation:

CreateConditionMessage
asks the underlying implementation to create a condition. The newly created condition is to be returned in condition. Further, stream is to be set to the stream. Because the message may be passed through some other stream implementations it is possible that this is a different stream. msgProcessed must be set to TRUE, otherwise StreamConditions assumes that the implementation does not support stream conditions.
In case of buffered streams it is important that the implementation does not forget to check the buffer status by use of the appropiate routines of Streams.
The underlying implementation is free to set condition to NIL. StreamConditions creates then a condition of its own and assumes that the stream implementation is able to process messages of type TestConditionMessage.
TestConditionMessage
requests the stream implementation to test the condition: wouldblock is to be set to TRUE if an operation would cause the process or task to be blocked or in case of errors. Any errors are to be related to errors instead to the stream. Again, msgProcessed must be set to TRUE to indicate that the message has been processed.

Create creates a condition which allows the process or task to wait until the stream becomes ready for the given operation. condition is set to NIL if stream conditions are not supported for the underlying stream implementation.

DIAGNOSTICS

Errors during Create are related to the given stream and errors during the evaluation of conditions are related to the errors parameter of the interface procedures of Conditions. Following errors are generated by StreamConditions:
msgFailed
indicates that a message was returned unprocessed.
invalidOp
an invalid operation was given to Create (neither read nor write).

SEE ALSO

Conditions
interface for conditions
Streams
streams interface

Edited by: borchert, last change: 2005/02/04, revision: 1.4, converted to HTML: 2005/02/04

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