public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* bug report: select on unconnected sockets
@ 2001-03-31 15:44 Radu Greab
  2001-03-31 16:15 ` john slee
  0 siblings, 1 reply; 3+ messages in thread
From: Radu Greab @ 2001-03-31 15:44 UTC (permalink / raw)
  To: linux-kernel; +Cc: radu

[-- Attachment #1: message body text --]
[-- Type: text/plain, Size: 669 bytes --]


Sorry if this is already known: on a RH 7.0 system with kernel 2.4.2
or 2.4.3, a select on an unconnected socket incorrectly says that the
socket is ready for input and output. Of course, reading from the socket
file descriptor returns -1 and errno is set to ENOTCONN as shown in
the strace output:

socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
select(4, [3], [3], [3], {0, 0})        = 2 (in [3], out [3], left {0, 0})
read(3, 0xbffff668, 1024)               = -1 ENOTCONN (Transport endpoint is not connected)

I attached a small example program to reproduce the bug.


Thanks,
Radu Greab

PS: please CC me your eventual replies as I'm not subscribed to the
list.



[-- Attachment #2: example program --]
[-- Type: text/plain, Size: 821 bytes --]

#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>

int main(int argc, char **argv) {
  fd_set rfds, wfds, efds;
  int s, rc;
  struct timeval timeout;
  char buf[1025];

  s = socket(PF_INET, SOCK_STREAM, 0);
  if (s == -1) {
    perror("couldn't create socket");
    return -1;
  }

  FD_ZERO(&rfds);
  FD_SET(s, &rfds);
  FD_ZERO(&wfds);
  FD_SET(s, &wfds);
  FD_ZERO(&efds);
  FD_SET(s, &efds);
  timeout.tv_sec = timeout.tv_usec = 0;
  rc = select(s + 1, &rfds, &wfds, &efds, &timeout);
  if (rc == -1) {
    perror("select");
    return -1;
  }
  printf("select result=%d\n", rc);
  if (FD_ISSET(s, &rfds)) {
    rc = read(s, buf, 1024);
    if (rc == -1) {
      perror("read");
      return -1;
    }
    printf("read result=%d\n", rc);
  }

  return 0;
}

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

* Re: bug report: select on unconnected sockets
  2001-03-31 15:44 bug report: select on unconnected sockets Radu Greab
@ 2001-03-31 16:15 ` john slee
  2001-03-31 16:26   ` Radu Greab
  0 siblings, 1 reply; 3+ messages in thread
From: john slee @ 2001-03-31 16:15 UTC (permalink / raw)
  To: Radu Greab; +Cc: linux-kernel

On Sat, Mar 31, 2001 at 06:44:20PM +0300, Radu Greab wrote:
> Sorry if this is already known: on a RH 7.0 system with kernel 2.4.2
> or 2.4.3, a select on an unconnected socket incorrectly says that the
> socket is ready for input and output. Of course, reading from the socket
> file descriptor returns -1 and errno is set to ENOTCONN as shown in
> the strace output:
> 
> socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
> select(4, [3], [3], [3], {0, 0})        = 2 (in [3], out [3], left {0, 0})
> read(3, 0xbffff668, 1024)               = -1 ENOTCONN (Transport endpoint is not connected)
> 
> I attached a small example program to reproduce the bug.

bleah.  which one is supposed to be right?

linux 2.4
---------
$ uname -a
Linux XXXXX 2.4.2-ac20 #8 Wed Mar 14 01:53:05 EST 2001 i686 unknown
$ ./t
select result=2
read: Transport endpoint is not connected

linux 2.2
---------
$ uname -a
Linux XXXXX 2.2.18 #1 Thu Dec 21 21:13:10 EST 2000 i586 unknown
$ ./t
select result=1

solaris
-------
$ uname -a
SunOS XXXXX 5.7 Generic_106541-07 sun4m sparc sun4m
$ ./t
select result=0

-- 
"Bobby, jiggle Grandpa's rat so it looks alive, please" -- gary larson

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

* Re: bug report: select on unconnected sockets
  2001-03-31 16:15 ` john slee
@ 2001-03-31 16:26   ` Radu Greab
  0 siblings, 0 replies; 3+ messages in thread
From: Radu Greab @ 2001-03-31 16:26 UTC (permalink / raw)
  To: john slee; +Cc: linux-kernel

On Sun, 1 Apr 2001 02:15 +1000, john slee wrote:
 > On Sat, Mar 31, 2001 at 06:44:20PM +0300, Radu Greab wrote:
 > > Sorry if this is already known: on a RH 7.0 system with kernel 2.4.2
 > > or 2.4.3, a select on an unconnected socket incorrectly says that the
 > > socket is ready for input and output. Of course, reading from the socket
 > > file descriptor returns -1 and errno is set to ENOTCONN as shown in
 > > the strace output:
 > > 
 > > socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
 > > select(4, [3], [3], [3], {0, 0})        = 2 (in [3], out [3], left {0, 0})
 > > read(3, 0xbffff668, 1024)               = -1 ENOTCONN (Transport endpoint is not connected)
 > > 
 > > I attached a small example program to reproduce the bug.
 > 
 > bleah.  which one is supposed to be right?

I think that the Solaris one is right.

 > 
 > linux 2.4
 > ---------
 > $ uname -a
 > Linux XXXXX 2.4.2-ac20 #8 Wed Mar 14 01:53:05 EST 2001 i686 unknown
 > $ ./t
 > select result=2
 > read: Transport endpoint is not connected

Select says that the socket is ready for both input and output. A read
results in ENOTCONN, a write results in EPIPE.

 > linux 2.2
 > ---------
 > $ uname -a
 > Linux XXXXX 2.2.18 #1 Thu Dec 21 21:13:10 EST 2000 i586 unknown
 > $ ./t
 > select result=1

Select says that the socket is ready for output, but a write results
in EPIPE.

 > 
 > solaris
 > -------
 > $ uname -a
 > SunOS XXXXX 5.7 Generic_106541-07 sun4m sparc sun4m
 > $ ./t
 > select result=0

And Digital Unix is right too:

$ uname -a
OSF1 XXX V4.0 1229 alpha
$ ./a.out
select result=0


Thanks,
Radu Greab

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

end of thread, other threads:[~2001-03-31 16:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-03-31 15:44 bug report: select on unconnected sockets Radu Greab
2001-03-31 16:15 ` john slee
2001-03-31 16:26   ` Radu Greab

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