delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/10/02/17:15:23

From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: libsocket: difference between O_NONBLOCK and FIONBIO?
Date: Mon, 02 Oct 2000 21:06:36 +0100
Organization: Customer of Energis Squared
Lines: 53
Message-ID: <39D8EACB.7D8400C6@phekda.freeserve.co.uk>
References: <8r9ihm$670$16$1 AT news DOT t-online DOT com>
NNTP-Posting-Host: modem-27.argon.dialup.pol.co.uk
Mime-Version: 1.0
X-Trace: news8.svr.pol.co.uk 970520039 8367 62.136.17.27 (2 Oct 2000 20:53:59 GMT)
NNTP-Posting-Date: 2 Oct 2000 20:53:59 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Mailer: Mozilla 4.51 [en] (X11; I; Linux 2.2.14 i586)
X-Accept-Language: de,fr
CC: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hello.

Peter Remmers wrote:
> After reading a lot of documents I know of two methods to put a
> socket into nonblocking mode:
> 
> fcntl(sock, F_SETFL, O_NONBKOCK);
> 
> and
> 
> int on=1;
> ioctl(sock, FIONBIO, &on);
> 
> What exactly is the difference between the two?
> The libsocket documentation talks about "similar":

They can both be used to set non-blocking mode, as you know. However,
fcntl()'s F_SETFL will set multiple options simultaneously. You should do
something like:

    int opts;

    opts  = fcntl(sock, F_GETFL);
    opts |= O_NONBLOCK;
    if (fcntl(sock, F_SETFL, opts) < 0) {
        /* error */
    }

To remove nonblocking mode, you'd use:

    int opts;

    opts  = fcntl(sock, F_GETFL);
    opts &= ~O_NONBLOCK;
    if (fcntl(sock, F_SETFL, opts) < 0) {
        /* error */
    }

> In what way do they differ then, if they are just *similar*?
> Don't they have the same effect?

In the libsocket the fcntl() support actually goes through the ioctl()
code. fcntl(..., O_NONBLOCK) traverses the same code path as ioctl(...,
FIONBIO, ...). So they have the same effect.

Would things be clearer if the libsocket docs used 'like' instead of
'similar'? How do you think the docs could be improved?

Hope that helps, bye,

-- 
Richard Dawe
[ mailto:richdawe AT bigfoot DOT com | http://www.bigfoot.com/~richdawe/ ]

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019