Winsock Does Not Limit Buffer Size

ID: Q227672


The information in this article applies to:
  • Microsoft Windows 2000 Professional
  • Microsoft Windows 2000 Server


SYMPTOMS

A Berkeley-style send (s, p, N, ..) always returns immediately for large N (over 1 MB), even when the buffer size set by SO_SNDBUF is much smaller than N. This problem also happens when SO_SNDBUF is not set (non-zero default assumed). If SO_SNDBUF is set to 0 (zero), then the call blocks correctly. The call should always block whenever available buffer space is smaller than N.


CAUSE

This feature improves the performance of most existing applications that do only one synchronous send at a time. Some applications may not benefit from this feature, and a possible workaround is available below.


RESOLUTION

The following wrapper workaround preserves system performance objectives and blocks for a reasonable duration. The workaround maintains a count of bytes already buffered and subtracts them from the current SO_SNDBUF setting.


sendBlock( SOCKET s, PTR p, int cb, int f )
{
    int nSockBuf = GetSockOpt( s, SO_SNDBUF );
    if( cb <= nSockBuf )
        return send( s, p, cb, f );

    cb -= nSockBuf;                    //Subtraction takes place here.

    int nRet = send( s, p, cb, f );
    if( nRet != cb )
        return nRet;

    return cb + send( s, p+cb, nSockBuf, f );
} 


STATUS

Microsoft has confirmed this to be a problem in Microsoft Windows 2000.


MORE INFORMATION

These symptoms may also be present if very large buffers are supplied in this type of call without using the above workaround.

Additional query words:

Keywords :
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: December 29, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.