Top Banner

of 10

Unix Streams

Apr 07, 2018

Download

Documents

phhkmu
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/3/2019 Unix Streams

    1/10

    CS502 / IT524 OVERVIEW 1

    Streams

    Drawback of device drivers

    The lack of comonality at the driver levelpercolates up to the user command level

    Where several commands may accomplish commonlogical functions but over different media

    Newtork protocols require a line discipline-likecapability

    Where each discipline implements on part of a protocoland the component parts can be combined in a flexiblemanner

  • 8/3/2019 Unix Streams

    2/10

    CS502 / IT524 OVERVIEW 2

    Streams

    Streams are a scheme for improving themodularity of devie drivers and protocols

    A Stream is a full-duplex connection betweena process and da device

    Streams modules are characterized by well-defined interfaces and by their flexibility for

    use in combination with other modules

    The flexibility they offer has strong benefitsfor network protocols and drivers

  • 8/3/2019 Unix Streams

    3/10

  • 8/3/2019 Unix Streams

    4/10

    CS502 / IT524 OVERVIEW 4

    Streams

    Block

    Figure 10.21. Streams Messages

    Message 1 Message 2 Message 3

  • 8/3/2019 Unix Streams

    5/10

    CS502 / IT524 OVERVIEW 5

    OutputQueue

    InputQueue

    OutputQueue

    InputQueue

    Inode ofDevice file

    Figure 10.22. Pushing a Module onto a Stream

    OutputQueue

    InputQueue

    Stream Head

    Line Discipline

    Terminal Driver

    Streams

  • 8/3/2019 Unix Streams

    6/10

    CS502 / IT524 OVERVIEW 6CS502 / IT524 OVERVIEW 6

    A More Detailed Examples ofStreams

    sh1 sh1 mpx

    Pty

    pair 1

    Pty

    pair 2

    User Level

    Kernel Level

    ttyld ttyld msg msg

    Tty driver

    Figure 10.23. Windowing Virtual Terminals on a Physical Terminal

  • 8/3/2019 Unix Streams

    7/10

    Pseude code for MultiplexingWindows

    CS502 / IT524 OVERVIEW 7

  • 8/3/2019 Unix Streams

    8/10

    /* 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

  • 8/3/2019 Unix Streams

    9/10

    /* 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 9

  • 8/3/2019 Unix Streams

    10/10

    Summary

    Streams are a scheme for improving the modularity of device driversand protocols.

    A stream is a full-duplex connection between processes and device

    drivers, which may contain line disciplines and protocols to processdata en route.

    Streams modules are characterized by well-defined interfaces and bytheir flexibility for use in combination with other modules.

    The flexibility the offer has strong benefits for network protocols anddrivers.

    CS502 / IT524 OVERVIEW 10