apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakob Praher <jakob.pra...@dynatrace.com>
Subject apr_socket_connect
Date Wed, 12 Apr 2006 08:43:22 GMT
hi all,

apparently I have a strange problem with apr_socket_connect, when 
calling it several times within a short time period, it turns out to 
return APR_SCUCESS without actually succeeded in connect( )ing!

After some research I found out, that on my machine (SUSE Linux 9.3, 
uname=2.6.11.4-21.11-smp), the section of problem is the call to 
getsockopt( ... SO_ERROR ... ) because:

after that:
- error is 0
- rc = 0
- errno is 115

normally error would not be 0 and therefore the block would exit with
if (error) {
	return error;
}

but since it getsockopt( ) fills in &error with 0 the flow continues 
past the next guard:

if (rc == -1 && errno != EISCONN) {
	return errno;
}

and eventually returns APR_SUCCESS!!!

My question is:
Do you know if this is a bug in the SUSE maintained kernel. *Can* 
getsockopt, according to its definition, behave like this, if connect( ) 
was not successful?

SOLUTION:

I would definitely keep the old rc when checking  calling getsockopt. 
This would lead to a more pessimistic error detection and would not 
render apr_socket_connect( ) falsly returning APR_SUCCESS without a 
connection as in my case!

For instance the following change:

1 : #ifdef SO_ERROR
2 :        {
3 :            	int error;
4 :	    	int rc_sockopt = rc;
5 :            	apr_socklen_t len = sizeof(error);
6 :            	if ((rc_sockopt = getsockopt(sock->socketdes,
7 :			SOL_SOCKET, SO_ERROR,
8 :                                 (char *)&error, &len)) < 0) {
9 :                return errno;
10:            	}
11:		if (error) {
12:               	return error;
13:            	}
14:        }
15: #endif /* SO_ERROR */

line 4,5 use a rc_sockopt instead of overwriting the outer rc. This 
would leave the final check to return the errno,

if (rc == -1 && errno != EISCONN) {
     return errno;
}

thanks in advance
-- Jakob


Mime
View raw message