I'm porting some C++ to C#. I'm struggling a bit to find equivalents to various socket options. One I can't figure out is how to set TCP_QUICKACK
in C#.
If I have a TcpClient
, what is the C# equivalent of:
optval = 1;
setsockopt(socket_, IPPROTO_TCP, TCP_QUICKACK, &optval, sizeof(optval));
There doesn't seem to be an equivalent in SocketOptionName
, nor does there seem to be a corresponding property in TcpClient.Client
.
How can I set this option?
I believe that the following will achieve this, but you probably need to ask yourself do you actually need to disable TCP Delayed Acknowledgement
. You might find the application will work fine without it.
// Disable TCP Delayed Acknowledgement on a socket
int SIO_TCP_SET_ACK_FREQUENCY = unchecked((int)0x98000017);
var outputArray = new byte[128];
var bytesInOutputArray = tcpClient.Client.IOControl(SIO_TCP_SET_ACK_FREQUENCY,BitConverter.GetBytes(1), outputArray);
The outputArray will be unchanged and bytesInOutputArray will be 0.
I have seen in a number of places over the years that TCP_QUICKACK works on Windows, albeit undocumented, it's value is 12 (same as Linux). But you can't pass it through from C#, Socket.SetSocketOption
will not accept it.
#define TCP_QUICKACK 12
Another undocumented option is SIO_TCP_SET_ACK_FREQUENCY
apparently setting the frequency to a value of 1 turns off TCP Delayed Acknowledgement.
The C++ Would like this
#define SIO_TCP_SET_ACK_FREQUENCY _WSAIOW(IOC_VENDOR,23)
result = WSAIoctl(socket, SIO_TCP_SET_ACK_FREQUENCY, &frequency, sizeof(frequency), NULL, 0, &bytes, NULL, NULL);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With