Re: To Block or not to Block

From: Lev Walkin (vlm_at_lionet.info)
Date: 07/16/04


Date: Fri, 16 Jul 2004 02:05:07 -0700

Robin Cawsey wrote:
> Hi,
> I've written a client server application using
> non-blocking sockets and most of the time it works fine, apart from
> when a message is send down the socket that causes the the
> non-blocking socket to want to block. This however returns an error
> because it's not able to block.
>
> Therefore is there anyway to get round this problem without setting
> the socket to block and not having to send the message in smaller
> chunks.

You should really, REALLY consider reorganizing the code structure
to allow sending message in smaller chunks and be able to retry transfer
after socket declared that its buffers are full. It will not necesserely
mean that the sender host will paketize the message differently.

Readings:

1. man poll, man select - for socket availability monitoring: to send
or receive only when the socket is ready.
2. man setsockopt, section on SO_SNDBUF: to set a larger buffer
which can help you to have better network paketization.
3. man setsockopt, section on SO_SNDLOWAT: to allow select() or
poll() only return when it is known that the socket buffers
can accomodate a certain (.sndbuf - .sndlowat) number of bytes
without blocking.

-- 
Lev Walkin
vlm@lionet.info


Relevant Pages

  • Re: Automatic TCP send socker buffer sizing
    ... I've seen in production that some sockets get large very quickly during periods of high latency (eg: when sending to a user downloading from a cablemodem and their headend gets temporarily saturated and has large buffers, which raises the RTT under saturation, which increases the bandwidth delay product), but then as there isn't any code to shrink the buffers. ... This would probably need to be in the timers to notice the case of the sender temporarily stopping sending - eg in a keepalive http socket ... Perhaps we can have a new setsockopt() flag to disable automatic sizing on a socket if we have a specific size we want a buffer to be and don't want it dynamically sized. ...
    (freebsd-net)
  • connect, socket API, is sending the connection request after long delay
    ... In our application we need to communication with multiple devices ... We're are using non-blocking sockets. ... sent the connection request to device. ... // Mark our socket non-blocking, ...
    (microsoft.public.vc.mfc)
  • connect, socket API, is sending the connection request after long delay
    ... In our application we need to communication with multiple devices ... We're are using non-blocking sockets. ... sent the connection request to device. ... // Mark our socket non-blocking, ...
    (microsoft.public.win32.programmer.networks)
  • Re: CAsyncSocket blocks
    ... make a distiction between blocking and non-blocking sockets? ... > room in the buffer to store the bytes which you requested to have sent. ... > of the connection is no longer reachable, as far as TCP/IP can tell, ... >> I cannot figure out why the socket behaves like this. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: WSAEventSelect
    ... that's exactly where you can't use this socket ... Due to msdn you have two options:WSAEventSelect or WSAAsyncSelect to ... From the documentation for WSAEventSelect: ... In principle I want to use WSAEventSelect with non-blocking sockets. ...
    (microsoft.public.win32.programmer.networks)