From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13407 invoked by alias); 16 May 2011 13:29:21 -0000 Received: (qmail 13195 invoked by uid 22791); 16 May 2011 13:28:53 -0000 X-Spam-Check-By: sourceware.org Received: from aquarius.hirmke.de (HELO calimero.vinschen.de) (217.91.18.234) by sourceware.org (qpsmtpd/0.83/v0.83-20-g38e4449) with ESMTP; Mon, 16 May 2011 13:28:38 +0000 Received: by calimero.vinschen.de (Postfix, from userid 500) id 711B92C00B8; Mon, 16 May 2011 15:28:35 +0200 (CEST) Date: Mon, 16 May 2011 13:29:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: Socket: non-blocking connect and getsockopt SO_ERROR Message-ID: <20110516132835.GG5248@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <1305549799.2447.40.camel@flander> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1305549799.2447.40.camel@flander> User-Agent: Mutt/1.5.21 (2010-09-15) Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2011-05/txt/msg00233.txt.bz2 On May 16 14:43, Jacob Eiler wrote: > Hi. > > I am experiencing an issue with getsockopt when running an application > under CygWin. > > The application (Kannel sms gateway) creates a new socket, attempt to > connect non-blocking to the other host and later calls getsockopt to > check for errors: > > s = socket(PF_INET, SOCK_STREAM, 0); > ... > flags = fcntl(s, F_GETFL, 0); > fcntl(s, F_SETFL, flags | O_NONBLOCK); > ... > connect(s, &addr, sizeof(addr)) > > connect returns EINPROGRESS and the application has a polling thread > setup to handle timeout and check for changes. In both cases a callback > function is invoked. > > The callback function checks the connection by calling > > getsockopt(s, SOL_SOCKET, SO_ERROR, &err, &len) > > but it returns 0 and no error - even if the connection was never > established. Subsequently the application tries to write data to the > socket - which fails with a "transport endpoint is not connected" error. > > The code works just fine on Linux with getsockopt returning an error. > Any pointer on how to get this working will be greatly appreciated. Use select. I'm not sure the underlying Winsock implementation sets the SO_ERROR value in the same way as on Linux. Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Project Co-Leader cygwin AT cygwin DOT com Red Hat -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple