Re: Problem to read on a serial port
Jens.Toerring_at_physik.fu-berlin.de
Date: 03/31/05
- Next message: Chuck Dillon: "Re: Unix compiling and linking options"
- Previous message: Geoff Clare: "Re: Problem to read on a serial port"
- In reply to: Geoff Clare: "Re: Problem to read on a serial port"
- Next in thread: collinm: "Re: Problem to read on a serial port"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 31 Mar 2005 13:28:54 GMT
Geoff Clare <geoff@clare.see-my-signature.invalid> wrote:
> 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.
Thanks for the clarification! I actually always was wondering WTF
the difference between O_NDELAY and O_NONBLOCK is supposed to be
and started to think of them as the same thing. So you may have
spared me some future trouble;-)
Regards, Jens
-- \ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de \__________________________ http://www.toerring.de
- Next message: Chuck Dillon: "Re: Unix compiling and linking options"
- Previous message: Geoff Clare: "Re: Problem to read on a serial port"
- In reply to: Geoff Clare: "Re: Problem to read on a serial port"
- Next in thread: collinm: "Re: Problem to read on a serial port"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|