netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geoffrey Lee <glee@gnupilgrims.org>
To: kuznet@ms2.inr.ac.ru
Cc: netdev@oss.sgi.com
Subject: Re: [PATCH] connect() return value.
Date: Wed, 14 Aug 2002 13:02:42 +1000	[thread overview]
Message-ID: <20020814030242.GA30872@anakin.wychk.org> (raw)
In-Reply-To: <200208140036.EAA22833@sex.inr.ac.ru>

> 
> I asked you not to do this. This is pathological case, and return
> value from this presents only academic interest.
> 
> 


Burk.  Sorry for that error.


> > We find the errno after the first connect is indeed EINPROGRESS. A 
> > read with 0 length returns -1, with an errno of 134. That corresponds
> > to ENOTCONN on Solaris.
> 
> F.e. if Solaris behaves in this way on normal not-nil read/write,
> it is fatally buggy. I do not understand why it works after this,
> just by plain luck.
> 
> read/write on not-yet-connected socket can only block (when blocking)
> or return EAGAIN otherwise. Well, or complete sucessfully.
>


Ok, let's try again.

Same OS, same conditions same program used, but this time we read and
write with a count of 1.


OSF1 4.0:

It seems even with a non-nil write it is very anti-social and returns
different error codes.

For read it returns -EWOULDBLOCK, while for write it returns -ENOTCONN.
On OSF1, the errno EWOULDBLOCK is the same as EAGAIN.

It looks like for socket reads and writes, OSF1 does the sanity
checks for read and write in a different order. This is a bug.


SunOS 5.6:

-ENOTCONN for both a read and write of 1 byte count.



Linux 2.4.18:

-EAGAIN in both read and write of one byte.



As you said that the fact that Solaris works at all with those semantics
is pure luck, so we try to understand it a bit better. We modify the program
further, and after the connection succeeds, we read some data and we print it
out.

For the write case, we use a simple `echo' server and write some data to
the server and read back from it, and see that it is ok. We sleep for a 
amount of time between the second connect call and the read / write call
to give it ample time for the 3 way handshake to complete. As a control
the same tests is done across all 3 operating systems.


We first start the server and telnet to it and make sure that it works
alright. We verify that this is true. We also start the server on the 
same computer to rule out endianness problems.


SunOS 5.6:

read case is ok.
write case is ok.

OSF1 4.0:

read case is ok.
write case is ok.

Linux 2.4.18:

read case is ok.
write case is ok.


So SunOS with -ENOTCONN semantics work. So does OSF1, but we note write
returns -ENOTCONN.

So if you say that it is indeed a bug, then both SunOS and OSF1 are
lucky.

But now that we have determined that is is not portable to use a read or 
a write to test if a non-blocking socket is connected or not, I'd like 
to hear your reasons why a read or a write returning -ENOTCONN is a
buggy behavior.



	-- G.
	

  reply	other threads:[~2002-08-14  3:02 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-10 10:24 [PATCH] connect() return value Geoffrey Lee
2002-08-11 20:46 ` kuznet
2002-08-11 23:25   ` Geoffrey Lee
2002-08-12  1:28     ` kuznet
2002-08-13  2:21       ` Geoffrey Lee
2002-08-13  4:44         ` kuznet
2002-08-13  5:37           ` Geoffrey Lee
2002-08-13 10:17             ` kuznet
2002-08-13 11:34               ` Geoffrey Lee
2002-08-13 13:47                 ` kuznet
2002-08-13 14:32                   ` Geoffrey Lee
2002-08-13 15:28                     ` kuznet
2002-08-13 23:51                       ` Geoffrey Lee
2002-08-14  0:36                         ` kuznet
2002-08-14  3:02                           ` Geoffrey Lee [this message]
2002-08-14  4:16                             ` kuznet
2002-08-14  4:57                               ` Geoffrey Lee
2002-08-14 17:25                                 ` kuznet
2002-08-15  3:25                                   ` glee
2002-08-15  3:15                                     ` David S. Miller
2002-08-15 11:02                                       ` Geoffrey Lee
2002-08-15 21:23                                         ` David S. Miller
2002-08-16  1:08                                           ` Geoffrey Lee

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=20020814030242.GA30872@anakin.wychk.org \
    --to=glee@gnupilgrims.org \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=netdev@oss.sgi.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 NNTP newsgroup(s).