Re: Question on select() and sockets
- From: Barry Margolin <barmar@xxxxxxxxxxxx>
- Date: Fri, 06 Jun 2008 22:56:58 -0400
In article
<232789a3-7349-4887-9e3a-cfdf358f9744@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
K-mart Cashier <cdalten@xxxxxxxxx> wrote:
On Jun 6, 2:07 pm, Alex Fraser <m...@xxxxxxxxxxx> wrote:
K-mart Cashier wrote:
Why do sockets have to be 'non-blocking' when using select() to set
the timeout? Ie, why can't they be blocked?
You can use blocking calls to send()/recv()/read()/write() if you don't
care if you block in them - but I don't think that should ever be the
case if you are using select().
Making the sockets non-blocking guarantees control over when you block
(ie, in select()). Although I was writing about pipes in my recent reply
to Edd, the same applies to sockets (first block of my reply):
http://groups.google.co.uk/group/comp.unix.programmer/msg/b589bcb9068...
Alex
Perhaps I'm not thinking this through, but how
"This all sounds fine. But you must set the pipes non-blocking else
you
can still end up blocking, even if you only call read() or write()
after
select() says the descriptor is, respectively, readable or writeable:
Is this possible?
Chad
Yes. Select() will report the descriptor as writable as soon as there's
any room in the pipe or socket buffer. If you try to write more than
this, and it's not set to non-blocking, you'll block.
--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.
- Follow-Ups:
- Re: Question on select() and sockets
- From: K-mart Cashier
- Re: Question on select() and sockets
- References:
- Question on select() and sockets
- From: K-mart Cashier
- Re: Question on select() and sockets
- From: Alex Fraser
- Re: Question on select() and sockets
- From: K-mart Cashier
- Question on select() and sockets
- Prev by Date: Re: Warning-free dlsym()
- Next by Date: Re: Question on select() and sockets
- Previous by thread: Re: Question on select() and sockets
- Next by thread: Re: Question on select() and sockets
- Index(es):
Relevant Pages
|