Re: blocking/nonblocking socket and select -> usefull?




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

.



Relevant Pages

  • Re: Communication speed between blocking call and non blocking cal
    ... Yes i set winsock kernel buffer to 5MB. ... I got good speed and I tested for blocking and nonblocking socket and got ... Problem was I did not set winsock kernel buffer. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Communication speed between blocking call and non blocking cal
    ... Yes i set winsock kernel buffer to 5MB. ... I got good speed and I tested for blocking and nonblocking socket and got ... Ultimately I have got good speed with non blocking socket. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Communication speed between blocking call and non blocking cal
    ... You could use event based notification, ... When you use nonblocking I/O, the system may have to perform extra buffering ... data buffer until you say that you are done with it. ... I checked default socket buffer ...
    (microsoft.public.win32.programmer.networks)
  • Re: strange select() behavior
    ... sharing descriptors, might fill that interface buffer. ... What do you do when a blocking socket operation returns ENOBUFS? ... because it's a semantic change. ...
    (comp.unix.programmer)
  • Re: Can someone help me
    ... // contents from the server to the client public class AsynchNetworkFileServer {class ClientHandler {// constructor public ClientHandler(Socket socketForClient) {// initialize member variable socket = socketForClient; // initialize buffer to hold ... // contents of file buffer = new byte; // create the network stream networkStream = new NetworkStream; // set the file callback for reading ...
    (microsoft.public.dotnet.languages.csharp)