X-Recipient: archive-cygwin AT delorie DOT com 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 Subject: Socket: non-blocking connect and getsockopt SO_ERROR From: Jacob Eiler Reply-To: jacob DOT eiler AT apide DOT com To: cygwin AT cygwin DOT com Content-Type: text/plain; charset="UTF-8" Date: Mon, 16 May 2011 14:43:19 +0200 Message-ID: <1305549799.2447.40.camel@flander> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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 DOT eiler AT apide DOT 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