You are on page 1of 10

Streams

Drawback of device drivers

The lack of comonality at the driver level percolates up to the user command level
Where several commands may accomplish common

logical functions but over different media

Newtork protocols require a line discipline-like capability


Where each discipline implements on part of a protocol

and the component parts can be combined in a flexible manner

CS502 / IT524

OVERVIEW

Streams
Streams are a scheme for improving the modularity of devie drivers and protocols A Stream is a full-duplex connection between a process and da device Streams modules are characterized by welldefined interfaces and by their flexibility for use in combination with other modules The flexibility they offer has strong benefits for network protocols and drivers
CS502 / IT524 OVERVIEW 2

Streams
Stream Head Output Queue Input Queue Inode of Device file

Driver

Output Queue

Input Queue

a queue pair

Figure 10.20. A Stream after open

CS502 / IT524

OVERVIEW

Streams
Message 1 Block

Message 2

Message 3

Figure 10.21. Streams Messages

CS502 / IT524

OVERVIEW

Streams
Stream Head Output Queue Input Queue Inode of Device file

Line Discipline

Output Queue

Input Queue

Terminal Driver

Output Queue

Input Queue

Figure 10.22. Pushing a Module onto a Stream


CS502 / IT524 OVERVIEW 5

A More Detailed Examples of Streams


User Level Kernel Level

sh1

sh1

mpx

ttyld

ttyld

msg

msg

Pty pair 1

Pty pair 2 Tty driver

Figure 10.23. Windowing Virtual Terminals on a Physical Terminal


CS502 / IT524 OVERVIEW 6

Pseude code for Multiplexing Windows

CS502 / IT524

OVERVIEW

/* assume filedescriptors 0 and 1 already refer to physical tty */ For(;;) { select(input); read input line; switch(line with input data) { case physical tty: if ( control command ) { open a free pseude-tty; fork a new process: if(parent) { push a msg discipline on mpx side; continue; } /* child here */ close unnecessary file descriptors; open other member of pseude-tty pair, get stdin, stdout, stderr; push tty line discipline; exec shell; } CS502 / IT524 OVERVIEW 8

/* regular data from tty coming up for virtual tty */ Demultiplex data read from physical tty, strip off headers and write to appropriate pty; Continue; /* back to for loop */ Case logical tty: /* a virtual tty is writing a window */ encode header indicating what window data is for; write header and data to physical tty; continue; } }

CS502 / IT524

OVERVIEW

Summary
Streams are a scheme for improving the modularity of device drivers and protocols. A stream is a full-duplex connection between processes and device drivers, which may contain line disciplines and protocols to process data en route. Streams modules are characterized by well-defined interfaces and by their flexibility for use in combination with other modules.

The flexibility the offer has strong benefits for network protocols and drivers.

CS502 / IT524

OVERVIEW

10

You might also like