Re: Blocking read() from a USB->Serial adapter.



Grant Edwards <grante@xxxxxxxx> wrote:
On 2006-11-25, Floyd L. Davidson <floyd@xxxxxxxxxx> wrote:

Or until the driver decides to return for whatever reason it
chooses. On success, you're guaranteed a minimum of one byte.

Maybe. (Maybe not too!)

There's the case where the file is at EOF. Is there another
case where read() will return success with 0 bytes?

Any time there is no data available. With a file that will
indeed set the EOF flag, but with a serial port (or a pipe, or a
console) there is no such concept.

Sure there is. The tty line discipline will generate an "EOF"
condition and return 0 bytes when it sees the EOF character
(typically ctrl-d) as the first byte after read() is called.

Okay, but that is actually just a manufactured work around to
simulate it, not an EOF condition. And it only exists for
specified circumstances (icanon?? tty line discipline?? I'm
not sure when it is or isn't there).

If the timer is enabled, and times out, read() will return 0.

You're right. I thought it returned with an ETIMEDOUT error,
but I was probably thinking of a different OS.

If the O_NONBLOCK flag is set, then it sets EAGAIN. But nothing
for blocking reads when the VTIME expires.

Another possibility is if the number of bytes request was 0,
read() will return 0.

Yup -- I forgot about that.

I had to go look all of this up... Anymore, I don't remember
anything except where to start searching... ;-)

--
Floyd L. Davidson <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@xxxxxxxxxx
.



Relevant Pages

  • Re: Blocking read() from a USB->Serial adapter.
    ... On success, you're guaranteed a minimum of one byte. ... There's the case where the file is at EOF. ... condition and return 0 bytes when it sees the EOF character ... (typically ctrl-d) ...
    (comp.os.linux.development.apps)
  • Re: Blocking read() from a USB->Serial adapter.
    ... On success, you're guaranteed a minimum of one byte. ... There's the case where the file is at EOF. ... and errno is set appropriately. ... Intesting -- I didn't know that either. ...
    (comp.os.linux.development.apps)
  • Re: which functions set the end-of-file indicator?
    ... everyone agreed that it's possible for EOF to be a valid byte. ... It is, however, trivial to convert EOF into an unsigned char. ... As they take an int expression for their first arguments, ... s) == SUCCESS) return ch; ...
    (comp.lang.c)
  • Re: which functions set the end-of-file indicator?
    ... everyone agreed that it's possible for EOF to be a valid byte. ... It is, however, trivial to convert EOF into an unsigned char. ... As they take an int expression for their first arguments, ... s) == SUCCESS) return ch; ...
    (comp.lang.c)
  • Re: EOF question
    ... The program should read input characters until it hits an EOF ... How that EOF condition is triggered is system-specific. ... should be able to trigger and EOF by entering control-Z on a line by ...
    (comp.lang.c)