Re: Problem to read on a serial port
From: Geoff Clare (geoff_at_clare.See-My-Signature.invalid)
Date: 03/31/05
- Next message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read on a serial port"
- Previous message: Andrew Torda: "buffer/vm cache, turn off for a specific file ?"
- In reply to: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read on a serial port"
- Next in thread: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read on a serial port"
- Reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read on a serial port"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 31 Mar 2005 14:01:23 +0100
Jens.Toerring@physik.fu-berlin.de wrote, on Thu, 31 Mar 2005:
> What do you think about the
>
> fcntl(fd, F_SETFL, 0);
>
> Wouldn't that also clear out other flags than O_NDELAY, which
> might have unintended effects (at least I don't know if there's
> a consensus between systems which flags exist at all and which
> get influenced by fcntl())? So, shouldn't one use e.g.
>
> fcntl(fd, F_SETFL, fcntl( fd, F_GET_FL ) & ~ O_NDELAY );
>
> to explicitely only reset the non-delay flag?
In the general case the get-and-set method should always be used.
According to POSIX fcntl(fd, F_SETFL, 0) would turn off O_APPEND,
O_NONBLOCK, O_SYNC, O_DSYNC and O_RSYNC if any of them were set.
Implementations could also have additional non-standard flags for
use with fcntl F_[GS]ETFL (such as O_NDELAY) which would be
turned off if they were set.
However, if you know for sure that other flags were not set when
the fd was opened, and have not been set since, then
fcntl(fd, F_SETFL, 0) should work fine to turn off only the
flags you know are set.
> Also, I didn't find
> 'FNDELAY' in POSIX, so wouldn't it be better to use O_NDELAY? Or
> is there some magic involved with the use of 'FNDELAY'?
Neither FNDELAY nor O_NDELAY are in POSIX. It is best to use
O_NONBLOCK.
> Another thing I am not sure about is what read() is supposed to
> return in non-blocking mode when no data are available. Is it
> really true that read() should return 0 in that case and not -1
> with errno being set to EAGAIN?
The zero return is the historical behaviour with O_NDELAY, and the
fact that it is broken-by-design (because it can't be distinguished
from EOF) is the reason POSIX invented O_NONBLOCK to replace O_NDELAY.
When O_NONBLOCK is used read() must indicate that no data are
available by returning -1 and setting errno to EAGAIN.
-- Geoff Clare <netnews@gclare.org.uk>
- Next message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read on a serial port"
- Previous message: Andrew Torda: "buffer/vm cache, turn off for a specific file ?"
- In reply to: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read on a serial port"
- Next in thread: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read on a serial port"
- Reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read on a serial port"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|