public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Radu Greab <radu@netsoft.ro>
To: linux-kernel@vger.kernel.org
Cc: radu@netsoft.ro
Subject: bug report: select on unconnected sockets
Date: Sat, 31 Mar 2001 18:44:20 +0300 (EEST)	[thread overview]
Message-ID: <15045.64340.14915.404305@ix.netsoft.ro> (raw)

[-- 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;
}

             reply	other threads:[~2001-03-31 15:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-31 15:44 Radu Greab [this message]
2001-03-31 16:15 ` bug report: select on unconnected sockets john slee
2001-03-31 16:26   ` Radu Greab

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=15045.64340.14915.404305@ix.netsoft.ro \
    --to=radu@netsoft.ro \
    --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