14.9.5 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 independent 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: port/input-blocking-mode port

Returns the input blocking mode of port.

— procedure: port/set-input-blocking-mode port mode

Changes the input blocking mode of port to be mode. Returns
an unspecified value.

— procedure: port/with-input-blocking-mode port mode thunk

Thunk must be a procedure of no arguments.
port/with-input-blocking-mode
binds the input blocking mode of port to be mode, executes
thunk, restores the input blocking mode of port to what it
was when port/with-input-blocking-mode was called, and returns
the value that was yielded by thunk. This binding is performed
by dynamic-wind, which guarantees that the input blocking mode is
restored if thunk escapes from its continuation.

— procedure: port/output-blocking-mode port

Returns the output blocking mode of port.

— procedure: port/set-output-blocking-mode port mode

Changes the output blocking mode of port to be mode.
Returns an unspecified value.

— procedure: port/with-output-blocking-mode port mode thunk

Thunk must be a procedure of no arguments.
port/with-output-blocking-mode
binds the output blocking mode of port to be mode, executes
thunk, restores the output blocking mode of port to what it
was when port/with-output-blocking-mode was called, and returns
the value that was yielded by thunk. This binding is performed
by dynamic-wind, which guarantees that the output blocking mode
is restored if thunk escapes from its continuation.