DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Developing applications using XTI or TLI

Implementing a read/write interface

Sometimes you may want to establish a transport connection and then exec(S) an existing user program such as cat(C) to process the data as it arrives over the connection. However, most existing programs use read(S) and write(S) to perform character I/O. XTI and TLI do not directly support a read/write interface to a transport provider, but one may be provided using the tirdwr(M) STREAMS module. (This module is present in the kernel by default.) Such a connection can be released with the close(S) system call. This interface enables an application to issue read and write calls over a transport connection that has been established by the server's call to t_accept(NET).


NOTE: This interface is not available with the connectionless-mode service.

In the following example, a server first pushes tirdwr onto a stream before running cat(C) so that a client can read from or write to it over the transport connection.

   #include <stropts.h>
   

. /* . * connection requested and accepted . */

if (ioctl(fd, I_PUSH, "tirdwr") < 0) { perror("I_PUSH of tirdwr failed"); exit(5); } close(0); dup(fd); execl("/bin/cat", "/bin/cat", 0); perror("execl of /bin/cat failed"); exit(6);

The server invokes the read/write interface by pushing the tirdwr module onto the stream head associated with the transport endpoint created when the connection was established. For a description of I_PUSH, see streamio(M). With tirdwr in place, the server calls close and dup(S) to establish the transport endpoint as its standard input, and uses cat to process the input.

Because the transport layer is implemented using STREAMS, the facilities of this character I/O mechanism can be used to provide enhanced user services. Note the following limitations on the use of this interface:

If tirdwr receives any other XTI or TLI indication, it normally generates a fatal protocol error, EPROTO, on the stream. This causes further system calls to fail. However, if tirdwr is pushed onto a stream after a connection has been established, such indications are not generated.

With tirdwr pushed onto a stream, an application can send and receive data over the transport connection for the duration of the connection. Either end of a connection can terminate it by closing the file descriptor associated with the transport endpoint or by popping the tirdwr module off the stream. In either case, tirdwr takes the following actions:



Next topic: For more about XTI and TLI
Previous topic: Server pseudo-code

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003