0
int32_t rcvBuf = 400 * 1024;
    setsockopt(socketFD, SOL_SOCKET, SO_RCVBUF, &rcvBuf, 4);f

int32_t checkRcvBuf = 0;
unsigned int checkRcvBufLen = sizeof(checkRcvBuf);
getsockopt(socketFD, SOL_SOCKET, SO_RCVBUF, &checkRcvBuf, &checkRcvBufLen);

int32_t sndBuf = 400 * 1024;
setsockopt(socketFD, SOL_SOCKET, SO_SNDBUF, &sndBuf, 4);

int32_t checkSndBuf = 0;
unsigned int checkSndBufLen = sizeof(checkSndBuf);
getsockopt(socketFD, SOL_SOCKET, SO_SNDBUF, &checkSndBuf, &checkSndBufLen);
halfer
  • 19,824
  • 17
  • 99
  • 186
  • can i set the value throgh this code?? am i doing right or wrong... – Mohammad irani Sep 09 '16 at 07:58
  • what is the Default value of SO_SNDBUF and SO_RCVBUF in OS X??? – Mohammad irani Sep 09 '16 at 08:00
  • i read in AppleDoc https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man2/setsockopt.2.html The system places an absolute limit on these values. what's the limit?????? – Mohammad irani Sep 09 '16 at 08:18
  • Possible duplicate of [How to get maximum TCP Receive/Send window in MAC OS X?](http://stackoverflow.com/questions/4508798/how-to-get-maximum-tcp-receive-send-window-in-mac-os-x) – Jayson Minard Sep 14 '16 at 22:28

2 Answers2

5

On MAC OSX you can see all sysctl variables via:

$ sysctl -a

If you grep those for the prefix net.inet.tcp

$ sysctl -a|grep net.inet.tcp

You can see all related variables. You are looking for these two:

net.inet.tcp.sendspace: 131072
net.inet.tcp.recvspace: 131072

Showing are the current values on my system.

These can also be set via sysctl and use man sysctl for more information on doing so, an example of setting one of these values:

$ sudo sysctl net.inet.tcp.sendspace=131072

These must be set with root privileges and likely if sysctl can set the value, then C/C++ code can likely do the same if it can access the OS kernel functions for doing so (likely must be run as root).

See also:

sysctl source:

Tuning MAC OSX kernel configuration:

Kernel functions in Objective-C:

And the fact that people are at least reading these parameters from Swift means it is possible from Objective-C as well:

Related sysctl functions available for coding:

Jayson Minard
  • 84,842
  • 38
  • 184
  • 227
0
  1. Access the root of your shell (terminal)...
  2. run the /proc/sys/net/core/wmem_default file in to your shell
  3. as you reach your file run this command sysctl -a
  4. then run the next command like sysctl -a | grep -i space
  5. then you get the default size of SNDBUF and RCVBUF of your OS.
Jayson Minard
  • 84,842
  • 38
  • 184
  • 227
  • 1
    This isn't very clear. "run the ... in to your shell" is execute a process, or `cat` the file? "as you reach your file" means what, what does "reach" mean in this context? Is "space" literal text in the grep command? – Jayson Minard Sep 14 '16 at 22:20