linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Possible bug with poll syscall
@ 2001-03-10 13:23 Alex Baretta
  2001-03-10 16:12 ` Alex Baretta
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Baretta @ 2001-03-10 13:23 UTC (permalink / raw)
  To: Linux Kernel Mailing List

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. I believe this
might be a bug. As far as I understand poll should be woken up by
connection requests and should signal them with a POLLIN. But,
then again, I might have misunderstood the specification.

Would anyone please shed some light on this issue?

Thank you very much.

Alex Baretta

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

* Re: Possible bug with poll syscall
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Baretta @ 2001-03-10 16:12 UTC (permalink / raw)
  To: Linux Kernel Mailing List

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.


The very same thing happens if I use select. It seems highly
unlikely that this should be the specified behavior of poll and
select alike. Is one now forced to used threads to manage multiple
ports?

Greetings,

Alex Baretta

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

* Re: Possible bug with poll syscall
  2001-03-10 16:12 ` Alex Baretta
@ 2001-03-11  2:18   ` Alex Baretta
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Baretta @ 2001-03-11  2:18 UTC (permalink / raw)
  To: Linux Kernel Mailing List

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

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

end of thread, other threads:[~2001-03-11  2:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).