|
|
A user may want to establish a transport connection and then exec(2) an existing user program such as cat(1) to process the data as it arrives over the connection. However, existing programs use read(2) and write(2) for their input/output needs. The Transport Interface does not directly support a read/write interface to a transport provider, but one is available with UNIX System V. This interface enables a user to issue read and write calls over a transport connection that is in the data transfer phase. This section describes the read/write interface to the connection-mode service of the Transport Interface. This interface is not available with the connectionless-mode service.
The read/write interface is presented using the client example of the ``Connection-mode service'' section with some minor modifications. The clients are identical until the data transfer phase is reached. At that point, this client will use the read/write interface and cat to process incoming data. cat can be run without change over the transport connection. Only the differences between this client and that of the example in the ``Connection-mode service'' section are shown below.
#include <stropts.h> . . /* . * Same local management and connection . * establishment steps. . */ .The client invokes the read/write interface by pushing the tirdwr(7xti) module onto the Stream associated with the transport endpoint where the connection was established (see I_PUSH in streamio(7)). This module converts the Transport Interface above the transport provider into a pure read/write interface. With the module in place, the client calls close(2) and dup(2) to establish the transport endpoint as its standard input file, and uses /usr/bin/cat to process the input. Because the transport endpoint identifier is a file descriptor, the facility for duping the endpoint is available to users.if (ioctl(fd, I_PUSH, "tirdwr") < 0) { perror("I_PUSH of tirdwr failed"); exit(5); }
close(0); dup(fd); execl("/usr/bin/cat", "/usr/bin/cat", 0); perror("execl of /usr/bin/cat failed"); exit(6); }
Because the Transport Interface uses STREAMS, the facilities of this character input/output mechanism can be used to provide enhanced user services. By pushing the tirdwr module above the transport provider, the user's interface is effectively changed. The semantics of read and write must be followed, and message boundaries will not be preserved.
The exact semantics of write, read, and close using tirdwr are described below. To summarize, tirdwr enables a user to send and receive data over a transport connection using read and write. This module will translate all Transport Interface indications into the appropriate actions. The connection can be released with the close system call.