Click here to Skip to main content
15,912,082 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a following doubt related to socket rmem_max and wmem_max.
Below is the output taken from my linux machine.

cat /proc/sys/net/core/rmem_max
212992
cat /proc/sys/net/core/rmem_default
212992
cat /proc/sys/net/core/wmem_max
212992
cat /proc/sys/net/core/wmem_default
212992.

so i thought of verifying whether the above values are wroking as expected or not. I have created two process(client socket and server socket) both are LOCAL unix sockets(AF_UNIX). I have made the server program to sleep for indefinite period of time before recv() call has been executed.

Client socket is sending 1024 bytes to server socket in a continuos while loop.
But i dont get a error even after sending more than 212992 bytes. My understanding is that since server is sleeping indefinitely it wont able to get the data from kernel socket buffer at the same time client is keep on pushing the data to the server. So all these data will be stored in the kernel buffer. since send() has the limitation of 212992 bytes(wmem_max) , send() client call should fail after enough kernel buffer has been used.

But this is not happening, i could see more than 113271663 number of ietrations are ongoing without any problem and send() call is not at all failing.

What is the value of wmem_default and rmem_default denotes?


Can someone please clarify what is the maximum socket buffers available in linux for send() and recv() and how this huge data is stored in linux kernel socket buffers wihtout any failure?

What I have tried:

Sent 1024 bytes successfully (i=139453022)
Sent 1024 bytes successfully (i=139453023)
Sent 1024 bytes successfully (i=139453024)
Sent 1024 bytes successfully (i=139453025)
Sent 1024 bytes successfully (i=139453026)
Sent 1024 bytes successfully (i=139453027)
...

139453027 number of 1024 chunks has been sent via send() kernel call without any failure.


//below is the server program sleeping indefinitely

for(;;) {
int completed, n, num;
printf("Waiting for a connection...\n");
n = sizeof(remote);
if ((sock_serv = accept(sock, (struct sockaddr *)&remote, &n)) == -1) {
perror("accept call failed");
exit(1);
}

printf("server socket Connected.\n");
sleep(100000); // indefinite sleep
completed = 0;
do {
num = recv(sock_serv, str, 1024, 0);
;
;
;
}
Posted
Updated 8-Nov-16 4:58am
Comments
KarstenK 12-Sep-16 5:44am    
long sleeping is always a bad idea, because the whole thread is in sleep mode.
Better is to poll every 100 ms. It is a long time in processor cycles.

1 solution

This is interesting behavior, if I had to guess, it's the fact that you're using an AF_UNIX local socket that seeing this behavior. When you specify a "local" socket, the kernel handles it completely differently. Local sockets are essentially just system files, because it's more efficient to do so, so the file may not be size restricted exactly the same way.

I'm guessing if you used actual AF_INET sockets, you'd start to see retransmissions/lost/dropped packets.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900