public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alex Baretta <alex@baretta.com>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Possible bug with poll syscall
Date: Sun, 11 Mar 2001 03:18:27 +0100	[thread overview]
Message-ID: <3AAAE073.4C18B7F8@baretta.com> (raw)
In-Reply-To: <3AAA2ADE.E8FF41E3@baretta.com> <3AAA5273.67DC90EF@baretta.com>

Alex Baretta wrote:
> 
> Alex Baretta wrote:
> >
> > I am using poll with the POLLIN flag to wait for connection
> > requests on a set of listening sockets in a server process.
> > Although clients attempt to connect to those sockets, poll does
> > returns zero after the expiration of the timeout.
...

There was a bug in my code. I am unable to find it, but I wrote a
minimal to case to prove my point, and actually I proved myself
wrong. Test case follows. If I ever find the time I'll try to
experiment and discover why in "the real thing" poll did not work
for me.


#include <sys/poll.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>

int main(int argc, char **argv) {
  struct pollfd fds;
  int res1, res2, nevents;
  struct sockaddr_in sockaddr;

  fds.fd = socket(PF_INET, SOCK_STREAM, 0);
  fds.events = POLLIN;
  
  
  sockaddr.sin_family = AF_INET;
  sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  sockaddr.sin_port = htons(50000);
  
  res1 = bind(fds.fd, (struct sockaddr *)&sockaddr,
sizeof(sockaddr));
  res2 = listen(fds.fd, 20);

  if (fds.fd == -1 || res1 == -1 || res2 == -1) {
    fprintf(stderr, "The program failed miserably.\n");
    exit(1);
  }
  
  fprintf(stderr, "I'm about to suspend myself on a poll
syscall!\n");
  nevents = poll(&fds, 1, -1);
  fprintf(stderr, "Waking up: nevents = %d\n", nevents);
  
  return 0;
};

      reply	other threads:[~2001-03-11  2:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-10 13:23 Possible bug with poll syscall Alex Baretta
2001-03-10 16:12 ` Alex Baretta
2001-03-11  2:18   ` Alex Baretta [this message]

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=3AAAE073.4C18B7F8@baretta.com \
    --to=alex@baretta.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