Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.unix.wizards Subject: Re: TERMIO wait /no wait operation Message-ID: <30145@sun.uucp> Date: Tue, 6-Oct-87 14:37:36 EDT Article-I.D.: sun.30145 Posted: Tue Oct 6 14:37:36 1987 Date-Received: Fri, 9-Oct-87 06:45:02 EDT References: <403@acp.OZ> Sender: news@sun.uucp Lines: 93 Keywords: TERMIO ICANON TIMEOUT > Reading the unix system V.2 and V.3 manuals, I see that > if ICANON is not set then a read will return an TIME 10ths > of a second or when MIN characters are available. > I cannot however see how to get it to sit indefinitly > and wait for a character. Is this feature (timeouts) only > available if the O_NDELAY flag is set in the file or > is it always operational. It is always operational (as long as ICANON is not set). > Is this feature used widely? I don't know. There are really two separate timeout features: 1) If MIN is non-zero, the timer is (re)started every time a character arrives; if the timer expires before a character arrives, the processes waiting on a "read" are woken up and a "read" will complete. If TIME is zero, there is no timer, and no timeout will occur. 2) If MIN is zero, the timer is started when the "read" is done; if the timer expires before a character arrives, the processes waiting on a "read" are woken up and a "read" will complete, returning 0 bytes. If TIME is zero, there is no timer, and the read will always terminate immediately - in effect, this is an alternate form of no-delay read. The second timeout feature was not present in System III; my suspicion is that somebody thought it should have been, and changed the tty driver in System V to add it. Given that it wasn't in System III, and given that you can implement timeouts of 1 second or greater using "alarm", I have no idea who actually uses it. > Does anybody know of documentation that is clear on > this point? It depends on your definition of "clear". The SVID has a long section describing the way MIN and TIME work; I believe it was derived from the description in a POSIX draft (I think the POSIX description antedated the SVID description, but it may have been the other way around). As such, it reads like a standard, rather than like a tutorial. All the information is there, it may just be hard to retrieve. > (for instance to find out how to stop fork/exit from creating zombies, > you have to look under SIGNAL of all places!)(flame off) It makes sense to put it there, as long as you grant that it makes sense to implement this feature with the "signal" system call; the latter is the problem. Overloading the meaning of SIG_IGN in that fashion is a bit tacky. > Several items I would like to find out are: > 1/ what is the exact configuration of termio needed > give the standard RAW mode under sysV. Turn IGNBRK, BRKINT, IGNPAR, PARMRK, INPCK, ISTRIP, INLCR, IGNCR, ICRNL, IUCLC, and IXON off in the "c_iflag" field. Turn OPOST off in the "c_oflag" field. Set the CSIZE subfield of the "c_cflag" field to CS8, and turn off PARENB. Turn off ISIG, ICANON, and XCASE in the "c_lflag" field. Set c_cc[VMIN] to 1, and c_cc[VTIME] to 0. (You can try other settings of MIN and TIME, as long as MIN is non-zero; a larger VMIN can increase the chances of getting more than one character per "read", and thus decrease the number of "read" calls issued.) > 2/ is there a similar timeout facility available > for pipes or do i HAVE to use ALARM/SIGNAL etc? You have to use "alarm"/"signal". > 4/ does a value of 255 or something disable the TIMEOUT in the > affore mentioned TERMIO ~ICANON mode ? No, a value of 0 does. See above. > This is how I see it at the moment.. could someone give me > some idea what REALLY HAPPENS? > if you want immediate return, use the O_NDELAY flag with fcntl() or a MIN and TIME of 0 (please don't say "c_cc[5]", say "c_cc[VTIME]" or just "TIME"; most of us haven't memorized the indices in "c_cc"). > if you want to wait indefinitly, use c_cc[5] = 0 in ioclt with > O_NDELAY not active. As long as MIN is non-zero; if MIN is zero, as well as TIME, you will get an immediate return. > if you want n 10ths timeout, use c_cc[5] = n in ioctl() with > O_DELAY inactive. Yes, depending on the sort of timeout you want. The value of MIN selects the type of timeout. Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com