Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the socket buffer size of linux

What's the default socket buffer size of linux? Is there any command to see it?

like image 605
Freewind Avatar asked Oct 23 '11 08:10

Freewind


People also ask

What is socket buffer size in Linux?

default The default size of the send buffer for a TCP socket. This value overwrites the initial default buffer size from the generic global /proc/sys/net/core/wmem_default defined for all protocols. The default value is 16 kB.

How do I know if my socket buffer is full?

You can try ioctl . FIONREAD tells you how many bytes are immediately readable. If this is the same as the buffer size (which you might be able to retrieve and/or set with another icotl call), then the buffer is full.

What is socket buffer in Linux?

The socket buffer is the structure used to address and manage a packet over the entire time this packet is being processed in the kernel.

How do I change the buffer size in Linux?

Change the following set of parameters as needed: /proc/sys/net/core/rmem_default > recv > 124928 > changed to 512000. /proc/sys/net/core/wmem_default > send > 124928 > changed to 512000. /proc/sys/net/core/rmem_max > 124928 > changed to 512000.


2 Answers

If you want see your buffer size in terminal, you can take a look at:

  • /proc/sys/net/ipv4/tcp_rmem (for read)
  • /proc/sys/net/ipv4/tcp_wmem (for write)

They contain three numbers, which are minimum, default and maximum memory size values (in byte), respectively.

like image 114
saeedn Avatar answered Oct 01 '22 02:10

saeedn


For getting the buffer size in c/c++ program the following is the flow

int n; unsigned int m = sizeof(n); int fdsocket; fdsocket = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP); // example getsockopt(fdsocket,SOL_SOCKET,SO_RCVBUF,(void *)&n, &m); // now the variable n will have the socket size 
like image 22
Dinesh P.R. Avatar answered Oct 01 '22 03:10

Dinesh P.R.