Next: Port handlers, Up: Programmatic ports
The ports structure defines the basis of the port data type and
exports the following procedures.
Port constructor. The arguments are all the fields of ports, which are described below. Note that
make-portis rarely called directly; usually one will use one of the buffered port constructors instead.
#f#f#fAccessors for the port fields:
handler- The handler is the functional parameterization mechanism: it provides all the port's operations, such as reading/writing blocks, disclosing (see Writer) the port, closing the port, &c. See Port handlers.
buffer- The buffer is used for buffered ports, where it is a byte vector. It may be any value for unbuffered ports.
lock- This misnamed field was originally used for a mutual exclusion lock, before optimistic concurrency was made the native synchronization mechanism in Scheme48. It is now used as a `timestamp' for buffered ports: it is provisionally written to with a unique value when a thread resets the
indexto reuse the buffer, and it is provisionally read from when reading from the buffer. In this way, if the buffer is reset while another thread is reading from it, the other thread's proposal is invalidated by the different value in memory than what was there when it logged the old timestamp in its proposal.status- A mask from the
port-status-optionsenumeration; see Miscellaneous I/O internals.data- Arbitrary data for particular kinds of ports. For example, for a port that tracks line & column information (see I/O extensions), this might be a record containing the underlying port, the line number, and the column number.
index- The current index into a buffered port's buffer. If the port is not buffered, this is
#f.limit- The limit of the
indexfield for a buffered port's buffer. When theindexfield is equal to thelimitfield, the buffer is full. If the port is not buffered, this is#f.pending-eof?- For output ports, this is a boolean flag indicating whether the buffer has been forced to output recently. For input ports, this is a boolean flag indicating whether an end of file is pending after reading through the current buffer.
These assign respective fields of ports. The
bufferandhandlerfields, however, are immutable.
#f#fProvisional versions of the above port accessors & modifiers; that is, accessors & modifiers that log in the current proposal, if there is one.