Search code examples
c#.nettcpnagle

When exactly does dotnet's tcp socket's send method not send all bytes?


Like all socket APIs, it says that it returns the number of bytes actually sent. Under which circumstances does the returned number not match the input's size?

My naive assumption was that it would send out full segments until the window is full, and once it would wait for an ACK it would return (I am sending from a W10 to an Ubuntu, and I assume both use Nagle's algorithm by default).

However even if I pass a >100MB buffer to send, it always returns the size of the input buffer. Does the standard library automagically "call send multiple times internally", or does my ubuntu send ACKs too fast? Or did I interpret the API and/or Nagle's algorithm wrong?


Solution

  • It looks like this would depend on the OS behavior. Dotnetcore isn't doing anything special like calling send multiple times. Your arguments get passed pretty much verbatim to the system call via: Socket.Send -> SocketPal.Send -> SystemNative_SendMessage