Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find out AF_UNIX + SOCK_SEQPACKET maximum message size

I wonder if there is any possibility to find out the max length of SEQPACKET except experimental (a-la for( i=0; i<100...00; i++ ) send( ... );).

And, the second question:

If I received errno == EMSGSIZE trying to send AF_UNIX SEQPACKET, is it guaranteed that it's because of max message size, or could there be some other reasons?

like image 425
grungegurunge Avatar asked Oct 14 '11 10:10

grungegurunge


1 Answers

Limit comes from variable sysctl_wmem_default. It is viewable in the proc filesystem: /proc/sys/net/core/wmem_max

Different Linux versions may have different implementation in this point. But there is this kind of code for UNIX domain sockets:

sk->sk_sndbuf = sysctl_wmem_default;

and

err = -EMSGSIZE;
if (len > sk->sk_sndbuf - 32)
    goto out;

So the actual limit is: value of /proc/sys/net/core/wmem_max minus 32. I don't know how much this magic number changes between version. Value of /proc/sys/net/core/wmem_max seems to vary depending of available ram pages.

In my linux box the value is 105472. And maximum datagram size (when using AF_UNIX and SOCK_DGRAM) is 105440. If I try to send message with size 105441, it will fail with EMSGSIZE.

like image 134
SKi Avatar answered Sep 23 '22 06:09

SKi