apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From INOUE Seiichiro <in...@ariel-networks.com>
Subject Re: recv blocking when nonblock is set
Date Wed, 08 Oct 2003 12:41:57 GMT
> 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 <inoue@ariel-networks.com>
  http://www.ariel-networks.com

Mime
View raw message