public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Kegel <dank@kegel.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: connect() to localhost non-blocking.
Date: Sun, 21 Oct 2001 16:18:10 -0700	[thread overview]
Message-ID: <3BD357B2.12AE9A5E@kegel.com> (raw)

> Patrick Mau <mau@oscar.prima.de> writes:
> 
> > I wrote a little test program to do some poll() benchmarks.
> > I changed the host address to localhost and observed that
> > connect() always returns EINPROGRESS when used with non-blocking
> > sockets.
> > 
> > >From the man page:
> > 
> > EINPROGRESS
> >  The socket is non-blocking and the connection cannot be completed
> >  immediately. It is possible to select(2) or poll(2) for completion by
> >  selecting the socket for writing.
> > 
> > So my question is:
> > 
> > What is meant by 'cannot be completed immediately' ?
> > I thought that connections to localhost would complete
> > without any delay when the application listens ?
> 
> Probably the accept()ing process hasn't been scheduled yet.
> EINPROGRESS is a perfectly reasonable response in such a case. 

You have to be prepared to handle both immediate and delayed
connection, especially if you want to be portable.  (Solaris behaves 
a bit differently than Linux in this regard.)  See
http://www.kegel.com/dkftpbench/dkftpbench-0.37/ftp_client_pipe.cc
for an example of how to handle nonblocking connects more or less portably.
(You have to wade through quite a bit of code, tabstops 4, to find
all the connect-handling stuff -- sorry.)
- Dan

             reply	other threads:[~2001-10-21 23:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-21 23:18 Dan Kegel [this message]
2001-10-22 15:49 ` connect() to localhost non-blocking Patrick Mau
  -- strict thread matches above, loose matches on Subject: below --
2001-10-21 20:42 Patrick Mau
2001-10-21 21:00 ` Doug McNaught

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=3BD357B2.12AE9A5E@kegel.com \
    --to=dank@kegel.com \
    --cc=linux-kernel@vger.kernel.org \
    /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