mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* bug in select() in linux
@ 2007-03-12 14:51 Lluís Batlle
       [not found] ` <20070312160104.25d6b321@lxorguk.ukuu.org.uk>
  0 siblings, 1 reply; 5+ messages in thread
From: Lluís Batlle @ 2007-03-12 14:51 UTC (permalink / raw)
  To: linux-kernel

Hello,

I've found a problem in the select() call. The manpage states:
"those in writefds will be watched to see if a write will not block"

I've tried a select() for write against a closed tcp socket (closed by
the other side), and the select call _blocks_.

Any write() call to that socket will _not block_, and will return with EPIPE.

I've seen this happening in 2.4.20 and 2.6.16.29 (xen patched) at least.

Maybe it's a glibc problem - you may know better.

Could you please keep me in carbon copy? I'm not sure I want to
subscribe to LKML.

Regards,
Lluís.

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

* Re: bug in select() in linux
       [not found] ` <20070312160104.25d6b321@lxorguk.ukuu.org.uk>
@ 2007-03-12 15:02   ` Lluís Batlle
  2007-03-12 15:08     ` Alistair John Strachan
  2007-03-12 17:03     ` Alan Cox
  0 siblings, 2 replies; 5+ messages in thread
From: Lluís Batlle @ 2007-03-12 15:02 UTC (permalink / raw)
  To: linux-kernel

Oh, of course you're right. I was inside too much layers to think of
the tcp protocol, and I did not pay attention to it.

Maybe something could be added to the manpage anyway.

The bad thing is that there's no way I can use a socket for writing
using select() if that connection has been half-closed by the other
end. Moo.

Thanks a lot for your time,
Lluís

2007/3/12, Alan Cox <alan@lxorguk.ukuu.org.uk>:
> > I've tried a select() for write against a closed tcp socket (closed by
> > the other side), and the select call _blocks_.
>
> A TCP close from the remote node is single sided. It sends a FIN and we
> ACK the FIN, that means only that the remote node has completed *sending*.
>
> > Any write() call to that socket will _not block_, and will return with EPIPE.
>
> We don't know this until you try the write. At that point the other end
> if it has closed entirely will issue an RST and terminate the connection
> in full.
>
> I don't therefore believe that this is actually a bug.
>
> Alan
>

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

* Re: bug in select() in linux
  2007-03-12 15:02   ` Lluís Batlle
@ 2007-03-12 15:08     ` Alistair John Strachan
  2007-03-12 15:15       ` Lluís Batlle
  2007-03-12 17:03     ` Alan Cox
  1 sibling, 1 reply; 5+ messages in thread
From: Alistair John Strachan @ 2007-03-12 15:08 UTC (permalink / raw)
  To: Lluís Batlle; +Cc: linux-kernel

On Monday 12 March 2007 15:02, Lluís Batlle wrote:
> Oh, of course you're right. I was inside too much layers to think of
> the tcp protocol, and I did not pay attention to it.
>
> Maybe something could be added to the manpage anyway.
>
> The bad thing is that there's no way I can use a socket for writing
> using select() if that connection has been half-closed by the other
> end. Moo.

This question comes up from time to time. I think the answer is 
ultimately "select() sucks, use poll()".

I can't exactly remember the details, but I believe POLLHUP or POLLOUT as 
flags do what you want.

-- 
Cheers,
Alistair.

Final year Computer Science undergraduate.
1F2 55 South Clerk Street, Edinburgh, UK.

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

* Re: bug in select() in linux
  2007-03-12 15:08     ` Alistair John Strachan
@ 2007-03-12 15:15       ` Lluís Batlle
  0 siblings, 0 replies; 5+ messages in thread
From: Lluís Batlle @ 2007-03-12 15:15 UTC (permalink / raw)
  To: linux-kernel

Wouldn't it be better for all of us that select() doesn't block on
write(), unless there is a socket writting buffer fulfilled? It will
be consistent with the select() specification.

2007/3/12, Alistair John Strachan <s0348365@sms.ed.ac.uk>:
> On Monday 12 March 2007 15:02, Lluís Batlle wrote:
> > Oh, of course you're right. I was inside too much layers to think of
> > the tcp protocol, and I did not pay attention to it.
> >
> > Maybe something could be added to the manpage anyway.
> >
> > The bad thing is that there's no way I can use a socket for writing
> > using select() if that connection has been half-closed by the other
> > end. Moo.
>
> This question comes up from time to time. I think the answer is
> ultimately "select() sucks, use poll()".
>
> I can't exactly remember the details, but I believe POLLHUP or POLLOUT as
> flags do what you want.
>
> --
> Cheers,
> Alistair.
>
> Final year Computer Science undergraduate.
> 1F2 55 South Clerk Street, Edinburgh, UK.
>

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

* Re: bug in select() in linux
  2007-03-12 15:02   ` Lluís Batlle
  2007-03-12 15:08     ` Alistair John Strachan
@ 2007-03-12 17:03     ` Alan Cox
  1 sibling, 0 replies; 5+ messages in thread
From: Alan Cox @ 2007-03-12 17:03 UTC (permalink / raw)
  To: Lluís Batlle; +Cc: linux-kernel

On Mon, 12 Mar 2007 16:02:11 +0100
"Lluís Batlle" <viriketo@gmail.com> wrote:

> Oh, of course you're right. I was inside too much layers to think of
> the tcp protocol, and I did not pay attention to it.
> 
> Maybe something could be added to the manpage anyway.
> 
> The bad thing is that there's no way I can use a socket for writing
> using select() if that connection has been half-closed by the other
> end. Moo.

You can because the only case it will block is when the transmit queue is
partly or completely full which means that you will discover the
connection has been reset when the transmit triggers a reset.

If you wait on the FD concerned for write or exception events all should
work nicely.

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

end of thread, other threads:[~2007-03-12 15:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-12 14:51 bug in select() in linux Lluís Batlle
     [not found] ` <20070312160104.25d6b321@lxorguk.ukuu.org.uk>
2007-03-12 15:02   ` Lluís Batlle
2007-03-12 15:08     ` Alistair John Strachan
2007-03-12 15:15       ` Lluís Batlle
2007-03-12 17:03     ` Alan Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®