Next: , Previous: , Up: Input/Output   [Contents][Index]


14.7 Blocking Mode

An interactive port is always in one of two modes: blocking or non-blocking. This mode is independent of the terminal mode: each can be changed independently of the other. Furthermore, if it is an interactive I/O port, there are separate blocking modes for input and for output.

If an input port is in blocking mode, attempting to read from it when no input is available will cause Scheme to “block”, i.e. suspend itself, until input is available. If an input port is in non-blocking mode, attempting to read from it when no input is available will cause the reading procedure to return immediately, indicating the lack of input in some way (exactly how this situation is indicated is separately specified for each procedure or operation).

An output port in blocking mode will block if the output device is not ready to accept output. In non-blocking mode it will return immediately after performing as much output as the device will allow (again, each procedure or operation reports this situation in its own way).

Interactive ports are initially in blocking mode; this can be changed at any time with the procedures defined in this section.

These procedures represent blocking mode by the symbol blocking, and non-blocking mode by the symbol nonblocking. An argument called mode must be one of these symbols. A port argument to any of these procedures may be any port, even if that port does not support blocking mode; in that case, the port is not modified in any way.

procedure: input-port-blocking-mode input-port
procedure: output-port-blocking-mode output-port

Returns the blocking mode of input-port or output-port. Returns #f if the given port doesn’t support blocking mode.

procedure: set-input-port-blocking-mode! input-port mode
procedure: set-output-port-blocking-mode output-port mode

Changes the blocking mode of input-port or output-port to be mode and returns an unspecified value.

procedure: with-input-port-blocking-mode input-port mode thunk
procedure: with-output-port-blocking-mode output-port mode thunk

Thunk must be a procedure of no arguments.

Binds the blocking mode of input-port or output-port to be mode, and calls thunk. When thunk returns, the original blocking mode is restored and the values yielded by thunk are returned.

obsolete procedure: port/input-blocking-mode input-port
obsolete procedure: port/set-input-blocking-mode input-port mode
obsolete procedure: port/with-input-blocking-mode input-port mode thunk
obsolete procedure: port/output-blocking-mode output-port
obsolete procedure: port/set-output-blocking-mode output-port mode
obsolete procedure: port/with-output-blocking-mode output-port mode thunk

These procedures are deprecated; instead use the corresponding procedures above.


Next: , Previous: , Up: Input/Output   [Contents][Index]