Add Book to My BookshelfPurchase This Book Online

Chapter 15 - Networking with TLI

UNIX Systems Programming for SVR4
David A. Curry
 Copyright © 1996 O'Reilly & Associates, Inc.

Using read and write with TLI
Earlier we said that read and write could not be used on transport endpoints without some special preparations. This is because TLI is implemented on top of the STREAMS subsystem, which is not discussed in this book. The original Streams subsystem was invented by Dennis Ritchie and included in Research UNIX Version 8. AT&T productized Streams by adding some additional functionality and changing the name to STREAMS, and released it for the first time in System V Release 3.0. However, SVR4 is the first release to fully support all devices with STREAMS drivers.
The STREAMS subsystem provides a raw data stream between the user and some device—a disk, a terminal, or a network interface. It removes the specialized drivers for each different type of device (there are still drivers, but they all have a common interface now). The user can add (“push”) and remove (“pop”) intermediate processing elements, called modules, to and from the data stream at will. The modules can be stacked so that more than one processes the data stream at the same time. This allows relatively simple, single-purpose modules to be combined in new and interesting ways to perform complex tasks, in the same manner as the UNIX shell allows complex tasks to be built out of simpler ones using pipelines.
STREAMS works by passing messages between adjacent processing elements. These messages are why read and write can't be used—they expect a plain byte stream, and do not know what to do with the message headers. In order to use read and write on a transport endpoint, it is necessary to push a processing module that essentially removes these message headers from the stream for the read side, and converts writes to messages on the write side. To push this module, the following call is used:
    #include <sys/ioctl.h>
    #include <sys/stropts.h>
    ·
    ·
    ·
    ioctl(fd, I_PUSH, "tirdwr");
    ·
    ·
    ·
After the module has been pushed, read and write can be used to transfer data. However, while the module is on the stream, the TLI functions cannot be used (although some may work). To use a TLI function, the module must be popped back off the stream:
    #include <sys/ioctl.h>
    #include <sys/stropts.h>
    ·
    ·
    ·
    ioctl(fd, I_POP, "tirdwr");
    ·
    ·
    ·
For all the hassles involved with this, it's probably not worth doing in the general case.

Previous SectionNext Section
Books24x7.com, Inc © 2000 –  Feedback