You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Justin Kirby <ju...@openaether.org> on 2003/10/08 03:04:43 UTC
recv blocking when nonblock is set
Basically the problem is this (in psuedo code)
create socket
set APR_SO_NONBLOCK
connect to server
recv <-- this blocks.
I was under the impression that by setting APR_SO_NONBLOCK that recv and
send functions would not block and return immediately if there was no
data available.
I saw a post suggesting a send call is required before recv so it won't
block, so I tried that. recv will still block after a write.
Am I missing something?
Justin
Re: recv blocking when nonblock is set
Posted by David Reid <da...@jetnet.co.uk>.
We accept patches for documentation :)
david
> > Basically the problem is this (in psuedo code)
> >
> > create socket
> > set APR_SO_NONBLOCK
> > connect to server
> > recv <-- this blocks.
>
>
> I was also confused, and I checked how blocking/non-blocking socket work.
> My understanding is that it depends on the combination of APR_SO_NONBLOCK
and APR_SO_TIMEOUT,
> and it depends on the OS.
>
>
> Unix (I checked only GNU/Linux)
> -------------------------------
> APR_SO_NONBLOCK=off
> APR_SO_TIMEOUT=0 : non-block
> APR_SO_TIMEOUT=-1 : block forever (internally, wait in read(2))
> APR_SO_TIMEOUT>0 : block for the time
>
> APR_SO_NONBLOCK=on
> APR_SO_TIMEOUT=0 : non-block
> APR_SO_TIMEOUT=-1 : block forever (internally, wait in poll(2))
> APR_SO_TIMEOUT>0 : block for the time
>
>
> Windows
> -------
> APR_SO_NONBLOCK=off
> APR_SO_TIMEOUT=0 : block forever
> APR_SO_TIMEOUT=-1 : block forever
> APR_SO_TIMEOUT>0 : block for the time
>
> APR_SO_NONBLOCK=on
> APR_SO_TIMEOUT=0 : non-block
> APR_SO_TIMEOUT=-1 : non-block
> APR_SO_TIMEOUT>0 : non-block
>
>
> FYI,
> The default values are APR_SO_NONBLOCK=0(off) and APR_SO_TIMEOUT=-1.
>
>
> As a result, my suggestion is as follows,
> To create a non-blocking socket:
> APR_SO_NONBLOCK=on && APR_SO_TIMEOUT=0
>
> To create a blocking(timer) socket:
> APR_SO_NONBLOCK=off && APR_SO_TIMEOUT>0
>
>
> I wish these features were documented.
>
>
> - INOUE Seiichiro <in...@ariel-networks.com>
> http://www.ariel-networks.com
>
Re: recv blocking when nonblock is set
Posted by INOUE Seiichiro <in...@ariel-networks.com>.
> Basically the problem is this (in psuedo code)
>
> create socket
> set APR_SO_NONBLOCK
> connect to server
> recv <-- this blocks.
I was also confused, and I checked how blocking/non-blocking socket work.
My understanding is that it depends on the combination of APR_SO_NONBLOCK and APR_SO_TIMEOUT,
and it depends on the OS.
Unix (I checked only GNU/Linux)
-------------------------------
APR_SO_NONBLOCK=off
APR_SO_TIMEOUT=0 : non-block
APR_SO_TIMEOUT=-1 : block forever (internally, wait in read(2))
APR_SO_TIMEOUT>0 : block for the time
APR_SO_NONBLOCK=on
APR_SO_TIMEOUT=0 : non-block
APR_SO_TIMEOUT=-1 : block forever (internally, wait in poll(2))
APR_SO_TIMEOUT>0 : block for the time
Windows
-------
APR_SO_NONBLOCK=off
APR_SO_TIMEOUT=0 : block forever
APR_SO_TIMEOUT=-1 : block forever
APR_SO_TIMEOUT>0 : block for the time
APR_SO_NONBLOCK=on
APR_SO_TIMEOUT=0 : non-block
APR_SO_TIMEOUT=-1 : non-block
APR_SO_TIMEOUT>0 : non-block
FYI,
The default values are APR_SO_NONBLOCK=0(off) and APR_SO_TIMEOUT=-1.
As a result, my suggestion is as follows,
To create a non-blocking socket:
APR_SO_NONBLOCK=on && APR_SO_TIMEOUT=0
To create a blocking(timer) socket:
APR_SO_NONBLOCK=off && APR_SO_TIMEOUT>0
I wish these features were documented.
- INOUE Seiichiro <in...@ariel-networks.com>
http://www.ariel-networks.com