For example, in C # there are TcpClient.ReceiveBufferSize and TcpClient.SendBufferSize (in fact, they are based on the system function setsockopt).
I want to understand what they influence, what size of buffer they set, because in the kernel of the OS and the WinSock library there is clearly not one buffer :)
I looked at their default values.
In Windows 8 (x64), they are by default equal to 65536.
In Windows Server 2003 (x64) - 8192.
Situation # 1.
I tried to create a server and client using the following algorithm:
- the client connects to the server
- the server (Win2003) transfers the file to the client to 70000 bytes with one call (the size selected is larger than both buffers)
- the client (Win8) waits for a few seconds and only then I manually call Read on the client, again I try to read 70,000 bytes with one call to Read
- while the network connection is stable
Result: the file is transferred normally read returns 70000 bytes and indeed the file is not damaged. Hence, in this case, the size of the buffers is not affected.
Situation # 2.
And what will happen when the cable is broken, which will then be eliminated and the accumulated (in the buffer?) Bytes should go to the receiver and be considered? In this case, will the buffer size be affected?
That is the following algorithm:
- the client has connected to the server
- cable breaks
- and at this time the client quickly formed an array of 70,000 bytes, called Write, the array was added to the queue (in some buffer )
- and then the cable was quickly returned to the site, everything happened very quickly, so the client and the server did not have time to fly out because of the "unconnected sockets", so the server begins to receive these bytes in segments and read them
But after all, there are 70,000 of them; maybe such a Write even N times in a row was before the cable returned to its place, and the default buffer limit is only 8192 and 65536, in any case less than 70,000 and more than 70,000 * N.
I have not yet modeled the second situation, just going.
As far as you know: what will happen? Whether there will be a loss of accumulated data in this case, will they turn out to be in a “black hole”?
And the main question: is it worth it to change the size of these buffers for a very unstable connection? Or they do not need to touch without need?
Why is it even possible to touch them?
Performance is not so important, I do not plan to transfer gigabytes, and delays even in a few seconds are not terrible.
UPD: But still in MSDN, WinSock has the following error in the list:
WSAENOBUFS 10055 No buffer space available. There is no need for the system.
This is what happens? And is this the buffer whose size is set by those parameters?