Reputation: 27633
TcpClient.NoDelay docs state:
Gets or sets a value that disables a delay when send or receive buffers are not full.
However, it's not clear whether this only applies to data written after it's set to true
, or to data that has been written and is now waiting, as well. I.e. When there's data in the buffer and NoDelay
is then set to true
, will the data in the buffer be sent immediately?
Upvotes: 6
Views: 371
Reputation: 7354
When there's data in the buffer and NoDelay is then set to true, will the data in the buffer be sent immediately?
No.
It gets evaluated on the next Send
with valid data.
You can verify with NoDelay = true
followed by Send
with a few bytes.
Or set NoDelay = true
without any call to Send
after and you should see no change.
I verified using Wireshark, but use whatever packet inspection tool you prefer.
TcpClient
is just a thin wrapper around Socket
, so you can use Socket.NoDelay
the same way.
Socket options are set by this method calling setsockopt
which is native code:
errorCode = UnsafeNclNativeMethods.OSSOCK.setsockopt(
m_Handle,
optionLevel,
optionName,
ref optionValue,
sizeof(int));
The actual option being set in this case is TCP_NODELAY.
Upvotes: 3
Reputation: 26330
The documentation is not very helpful with this, but consider this:
If there is still data in the buffer when you set NoDelay
to true
then it should affect the waiting bytes, because if you write more data it surly affects that. How should that work if not all bytes (written before and after setting NoDelay
to true
) were treated equally?
Can you be 100% sure about this? Not without asking the authors of TcpClient
or inspecting its code.
Upvotes: 0