Re: poll() returns POLLIN but no data ?
From: David Schwartz (davids_at_webmaster.com)
Date: 06/25/05
- Next message: Peter Seibel: "Re: Any standard way to fork and exec something that isn't in a file?"
- Previous message: Paul Pluzhnikov: "Re: Catch SIGSEGV and longjmp(3) to Safety?"
- In reply to: Leon Mergen: "poll() returns POLLIN but no data ?"
- Next in thread: Maxim Yegorushkin: "Re: poll() returns POLLIN but no data ?"
- Reply: Maxim Yegorushkin: "Re: poll() returns POLLIN but no data ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 25 Jun 2005 13:27:02 -0700
"Leon Mergen" <lmergen@gmail.com> wrote in message
news:1119705877.8010.10.camel@localhost.localdomain...
> Hello,
>
> Consider this piece of code:
>
> ---
> struct pollfd ufds;
> char buffer[8192] = "";
>
> ufds.fd = sockStream->getHandle ();
> ufds.events = POLLIN|POLLHUP;
> ufds.revents = 0;
>
> int result = poll ( &ufds, 1, 30000 );
> if (result > 0) {
> if (ufds.revents & POLLHUP ) {
> // Close connection
> } else if (ufds.revents & POLLIN ) {
> recv (sockStream->getHandle, buffer, sizeof(buffer), 0);
> }
> }
> ---
>
> For some reason, ufds.revents matches POLLIN, but when executing the
> blocking recv function, there is no data and that function blocks. I'm
> running Linux 2.6.10, and have /no/ idea what might be causing this.
> Anyone else has an idea ?
You should be using non-blocking sockets if you don't want to block. The
system does not "remember" that it gave you the POLLIN indication and
magically convert the "next" operation to a non-blocking one. Also, you are
ignoring the return value of 'recv'.
DS
- Next message: Peter Seibel: "Re: Any standard way to fork and exec something that isn't in a file?"
- Previous message: Paul Pluzhnikov: "Re: Catch SIGSEGV and longjmp(3) to Safety?"
- In reply to: Leon Mergen: "poll() returns POLLIN but no data ?"
- Next in thread: Maxim Yegorushkin: "Re: poll() returns POLLIN but no data ?"
- Reply: Maxim Yegorushkin: "Re: poll() returns POLLIN but no data ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]