Help and Support
 

powered byLive Search

Winsock Does Not Limit Buffer Size

Article ID:227672
Last Review:November 3, 2003
Revision:3.0
This article was previously published under Q227672

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.

Back to the top

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.

Back to the top

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 );
}
				

Back to the top

STATUS

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

Back to the top

MORE INFORMATION

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

Back to the top


APPLIES TO
Microsoft Windows 2000 Server
Microsoft Windows 2000 Professional Edition

Back to the top

Keywords: 
kbprb KB227672

Back to the top

Article Translations

 

Related Support Centers

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.