Re: Question on select() and sockets



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
.



Relevant Pages

  • Re: Question on select() and sockets
    ... But you must set the pipes non-blocking else ... I don't know of an implementation where readcan block after selectsays a pipe descriptor is readable, but as you described there is at least one real-world implementation where this is not true for sockets. ... the final issue I mentioned - that you don't know how many bytes you can write without blocking - seems quite clear to me. ... The descriptor for a socket is bidirectional, and both directions are normally used, so the issue of whether it is allowed for readability to be retracted is basically moot: write/sendmust be non-blocking, and handling the possibility that you get EAGAIN/EWOULDBLOCK on read/recvis surely preferable to setting/unsetting O_NONBLOCK around every write/sendcall. ...
    (comp.unix.programmer)
  • Re: orb run blocking question
    ... >> Is there a way to start a corba server without the blocking ... Take care, ... Electrical Engineering and Computer Science TEL: ...
    (comp.object.corba)
  • Re: [Ksummit-2007-discuss] Re: [Ksummit-2006-discuss] 2007 Linux Kernel Summit
    ... continue blocking 2D support and expect anyone to ... even care about your hardware ... ...
    (Linux-Kernel)
  • Re: DVD compatibility with VMS
    ... :cdrecord/cdwrite doesn't care about 512/2048 block jumpers. ... But while the tool itself cares not about the blocking for its operations, ... what is written out can sometimes care what the target blocking is. ...
    (comp.os.vms)
  • Add Blocking
    ... for some strange reason my computer is blocking adds I ... wouldn't care but it won't let me into POGO now. ... I've uninstalled my Norton Fire Wall, ...
    (microsoft.public.inetserver.iis.security)

Loading