public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Jacob Eiler <jacob.eiler@apide.com>
To: cygwin@cygwin.com
Subject: Socket: non-blocking connect and getsockopt SO_ERROR
Date: Mon, 16 May 2011 12:43:00 -0000	[thread overview]
Message-ID: <1305549799.2447.40.camel@flander> (raw)

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

             reply	other threads:[~2011-05-16 12:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-16 12:43 Jacob Eiler [this message]
2011-05-16 13:29 ` Corinna Vinschen
2011-05-17 14:20 ` Brian Ford

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1305549799.2447.40.camel@flander \
    --to=jacob.eiler@apide.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).