You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Jacob Craig Lewallen <jl...@cs.ucr.edu> on 2003/05/28 22:17:50 UTC

[PATCH] Socket timeouts and APR_SO_NONBLOCK?

	I mentioned this a few months ago and she seems to have fallen through 
the cracks... or I'm mistaken and nobody told me... I'm using the 
apr_socket_timeout_set call to set a timeout on a socket and then using 
the same call to turn the timeout off again after I've established a 
connection. There seems to be a small problem with the flag management 
in this process.

	Basically, APR, as expected, makes the socket non blocking to handle 
the timeouts. When I turn off the timeouts, it fails to clear the flag 
from the socket's file descriptor because the code never sets the 
APR_SO_NONBLOCK flag in the APR socket's netmask. For example, the 
socket is properly returned to blocking if I set the socket to non 
blocking myself and then turn on the timeout and then turn it back off. 
This works because APR_SO_NONBLOCK is being set explicitly by me. I've 
included a patch that will set APR_SO_NONBLOCK when APR makes a socket 
non blocking behind the scenes to handle timeouts, it's very simple, 
trust me.

	Does this make sense?

--
jacob lewallen
jlewalle@cs.ucr.edu

Re: [PATCH] Socket timeouts and APR_SO_NONBLOCK?

Posted by Jeff Trawick <tr...@attglobal.net>.
I've committed your changes and some more of my own, so this would be a 
great time to make sure everything still works :)

Thanks again for your efforts,

Jeff


Re: [PATCH] Socket timeouts and APR_SO_NONBLOCK?

Posted by Jacob Craig Lewallen <jl...@cs.ucr.edu>.
Jeff Trawick wrote:
> 
> Looking at things again, perhaps before injesting enough caffeine, it 
> looks like there are other bogosities w.r.t. timeouts that perhaps hid 
> the bug from me for my particular testcase.  I see various places where 
> we think that sock->timeout != 0 means there is a timeout in place, when 
> a check via apr_is_option_set(sock->netmask, APR_SO_TIMEOUT) is the 
> proper thing to do.

	Ok, I see.. yeah the only code I really focused on was that one function.

> 
> I now see that your patch needs to be committed, but for the short term 
>  I'd like to explore some other bogosities.
> 
> Thanks for hanging in there!
> 

	Ok, I've recompiled and tested with the new changes and things seem to 
be working fine (for the past couple hours). I'll drop a line if 
anything surfaces later. Hey, and thanks for the timely resolution.

--
jacob lewallen
jlewalle@cs.ucr.edu


Re: [PATCH] Socket timeouts and APR_SO_NONBLOCK?

Posted by Jeff Trawick <tr...@attglobal.net>.
Jacob Lewallen wrote:
> Jeff Trawick wrote:
> 
>> Jacob Craig Lewallen wrote:
>>
>>
>> I assume that your app did
>>
>>   apr_socket_timeout_set(sock, 0)
>>
>> to clear the timeout?
> 
> 
>     Actually I am passing -1, which does "clear" the timeouts. 
> Unfortunately the socket is still non blocking. . .  If you look in 
> sockopt.c on line 133 you'll see a call to apr_is_option_set, checking 
> for APR_SO_NONBLOCK. My problem is, this never gets set when it DOES 
> make the socket non blocking in the first call to timeout_set and so the 
> socket is never returned to blocking even if you do pass -1. In other 
> words, on the first call on a blocking socket it'll check for NONBLOCK, 
> fail, and set the socket to be non blocking, but never set the 
> APR_SO_NONBLOCK flag to reflect this. Or am I just being dense?

No, you're not being dense.

To be honest, I thought your previous note was clear about the bug but 
then when I went to try it empirically I couldn't reproduce it.  Then I 
wondered if you had passed the right value to apr_socket_timeout_set() :)

Looking at things again, perhaps before injesting enough caffeine, it 
looks like there are other bogosities w.r.t. timeouts that perhaps hid 
the bug from me for my particular testcase.  I see various places where 
we think that sock->timeout != 0 means there is a timeout in place, when 
a check via apr_is_option_set(sock->netmask, APR_SO_TIMEOUT) is the 
proper thing to do.

I now see that your patch needs to be committed, but for the short term 
  I'd like to explore some other bogosities.

Thanks for hanging in there!


Re: [PATCH] Socket timeouts and APR_SO_NONBLOCK?

Posted by Jacob Lewallen <jl...@cs.ucr.edu>.
Jeff Trawick wrote:
> Jacob Craig Lewallen wrote:
> 
> 
> I assume that your app did
> 
>   apr_socket_timeout_set(sock, 0)
> 
> to clear the timeout?

	Actually I am passing -1, which does "clear" the timeouts. 
Unfortunately the socket is still non blocking. . .  If you look in 
sockopt.c on line 133 you'll see a call to apr_is_option_set, checking 
for APR_SO_NONBLOCK. My problem is, this never gets set when it DOES 
make the socket non blocking in the first call to timeout_set and so the 
socket is never returned to blocking even if you do pass -1. In other 
words, on the first call on a blocking socket it'll check for NONBLOCK, 
fail, and set the socket to be non blocking, but never set the 
APR_SO_NONBLOCK flag to reflect this. Or am I just being dense?

--
jacob lewallen
jlewalle@cs.ucr.edu


Re: [PATCH] Socket timeouts and APR_SO_NONBLOCK?

Posted by Jeff Trawick <tr...@attglobal.net>.
Jacob Craig Lewallen wrote:
>     I mentioned this a few months ago and she seems to have fallen 
> through the cracks... or I'm mistaken and nobody told me... I'm using 
> the apr_socket_timeout_set call to set a timeout on a socket and then 
> using the same call to turn the timeout off again after I've established 
> a connection. There seems to be a small problem with the flag management 
> in this process.
> 
>     Basically, APR, as expected, makes the socket non blocking to handle 
> the timeouts. When I turn off the timeouts

I assume that your app did

   apr_socket_timeout_set(sock, 0)

to clear the timeout?

That is expected to leave your socket non-blocking.

To really turn off the timeouts, you need to do

   apr_socket_timeout_set(sock, -1)

I just hacked up apr/test/client.c to try your testcase.  With timeout 
parameter of 0, I see what you see.  With timeout parameter of -1, it 
works as expected.

I'll update the doc for apr_socket_timeout_set() to clarify that

timeout > 0:  read and write calls return APR_TIMEUP if specified time 
elapsess without making progress on the read or write request

timeout == 0: read and write calls never block

timeout < 0: read and write calls block