Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will TcpClient.NoDelay affect already written data?

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?

like image 560
ispiro Avatar asked Jan 20 '21 15:01

ispiro


1 Answers

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.

like image 163
Zer0 Avatar answered Nov 19 '22 12:11

Zer0