For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > November 2005 > Poll returns POLLERR|POLLHUP for socket connect call









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Poll returns POLLERR|POLLHUP for socket connect call
fc2004@gmail.com

2005-11-16, 7:02 pm

Hi,

My client program use poll to report network events, when I register
write event for a outbound connection request, I found out poll keeps
spinning because it gets POLLERR|POLLHUP? is this a normal case? If it
is, is the client supposed to call read or close ?

The platform is Linux 2.4.21-37.ELsmp #1 SMP.

Thanks

Fang

David Schwartz

2005-11-16, 7:02 pm


<fc2004@gmail.com> wrote in message
news:1132183754.645372.272970@o13g2000cwo.googlegroups.com...

> My client program use poll to report network events, when I register
> write event for a outbound connection request, I found out poll keeps
> spinning because it gets POLLERR|POLLHUP? is this a normal case?


Yes. It means that there's an error or the connection has closed. The
problem is not that 'poll' is spinning but that *your* are spinning on a
closed or errored connection.

> If it
> is, is the client supposed to call read or close ?


It depends what you are trying to do.

DS


fc2004@gmail.com

2005-11-16, 9:58 pm

Yes, it's my code that spins since it didn't expect such errors and
keeps polling.

Thanks

Andrei Voropaev

2005-11-17, 7:57 am

On 2005-11-17, fc2004@gmail.com <fc2004@gmail.com> wrote:
> Yes, it's my code that spins since it didn't expect such errors and
> keeps polling.


Actually I believe such behaviour of poll is OS specific. I've seen it
on linux, but not on NetBSD. Also with newer linux kernels
POLLHUP|POLLERR are always reported first with POLLIN or POLLOUT, if you
requested those. So your application always has a chance to do write or
read and check return values from those to see that there's EOF or some
error. And in this case it's not wise to keep your descriptor watched by
poll :)

So, as long as you always request either POLLIN or POLLOUT (or both) for your
descriptor and do read or write when poll reports those ready, you
shouldn't worry about POLLERR and POLLHUP. (It seems to me that only in
some older linux kernel this was not true, but I'm not sure)

--
Minds, like parachutes, function best when open
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com