⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ioctl.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>ioctl</title></head><body bgcolor=white><center><font size=2>The Single UNIX &reg; Specification, Version 2<br>Copyright &copy; 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_006_008">&nbsp;</a>NAME</h4><blockquote>ioctl - control a STREAMS device</blockquote><h4><a name = "tag_000_006_009">&nbsp;</a>SYNOPSIS</h4><blockquote><pre><code>#include &lt;<a href="stropts.h.html">stropts.h</a>&gt;int ioctl(int <i>fildes</i>, int <i>request</i>, ... /* arg */);</code></pre></blockquote><h4><a name = "tag_000_006_010">&nbsp;</a>DESCRIPTION</h4><blockquote>The<i>ioctl()</i>function performs a variety of control functions on STREAMS devices.  Fornon-STREAMS devices, the functions performed by this call areunspecified.  The <i>request</i> argument and an optional thirdargument (with varying type) are passed to and interpreted by the appropriatepart of the STREAM associated with <i>fildes</i>.<p>The <i>fildes</i> argument is an open file descriptor that refers to a device.<p>The <i>request</i> argument selects the control functionto be performed and will depend on the STREAMS device being addressed.<p>The <i>arg</i> argument represents additional information that is needed bythis specific STREAMS device to perform the requested function.  The type of<i>arg</i> depends upon the particular control request, but it is either aninteger or a pointer to a device-specific data structure.<p>The<i>ioctl()</i>commands applicable to STREAMS, their arguments, and errorstatuses that apply to each individual command are described below.<p>The following<i>ioctl()</i>commands, with error values indicated, are applicable to all STREAMS files:<dl compact><dt>I_PUSH<dd>Pushes the module whose name is pointed to by <i>arg</i> onto the top of thecurrent STREAM, just below the STREAM head.  It then calls the<i><a href="open.html">open()</a></i>function of the newly-pushed module.The<i>ioctl()</i>function with the I_PUSH command will fail if:<dl compact><dt>[EINVAL]<dd>Invalid module name.<dt>[ENXIO]<dd>Open function of new module failed.<dt>[ENXIO]<dd>Hangup received on <i>fildes</i>.</dl><p><dt>I_POP<dd>Removes the module just below the STREAM head of the STREAM pointed to by<i>fildes</i>.  The <i>arg</i> argument should be 0 in an I_POP request.<p>The<i>ioctl()</i>function with the I_POP command will fail if:<dl compact><dt>[EINVAL]<dd>No module present in the STREAM.<dt>[ENXIO]<dd>Hangup received on <i>fildes</i>.</dl><p><dt>I_LOOK<dd>Retrieves the name of the module just below the STREAM headof the STREAM pointed to by <i>fildes</i>, and places itin a character string pointed to by <i>arg</i>.The buffer pointed to by <i>arg</i> should be at least FMNAMESZ+1bytes long, where FMNAMESZ is defined in &lt;<b>stropts.h</b>&gt;.<p>The<i>ioctl()</i>function with the I_LOOK command will fail if:<dl compact><dt>[EINVAL]<dd><index term="[EINVAL]"></index>No module present in the STREAM.</dl><p><dt>I_FLUSH<dd>This request flushes read and/or write queues, depending on the value of<i>arg</i>.  Valid <i>arg</i> values are:<dl compact><dt>FLUSHR<dd>Flush all read queues.<dt>FLUSHW<dd>Flush all write queues.<dt>FLUSHRW<dd>Flush all read and all write queues.</dl><p>The<i>ioctl()</i>function with the I_FLUSH command will fail if:<dl compact><dt>[EINVAL]<dd>Invalid <i>arg</i> value.<dt>[EAGAIN] or [ENOSR]<dd>Unable to allocate buffers for flush message.<dt>[ENXIO]<dd>Hangup received on <i>fildes</i>.</dl><p><dt>I_FLUSHBAND<dd>Flushes a particular band of messages.  The <i>arg</i> argument points to a<b>bandinfo</b> structure.  The <b>bi_flag</b> member may be one of FLUSHR,FLUSHW, or FLUSHRW as described above.  The <b>bi_pri</b> member determines thepriority band to be flushed.<p><dt>I_SETSIG<dd>Requests that the STREAMS implementation send theSIGPOLL signal to the calling process when a particular event has occurred onthe STREAM associated with <i>fildes</i>.  I_SETSIG supports an asynchronousprocessing capability in STREAMS.  The value of <i>arg</i> is a bitmask thatspecifies the events for which the process should be signaled.  It is thebitwise-OR of any combination of the following constants:<dl compact><dt>S_RDNORM<dd>A normal (priority band set to 0) message has arrived at the head of aSTREAM head read queue.  A signal will be generated even if the message is ofzero length.<dt>S_RDBAND<dd>A message with a non-zero priority band has arrived at the head of a STREAMhead read queue.  A signal will be generated even if the message is of zerolength.<dt>S_INPUT<dd>A message, other than a high-priority message, has arrived at the head of aSTREAM head read queue.  A signal will be generated even if the message is ofzero length.<dt>S_HIPRI<dd>A high-priority message is present on a STREAM head read queue.  A signal willbe generated even if the message is of zero length.<dt>S_OUTPUT<dd>The write queue for normal data (priority band 0) just below the STREAMhead is no longer full.  This notifies the process that there is room on thequeue for sending (or writing) normal data downstream.<dt>S_WRNORM<dd>Same as S_OUTPUT.<dt>S_WRBAND<dd>The write queue for a non-zero priority band just below the STREAM head is nolonger full.  This notifies the process that there is room on the queue forsending (or writing) priority data downstream.<dt>S_MSG<dd>A STREAMS signal message that contains the SIGPOLL signal has reached thefront of the STREAM head read queue.<dt>S_ERROR<dd>Notification of an error condition has reached the STREAM head.<dt>S_HANGUP<dd>Notification of a hangup has reached the STREAM head.<dt>S_BANDURG<dd>When used in conjunction with S_RDBAND, SIGURG is generated instead of SIGPOLLwhen a priority message reaches the front of the STREAM head read queue.</dl><p>If <i>arg</i> is 0, the calling process will be unregistered and will notreceive further SIGPOLL signals for the stream associated with <i>fildes</i>.<p>Processes that wish to receive SIGPOLL signals must explicitly register toreceive them using I_SETSIG.  If several processes register to receive thissignal for the same event on the same STREAM, each process will be signaledwhen the event occurs.<p>The<i>ioctl()</i>function with the I_SETSIG command will fail if:<dl compact><dt>[EINVAL]<dd>The value of <i>arg</i> is invalid.<dt>[EINVAL]<dd>The value of <i>arg</i> is 0 and the callingprocess is not registered to receive the SIGPOLL signal.<dt>[EAGAIN]<dd>There were insufficient resources to store the signal request.</dl><p><dt>I_GETSIG<dd>Returns the events for which the calling process is currently registeredto be sent a SIGPOLL signal.  The events are returned as a bitmask in an<b>int</b>pointed to by <i>arg</i>, where the events are those specified inthe description of I_SETSIG above.<p>The<i>ioctl()</i>function with the I_GETSIG command will fail if:<dl compact><dt>[EINVAL]<dd>Process is not registered to receive the SIGPOLL signal.</dl><p><dt>I_FIND<dd>This request compares the names of all modules currently present in the STREAMto the name pointed to by <i>arg</i>, and returns 1 if the named module ispresent in the STREAM, or returns 0 if the named module is not present.<p>The<i>ioctl()</i>function with the I_FIND command will fail if:<dl compact><dt>[EINVAL]<dd><i>arg</i> does not contain a valid module name.</dl><p><dt>I_PEEK<dd>This request allows a process to retrieve the information in the first messageon the STREAM head read queue without taking the message off the queue.  It isanalogous to<i><a href="getmsg.html">getmsg()</a></i>except that this command does not remove the message from the queue.The <i>arg</i> argument points to a <b>strpeek</b> structure.<p>The <b>maxlen</b> member in the <b>ctlbuf</b> and <b>databuf</b> <b>strbuf</b>structures must be set to the number of bytes of control information and/ordata information, respectively, to retrieve.  The <b>flags</b> member may bemarked RS_HIPRI or 0, as described by<i><a href="getmsg.html">getmsg()</a></i>.If the process sets <b>flags</b> to RS_HIPRI, for example, I_PEEK will onlylook for a high-priority message on the STREAM head read queue.<p>I_PEEK returns 1 if a message was retrieved, and returns 0 if no message wasfound on the STREAM head read queue, or if the RS_HIPRI flag was set in<b>flags</b> and a high-priority message was not present on the STREAM headread queue.  It does not wait for a message to arrive.  On return,<b>ctlbuf</b> specifies information in the control buffer,<b>databuf</b> specifies information in the data buffer, and<b>flags</b> contains the value RS_HIPRI or 0.<p><dt>I_SRDOPT<dd>Sets the read mode using the value of the argument <i>arg</i>.  Read modes aredescribed in<i><a href="read.html">read()</a></i>.Valid <i>arg</i> flags are:<dl compact><dt>RNORM<dd>Byte-stream mode, the default.<dt>RMSGD<dd>Message-discard mode.<dt>RMSGN<dd>Message-nondiscard mode.</dl><p>The bitwise inclusive OR of RMSGD and RMSGN will return [EINVAL].The bitwise inclusive OR of RNORM and either RMSGD or RMSGN willresult in the other flag overriding RNORM which is the default.<p>In addition, treatment of control messages by the STREAM head may bechanged by setting any of the following flags in <i>arg</i>:<dl compact><dt>RPROTNORM<dd>Fail<i><a href="read.html">read()</a></i>with [EBADMSG] if a message containing a control part is at the front of theSTREAM head read queue.<dt>RPROTDAT<dd>Deliver the control part of a message as data when a process issues a<i><a href="read.html">read()</a></i>.<dt>RPROTDIS<dd>Discard the control part of a message, delivering any data portion,when a process issues a<i><a href="read.html">read()</a></i>.</dl><p>The<i>ioctl()</i>function with the I_SRDOPT command will fail if:<dl compact><dt>[EINVAL]<dd>The <i>arg</i> argument is not valid.</dl><p><dt>I_GRDOPT<dd>Returns the current read mode setting as, described above, in an <b>int</b>pointed to by the argument <i>arg</i>.  Read modes are described in<i><a href="read.html">read()</a></i>.<p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -