Re: blocking/nonblocking socket and select -> usefull?
- From: "David Schwartz" <davids@xxxxxxxxxxxxx>
- Date: 16 Jan 2007 22:39:57 -0800
oliver.kowalke@xxxxxx wrote:
So for TCP this means nonblocking read make no sense because:
1) read copies n bytes in the application buffer
or
2) read copied less than n bytes in the application buffer and I let
select decide when another chunck of data could be read from the socket
until n bytes are filled in the application buffer
What if the implementation received the bytes and notified you by
'select', but before you get around to calling 'read', and before the
implementation can send an acknowledgement, there's TCP memory pressure
and the implementation elects to drop the packet and wait for the other
end to resend it. If the network link breaks before the other end can
resend it, you block in 'recv' forever. Oops.
read on UDP returns complete datagrams (if not truncated because
application buffer was too small). therefore making this nonblocking is
wasting cpu cycles.
What if the implementation drops the UDP datagram in-between when you
got the 'select' hit and when you call 'recvmsg'? You would then block
until another datagram was received. Oops.
Conclusion:
In this case (the user specifies how many bytes should be read from the
socket until processing goes on) nonblocking for read results not in
speedups. For write ops nonblocking would be good in order not to
block system resources like threads.
If you want non-blocking operations, you need non-blocking sockets.
Otherwise *every* operation can block.
"I can't think of any way it could break" is *NOT* the same as "it is
guaranteed to work".
DS
.
- Follow-Ups:
- Re: blocking/nonblocking socket and select -> usefull?
- From: Rick Jones
- Re: blocking/nonblocking socket and select -> usefull?
- References:
- blocking/nonblocking socket and select -> usefull?
- From: oliver . kowalke
- Re: blocking/nonblocking socket and select -> usefull?
- From: Boltar
- Re: blocking/nonblocking socket and select -> usefull?
- From: Oliver Kowalke
- Re: blocking/nonblocking socket and select -> usefull?
- From: Rainer Weikusat
- Re: blocking/nonblocking socket and select -> usefull?
- From: Oliver Kowalke
- Re: blocking/nonblocking socket and select -> usefull?
- From: Rick Jones
- Re: blocking/nonblocking socket and select -> usefull?
- From: oliver . kowalke
- blocking/nonblocking socket and select -> usefull?
- Prev by Date: Re: blocking/nonblocking socket and select -> usefull?
- Next by Date: Re: blocking/nonblocking socket and select -> usefull?
- Previous by thread: Re: blocking/nonblocking socket and select -> usefull?
- Next by thread: Re: blocking/nonblocking socket and select -> usefull?
- Index(es):
Relevant Pages
|