I was wondering if there is an easy way to find the maximum size that is supported by Linux sockets? (Is this configurable? If so where?)

For example, most of the socket examples found on the web send "Hello Socket" or some such other small string, however if I put the whole of War And Peace into the socket, when does it break?

As everything is a file, is it the maximum file size? How is it coordinated when sockets connect different file systems?

I'm most interested in stream sockets.

  • 3
    Re War & Piece: be mindful of the EFELL_ASLEEP error code from read. – Mat May 6 '12 at 21:42

net.core.rmem_max and net.core.wmem_max are your thing. You can examine their values with

# sysctl net.core.rmem_max

and set them with

# sysctl -w net.core.rmem_max=8388608

These are the socket buffer sizes, when receiving and sending, respectively. They have default values, too, - rmem_default and wmem_default.

| improve this answer | |

You didn't say what type of sockets.

Stream sockets

You can send (by definition) an unlimited amount of data. If it cannot all be buffered or sent at once or if the receiver cannot receive it all at once, the send will either block (for blocking sockets) or return a partial count of bytes written or EAGAIN (for nonblocking sockets).

Datagram sockets

It depends on the protocol. UDPv4 supports only 65536 bytes per datagram. UDPv6 supports much more. UNIX domain sockets probably support still more: you are probably just limited by memory in this case.

| improve this answer | |
  • Stream Sockets Actually - Although i didnt know there would be a difference. – NWS May 6 '12 at 20:52
  • -1 for 'unlimited amount of data' comment. – billz Nov 17 '17 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.