public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* connect() to localhost non-blocking.
@ 2001-10-21 20:42 Patrick Mau
  2001-10-21 21:00 ` Doug McNaught
  0 siblings, 1 reply; 4+ messages in thread
From: Patrick Mau @ 2001-10-21 20:42 UTC (permalink / raw)
  To: Linux Kernel

Hallo all,

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 ?

thanks for your answers,
Patrick

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: connect() to localhost non-blocking.
  2001-10-21 20:42 connect() to localhost non-blocking Patrick Mau
@ 2001-10-21 21:00 ` Doug McNaught
  0 siblings, 0 replies; 4+ messages in thread
From: Doug McNaught @ 2001-10-21 21:00 UTC (permalink / raw)
  To: Patrick Mau; +Cc: Linux Kernel

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. 

-Doug
-- 
Let us cross over the river, and rest under the shade of the trees.
   --T. J. Jackson, 1863

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: connect() to localhost non-blocking.
@ 2001-10-21 23:18 Dan Kegel
  2001-10-22 15:49 ` Patrick Mau
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Kegel @ 2001-10-21 23:18 UTC (permalink / raw)
  To: linux-kernel@vger.kernel.org

> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: connect() to localhost non-blocking.
  2001-10-21 23:18 Dan Kegel
@ 2001-10-22 15:49 ` Patrick Mau
  0 siblings, 0 replies; 4+ messages in thread
From: Patrick Mau @ 2001-10-22 15:49 UTC (permalink / raw)
  To: Dan Kegel; +Cc: Linux Kernel

On Sun, Oct 21, 2001 at 04:18:10PM -0700, Dan Kegel wrote:
> > Patrick Mau <mau@oscar.prima.de> writes:
> > 

[Snip]

> 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

Hallo Dan,

thnaks for the pointer and your remarks, but I really
wondered if linux _never_ immediatly accept()'s connections.

I never saw a connect() call returning 0 (connected) on a
non-blocking socket. Always EINPROGRESS. I guess I have to
look at the kernel to see scheduling effects ...

thanks,
Patrick

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-10-22 15:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-10-21 20:42 connect() to localhost non-blocking Patrick Mau
2001-10-21 21:00 ` Doug McNaught
  -- strict thread matches above, loose matches on Subject: below --
2001-10-21 23:18 Dan Kegel
2001-10-22 15:49 ` Patrick Mau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox