📄 streams.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>STREAMS</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><blockquote><center><h3><a name = "tag_000_001"> </a>STREAMS</h3></center><xref type="2" name="OVSTREAMS"></xref>STREAMS provides a uniform mechanism for implementing networking services andother character-based I/O. The STREAMS interface provides direct access toprotocol modules. A STREAM is typically a full-duplex connection between aprocess and an open device or pseudo-device. However, since pipes may beSTREAMS-based, a STREAM can be a full-duplex connection between twoprocesses. The STREAM itself exists entirely within the implementation andprovides a general character I/O interface for processes. It optionallyincludes one or more intermediate processing modules that are interposedbetween the process end of the STREAM (STREAM head) and a device driver at theend of the STREAM (STREAM end).<p>STREAMS I/O is based on messages. Messages flow in both directions in aSTREAM. A given module need not understand and process every message in theSTREAM, but every module in the STREAM handles every message. Each moduleaccepts messages from one of its neighbour modules in the STREAM, and passesthem to the other neighbour. For example, a line discipline module maytransform the data. Data flow through the intermediate modules isbidirectional, with all modules handling, and optionally processing, allmessages. There are three types of messages:<ul><p><li><i>data messages</i>containing actual data for input or output<p><li><i>control data</i>containing instructions for the STREAMS modules and underlying implementation<p><li>other messages, which include file descriptors.<p></ul><p>The interface between the STREAM and the rest of the implementation isprovided by a set of functions at the STREAM head. When a process calls<i><a href="write.html">write()</a></i>,<i><a href="putmsg.html">putmsg()</a></i>,<i><a href="putpmsg.html">putpmsg()</a></i>or<i><a href="ioctl.html">ioctl()</a></i>,messages are sent down the STREAM, and<i><a href="read.html">read()</a></i>,<i><a href="getmsg.html">getmsg()</a></i>or<i><a href="getpmsg.html">getpmsg()</a></i>accepts data from the STREAM and passes it to a process. Data intended forthe device at the downstream end of the STREAM is packaged into messages andsent downstream, while data and signals from the device are composed intomessages by the device driver and sent upstream to the STREAM head.<p>When a STREAMS-based device is opened, a STREAM is created that contains twomodules: the STREAM head module and the STREAM end (driver) module. If pipesare STREAMS-based in an implementation, when a pipe is created, two STREAMSare created, each containing a STREAM head module. Other modules are added tothe STREAM using<i><a href="ioctl.html">ioctl()</a></i>.New modules are "pushed" onto the STREAM one at a time in last-in, first-out(LIFO) style, as though the STREAM was a push-down stack.<h5><a name = "tag_000_001_000_001"> </a>Priority</h5><p>Message types are classified according to their queueing priority and may benormal (non-priority), priority, or high-priority messages. A message belongsto a particular priority band that determines its ordering when placed on aqueue. Normal messages have a priority band of 0 and are always placed atthe end of the queue following all other messages in the queue. High-prioritymessages are always placed at the head of the queue, but will be discardedif there is already a high-priority message in the queue. Their priority band is ignored;they are high-priority by virtue of their type. Priority messages have apriority band greater than 0. Priority messages are always placed afterany messages of the same or higher priority. High-priority and prioritymessages are used to send control and data information outside the normal flowof control. By convention, high-priority messages are not affected by flowcontrol. Normal and priority messages have separate flow controls.<h5><a name = "tag_000_001_000_002"> </a>Message Parts</h5><p>A process may access STREAMS messages that contain a data part, control part,or both. The data part is that information which is transmitted over thecommunication medium and the control information is used by the local STREAMSmodules. The other types of messages are used between modules and are notaccessible to processes. Messages containing only a data part are accessiblevia<i><a href="putmsg.html">putmsg()</a></i>,<i><a href="putpmsg.html">putpmsg()</a></i>,<i><a href="getmsg.html">getmsg()</a></i>,<i><a href="getpmsg.html">getpmsg()</a></i>,<i><a href="read.html">read()</a></i>or<i><a href="write.html">write()</a></i>.Messages containing a control part with or without a data part areaccessible via calls to<i><a href="putmsg.html">putmsg()</a></i>,<i><a href="putpmsg.html">putpmsg()</a></i>,<i><a href="getmsg.html">getmsg()</a></i>or<i><a href="getpmsg.html">getpmsg()</a></i>.<h4><a name = "tag_000_001_001"> </a>Accessing STREAMS</h4><p>A process accesses STREAMS-based files using the standard functions<i><a href="open.html">open()</a></i>,<i><a href="close.html">close()</a></i>,<i><a href="read.html">read()</a></i>,<i><a href="write.html">write()</a></i>,<i><a href="ioctl.html">ioctl()</a></i>,<i><a href="pipe.html">pipe()</a></i>,<i><a href="putmsg.html">putmsg()</a></i>,<i><a href="putpmsg.html">putpmsg()</a></i>,<i><a href="getmsg.html">getmsg()</a></i>,<i><a href="getpmsg.html">getpmsg()</a></i>or<i><a href="poll.html">poll()</a></i>.Refer to the applicable function definitions for general properties anderrors.<p>Calls to<i><a href="ioctl.html">ioctl()</a></i>are used to perform control functions with the STREAMS-based deviceassociated with the file descriptor <i>fildes</i>. The arguments <i>command</i>and <i>arg</i> are passed to the STREAMS file designated by <i>fildes</i> andare interpreted by the STREAM head. Certain combinations of these argumentsmay be passed to a module or driver in the STREAM.<p>Since these STREAMS requests are a subset of<i><a href="ioctl.html">ioctl()</a></i>,they are subject to the errors described there.<p>STREAMS modules and drivers can detect errors, sending an error message to theSTREAM head, thus causing subsequent functions to fail and set <i>errno</i> tothe value specified in the message. In addition, STREAMS modules and driverscan elect to fail a particular<i><a href="ioctl.html">ioctl()</a></i>request alone by sending a negative acknowledgement message to the STREAMhead. This causes just the pending<i><a href="ioctl.html">ioctl()</a></i>request to fail and set <i>errno</i> to the value specified in the message.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -