From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2765 invoked by alias); 16 May 2011 12:43:36 -0000 Received: (qmail 2757 invoked by uid 22791); 16 May 2011 12:43:35 -0000 X-SWARE-Spam-Status: No, hits=4.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from csmtp2.one.com (HELO csmtp2.one.com) (91.198.169.22) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 16 May 2011 12:43:21 +0000 Received: from [192.168.0.115] (4405ds5-vbr.0.fullrate.dk [90.184.142.22]) by csmtp2.one.com (Postfix) with ESMTPA id E29DD3080275 for ; Mon, 16 May 2011 12:43:19 +0000 (UTC) Subject: Socket: non-blocking connect and getsockopt SO_ERROR From: Jacob Eiler Reply-To: jacob.eiler@apide.com To: cygwin@cygwin.com Content-Type: text/plain; charset="UTF-8" Date: Mon, 16 May 2011 12:43:00 -0000 Message-ID: <1305549799.2447.40.camel@flander> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes 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/msg00232.txt.bz2 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. BR Jacob -- Jacob Eiler Apide ApS e: jacob.eiler@apide.com t: +45 2374 0486 w: apide.com -- 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