STREAMS

13.6 STREAMS ( Optional )

  • The streams mechanism in UNIX provides a bi-directional pipeline between a user process and a device driver, onto which additional modules can be added.
  • The user process interacts with the stream head.
  • The device driver interacts with the device end.
  • Zero or more stream modules can be pushed onto the stream, using ioctl( ). These modules may filter and/or modify the data as it passes through the stream.
  • Each module has a read queue and a write queue.
  • Flow control can be optionally supported, in which case each module will buffer data until the adjacent module is ready to receive it. Without flow control, data is passed along as soon as it is ready.
  • User processes communicate with the stream head using either read( ) and write( ) ( or putmsg( ) and getmsg( ) for message passing. )
  • Streams I/O is asynchronous ( non-blocking ), except for the interface between the user process and the stream head.
  • The device driver must respond to interrupts from its device - If the adjacent module is not prepared to accept data and the device driver's buffers are all full, then data is typically dropped.
  • Streams are widely used in UNIX, and are the preferred approach for device drivers. For example, UNIX implements sockets using streams.

Figure 13.14 - The SREAMS structure.