Return-Path: Delivered-To: apmail-apr-dev-archive@www.apache.org Received: (qmail 68986 invoked from network); 12 Apr 2006 08:50:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 12 Apr 2006 08:50:35 -0000 Received: (qmail 69927 invoked by uid 500); 12 Apr 2006 08:50:32 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 69870 invoked by uid 500); 12 Apr 2006 08:50:31 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Id: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 69858 invoked by uid 99); 12 Apr 2006 08:50:31 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Apr 2006 01:50:31 -0700 X-ASF-Spam-Status: No, hits=1.3 required=10.0 tests=RCVD_NUMERIC_HELO,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of apr-dev@m.gmane.org designates 80.91.229.2 as permitted sender) Received: from [80.91.229.2] (HELO ciao.gmane.org) (80.91.229.2) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Apr 2006 01:50:30 -0700 Received: from root by ciao.gmane.org with local (Exim 4.43) id 1FTb34-0007FM-HK for dev@apr.apache.org; Wed, 12 Apr 2006 10:50:02 +0200 Received: from 81.189.96.46 ([81.189.96.46]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 12 Apr 2006 10:50:02 +0200 Received: from jakob.praher by 81.189.96.46 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 12 Apr 2006 10:50:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: dev@apr.apache.org From: Jakob Praher Subject: apr_socket_connect Date: Wed, 12 Apr 2006 10:43:22 +0200 Lines: 68 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 81.189.96.46 User-Agent: Mozilla Thunderbird 1.0 (X11/20041207) X-Accept-Language: en-us, en Sender: news X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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