In a Unix process, input and output is accomplished through ports. There are typically 64 ports in a Unix process, although there may be more depending upon the version of Unix. A port is represented as an integer value (the values are zero based, ranging between 0 and 63) in the source code of the process, and this value is referred to as a file descriptor.
Unix filter processes perform input and output in streams, using designated ports. The ports for streams in a Unix filter are half-duplex (when hooked to named or unnamed pipes) so a filter usually performs input and output on separate ports. The choice of port numbers is a significant part of the design of a given filter; the choices are not made randomly. Most Unix filters perform input from port 0, and output to port 1. Error messages are written using port 2. These choices are a well-known convention among Unix developers. This design allows for filters to be easily composed with pipes on the Unix command line into larger, more complex tools, that are themselves filters.
In the UniCon language, the description of a StreamIn or StreamOut player captures the system designer's intentions regarding particular streams of data in a filter process. Information such as the structure of the data in the stream and the port number over which the stream of data will flow is captured for each player. The PortBinding property is used to specify the port number over which the data in the stream will flow. This property is required in the property list of a StreamIn and StreamOut player.
Subsequent specifications of the PortBinding property in a single property list replace earlier specifications (i.e., the last specification is the one that the UniCon compiler uses).
COMPONENT Sort INTERFACE IS TYPE Filter PLAYER input IS StreamIn SIGNATURE ("line") PORTBINDING (stdin) END input PLAYER output IS StreamOut SIGNATURE ("line") PORTBINDING (1) END output PLAYER error IS StreamOut SIGNATURE ("line") PORTBINDING ("stderr") END error END INTERFACE IMPLEMENTATION IS VARIANT sort IN "sort" IMPLTYPE (Executable) END sort END IMPLEMENTATION END Sort
Author:
Last Modified: May 12, 1996