views:

237

answers:

3

Hi,

How to increase the TCP receive window for a specific socket? - I know how to do so for all the sockets by setting the registry key TcpWindowSize, but how do do that for a specific one?

According to MSFT's documents, the way is

Calling the Windows Sockets function setsockopt, which sets the receive window on a per-socket basis.

But in setsockopt, it is mentioned about SO_RCVBUF :

Specifies the total per-socket buffer space reserved for receives. This is unrelated to SO_MAX_MSG_SIZE and does not necessarily correspond to the size of the TCP receive window.

So is it possible? How?

Thanks.

+1  A: 

I am fairly sure that SO_RCVBUF is what you want. The first link says that SO_RCVBUF has the highest priority for determining the TCP window size over and above anything set on the system. From the way I am reading it, I think that all second part is saying is that the SO_RCVBUF size does not have to match the system receive window size. In other words, it can be a different size that you set.

Genesis
Thank you.And is there a way to set SO_MAX_MSG_SIZE?
rursw1
+2  A: 

SO_MAX_MSG_SIZE is for UDP. Here's from MSDN:

SO_MAX_MSG_SIZE - Returns the maximum outbound message size for message-oriented sockets supported by the protocol. Has no meaning for stream-oriented sockets.

It's also not settable.

For TCP just use SO_(SND|RCV)BUF.

Nikolai N Fetissov
A: 

You need to be careful tuning this and testing the results. Windows Vista and above have a smart adaptive window size auto tuning feature which specifically tunes the window size to work well both on LANs and long fat networks such as 3G and high loss networks. Setting the window size yourself will override this so that windows can no longer tune the window size automatically. This may damage your performance should you ever need to run over a particularly high latency network such as a cellular network.

Stewart