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

📄 termios.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
📖 第 1 页 / 共 4 页
字号:
whole line at once;any numberof bytes, even one, may be requested in a<i><a href="../xsh/read.html">read()</a></i>without losing information.<p>If {MAX_CANON} is defined for this terminal device, it isa limit on the number of bytes in a line.The behaviourof the system when this limitis exceeded is implementation-dependent.If {MAX_CANON} isnot defined, there is no suchlimit;see<i><a href="../xsh/pathconf.html">pathconf()</a></i>.<p>Erase and kill processing occur wheneither of two special characters, the ERASE andKILL characters (see<xref href=specchar><a href="#tag_008_001_009">Special Characters</a></xref>),is received.This processing affectsdata in the input queue thathas not yet been delimited by a newline (NL), EOF or EOLcharacter.This un-delimited data makes upthe current line.The ERASE characterdeletes the last character in thecurrent line, if there is one.The KILL character deletesall data in the current line,if there are any.The ERASE and KILL characters have noeffect if there is no datain the current line.The ERASE and KILL characters themselvesare not placed in the inputqueue.<h4><a name = "tag_008_001_007">&nbsp;</a>Non-canonical Mode Input Processing</h4><xref type="3" name="noncanon"></xref>In non-canonical mode input processing, inputbytes are not assembled into lines, anderase and kill processing does notoccur.The values of the MIN and TIME members ofthe<b>c_cc</b>array are usedto determine how to process the bytes received.The ISO&nbsp;POSIX-1 standard does not specify whether the setting of O_NONBLOCK takesprecedence over MIN or TIME settings.Therefore, if O_NONBLOCK is set,<i><a href="../xsh/read.html">read()</a></i>may return immediately, regardless of the setting of MIN or TIME.Also, if no data is available,<i><a href="../xsh/read.html">read()</a></i>may either return 0, or return -1 with<i>errno</i>set to [EAGAIN].<p>MIN represents the minimum number ofbytes that should be received when the<i><a href="../xsh/read.html">read()</a></i>function returns successfully.TIME is atimer of 0.1 second granularity that is used totime out bursty and short-term data transmissions.If MIN is greater than {MAX_INPUT},the response to the request isundefined.The four possible values for MINand TIME and their interactions aredescribed below.<h5><a name = "tag_008_001_007_001">&nbsp;</a>Case A: MIN &gt; 0, TIME &gt; 0</h5>In this case TIME serves asan inter-byte timer and is activated after the first byte isreceived.Since it is an inter-bytetimer, it is reset after a byte is received.Theinteraction between MIN and TIME is asfollows.As soon as one byte is received, theinter-byte timer is started.If MIN bytes arereceived before the inter-byte timer expires(remember that the timer is resetupon receipt of each byte), the read is satisfied.If thetimer expires before MIN bytes arereceived, the characters received to that point arereturned to the user.Note thatif TIME expires at least one byte is returned becausethe timer would not have beenenabled unless a byte was received.In this case (MIN &gt; 0,TIME &gt; 0) the read blocks untilthe MIN and TIME mechanisms are activated by thereceipt of the first byte, ora signal is received.If the data is in the buffer at the time of the<i><a href="../xsh/read.html">read()</a></i>,the result will be as if the data has been received immediatelyafter the<i><a href="../xsh/read.html">read()</a></i>.<h5><a name = "tag_008_001_007_002">&nbsp;</a>Case B: MIN &gt; 0, TIME = 0</h5>In this case, since the valueof TIME is zero, the timer plays no role and only MIN issignificant.A pending read is notsatisfied until MIN bytes are received (that is, the pendingread blocks until MIN bytesare received), or a signal is received.A program thatuses this case to read record-basedterminal I/O may block indefinitely in the readoperation.<h5><a name = "tag_008_001_007_003">&nbsp;</a>Case C: MIN = 0, TIME &gt; 0</h5>In this case, since MIN = 0,TIME no longer represents an inter-byte timer.It now servesas a read timer that isactivated as soon as the<i><a href="../xsh/read.html">read()</a></i>function is processed.A read issatisfied as soon as a singlebyte is received or the read timer expires.Note that in thiscase if the timer expires, nobytes are returned.If the timer does not expire, the onlyway the read can be satisfiedis if a byte is received.In this case the read will not blockindefinitely waiting for a byte;ifno byte is received within TIME*0.1 seconds after theread is initiated, the<i><a href="../xsh/read.html">read()</a></i>returns a value of zero, having read no data.If the data is in the buffer at the time of the<i><a href="../xsh/read.html">read()</a></i>,the timer is started as if the data has been received immediatelyafter the<i><a href="../xsh/read.html">read()</a></i>.<h5><a name = "tag_008_001_007_004">&nbsp;</a>Case D: MIN = 0, TIME = 0</h5>The minimum of either the numberof bytes requested or the number of bytes currentlyavailable is returned without waiting for more bytes to be input.If no characters are available,<i><a href="../xsh/read.html">read()</a></i>returns a value of zero, having read no data.<h4><a name = "tag_008_001_008">&nbsp;</a>Writing Data and Output Processing</h4><xref type="3" name="writedata"></xref>When a process writes one ormore bytes to a terminal device file, they are processedaccording to the<b>c_oflag</b>field (see<xref href=outmodes><a href="#tag_008_002_003">Output Modes</a></xref>).The implementation mayprovide a buffering mechanism;as such,when a call to<i><a href="../xsh/write.html">write()</a></i>completes, all of thebytes written have been scheduled fortransmission to the device, but the transmissionwill not necessarily have completed.See<i><a href="../xsh/write.html">write()</a></i>for the effects ofO_NONBLOCK on<i><a href="../xsh/write.html">write()</a></i>.<h4><a name = "tag_008_001_009">&nbsp;</a>Special Characters</h4><xref type="3" name="specchar"></xref>Certain characters have special functions oninput or output or both.These functions aresummarised as follows:<p><dl compact><dt>INTR<dd>Special character on input, which is recognised if the ISIG flag isset.Generates a SIGINT signal which is sent to all processesin the foreground process group for which the terminal isthe controlling terminal.IfISIG is set, the INTR character is discarded when processed.<dt>QUIT<dd>Special character on input, which is recognised if the ISIG flag isset.Generates a SIGQUIT signal which is sent to all processesin the foreground process group for which the terminal is thecontrolling terminal.IfISIG is set, the QUIT character is discarded when processed.<dt>ERASE<dd>Special character on input, which is recognised if the ICANON flag isset.Erases the last character in the current line;see<xref href=canon><a href="#tag_008_001_006">Canonical Mode Input Processing</a></xref>.It will not erase beyond thestart of a line, as delimited by an NL, EOF or EOL character.IfICANON is set, the ERASE character is discarded when processed.<dt>KILL<dd>Special character on input, which is recognised if the ICANON flag isset.Deletes the entire line, as delimited by an NL, EOF or EOLcharacter.If ICANON is set, the KILL character is discarded whenprocessed.<dt>EOF<dd>Special character on input, which is recognised if the ICANON flag isset.When received, all the bytes waiting to be read areimmediately passed to the process without waiting for a newline,and the EOF is discarded.Thus, if there are no bytes waiting (thatis, the EOF occurred at the beginning of a line), a byte count ofzero is returned from the<i><a href="../xsh/read.html">read()</a></i>,representing an end-of-fileindication.If ICANON is set, the EOF character is discarded whenprocessed.<dt>NL<dd>Special character on input, which is recognised if the ICANON flag isset.It is the line delimiternewline.It cannot be changed.<dt>EOL<dd>Special character on input, whichis recognised if the ICANON flag isset.It is an additional line delimiter, like NL.<dt>SUSP<dd>If theISIG flag is set, receipt of the SUSP character causes aSIGTSTP signal to be sent to all processes in the foregroundprocess group for which the terminal is thecontrolling terminal, and the SUSP characteris discarded when processed.<dt>STOP<dd>Special character onboth input and output, which is recognised if theIXON (output control) or IXOFF (input control) flag is set.Can be used to suspend outputtemporarily.It is useful with CRT terminals toprevent output from disappearing before it can be read.If IXON isset, the STOP character is discarded when processed.<dt>START<dd>Special character on both input and output, which is recognised if theIXON (output control) or IXOFF (input control) flag is set.Can be used to resumeoutput that has been suspended by a STOP character.If IXON isset, the START character is discarded when processed.<dt>CR<dd>Special character on input, which is recognised if the ICANON flag isset;it is thecarriage-return character.When ICANON and ICRNL are set and IGNCR isnot set, this character is translated into an NL, and has the sameeffect as an NL character.</dl><p>The NL and CR characters cannotbe changed.It is implementation-dependent whether theSTART and STOP characters can bechanged.The values for INTR, QUIT, ERASE, KILL,EOF, EOL and SUSPare changeable to suit individual tastes.Special character functionsassociated with changeable special control characterscan be disabled individually.<p>If two or more special charactershave the same value, the function performed when thatcharacter is received is undefined.<p>A special character is recognised notonly by its value, but also by its context;for example, animplementation may support multi-byte sequences thathave a meaning different from themeaning of the bytes when consideredindividually.Implementations may also supportadditional single-byte functions.These implementation-dependent multi-byte or single-bytefunctions are recognised only if theIEXTEN flag is set;otherwise, data is received withoutinterpretation, except as required to recognise thespecial characters defined in this section.<p>If IEXTEN is set, theERASE, KILL and EOF characters can be escaped by a preceding \character, in which case no special function occurs.<h4><a name = "tag_008_001_010">&nbsp;</a>Modem Disconnect</h4>If a modem disconnect is detectedby the terminal interface for a controlling terminal,and if CLOCAL is not setin the<b>c_cflag</b>field for the terminal (see<xref href=conmodes><a href="#tag_008_002_004">Control Modes</a></xref>),the SIGHUP signal is sentto the controlling process for which the terminal is the controllingterminal.Unless other arrangements have beenmade, this causes the controlling processto terminate (see<i><a href="../xsh/exit.html">exit()</a></i>).Anysubsequent read from the terminal device returnsthe value of zero, indicating end-of-file.(See<i><a href="../xsh/read.html">read()</a></i>.)Thus, processes that read aterminal file and test for end-of-filecan terminate appropriately after a disconnect.If the EIO condition as specified in<i><a href="../xsh/read.html">read()</a></i>also exists, it is unspecified whether on EOF condition or the[EIO] is returned.Any subsequent<i><a href="../xsh/write.html">write()</a></i>to the terminal devicereturns -1, with<i>errno</i>set to [EIO], until thedevice is closed.<h4><a name = "tag_008_001_011">&nbsp;</a>Closing a Terminal Device File</h4>The last process to close aterminal device file causes any output to be sent to thedevice and any input to bediscarded.If HUPCL is set in the control modes and thecommunications port supports a disconnect function,the terminal device will perform adisconnect.<h3><a name = "tag_008_002">&nbsp;</a>Parameters that Can be Set</h3>

⌨️ 快捷键说明

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