Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set TCP_QUICKACK option in TcpClient

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?

like image 466
Jason C Avatar asked Nov 07 '22 10:11

Jason C


1 Answers

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);
like image 68
Rowan Smith Avatar answered Nov 12 '22 18:11

Rowan Smith