XTI/TLI Read/Write Interface
To process the data as it arrives over the connection, a user can establish a transport
connection using exec
()
on an existing program such as
/usr/bin/cat
. Existing programs use read
()
and
write
(). XTI/TLI does not directly support a read/write interface to a
transport provider, but one may be provided by using the tirdwr
module.
For more information, see the
exec
(2),
read
(2), and
write
(2) man pages. The interface enables you to issue
read
()
and write
()
calls over a transport connection
in the data transfer phase. This section describes the read/write interface with the
XTI/TLI connection mode service. This interface is not available with the connectionless
mode service.
Example 8-1 Using the XTI/TLI Read/Write Interface
#include <stropts.h> /* Same local management and connection establishment steps. */ if (ioctl(fd, I_PUSH, "tirdwr") == -1) { perror("I_PUSH of tirdwr failed"); exit(5); } close(0); dup(fd); execl("/usr/bin/cat", "/usr/bin/cat", (char *) 0); perror("exec of /usr/bin/cat failed"); exit(6);
The client invokes the read/write interface by pushing the tirdwr
module onto the stream associated with the transport endpoint. For more information about
I_PUSH
, see the
streamio
(4I) man page. The tirdwr
module converts XTI/TLI
above the transport provider into a read/write interface. Once the the
tirdwr
module is pushed, the client calls close
()
and dup
()
to establish the transport endpoint as its standard input file,
and uses /usr/bin/cat
to process the input. For more information, see
the
close
(2) and
dup
(2).
Pushing the tirdwr
module onto the transport provider forces XTI/TLI
to use read
()
and write
()
semantics. XTI/TLI does not
preserve message boundaries when using read
()
and write
()
semantics. Pop tirdwr
from the transport provider to restore the XTI/TLI
semantics. For more information about I_POP
, see the
streamio
(4I) man page.
Caution:
Push thetirdwr
module onto a stream only when the transport
endpoint is in the data transfer phase. After pushing the module, the user cannot call
any XTI/TLI routines. If the user invokes an XTI/TLI routine, tirdwr
generates a fatal protocol error, EPROTO
, on the stream,
rendering it unusable. If you then pop the tirdwr
module off the
stream, the transport connection aborts.