Reputation: 19104
As crazy as it sounds, there are situations in life when one needs to configure TCP stack parameters manually, such as MSS.
I see it can be done machine-wide as described, for example, here. But I need a way to configure it on per-tcp-socket basis.
Upvotes: 3
Views: 2195
Reputation: 109
I think windows may does not allow you to adjust MSS per socket.
Here's the test sample:
Just call setsockopt
with TCP_MAXSEG
.
#include <ws2tcpip.h>
`int mss = 512;`
`setsockopt(sock, IPPROTO_TCP, TCP_MAXSEG, (char*)&mss, sizeof(mss);`
Set it before connect
or listen
.
I tested it with vs2015 on windows10. This code can pass the compile in VS2015, but can not run. Windows will give a error WSAENOPROTOOPT
when it's running.
Upvotes: 0
Reputation: 84239
That should be standard setsockopt
with TCP_MAXSEG
. Just remember that this has to be done before connection is initiated (i.e. before connect
or listen
) and that TCP stack might change the actual value according to path MTU.
Upvotes: 2
Reputation: 19837
You can try calling setsockopt()
with TCP_MAXSEG as is implied to be possible at the bottom of this MSDN article. But what's strange is that the TCP_MAXSEG is not a valid optname to supply to getsockopt()
. So maybe it can be set but not retrieved? I guess give it a try and see if it works.
Upvotes: 0