As you can see on this question , which covers other socket options, the answer depends on the operating system, so both answers may be correct, since one of them is a response from the Linux world, and one of them answers from the UNIX world (BSD and Co) .
In the BSD and BSD clone, this parameter means the following:
If the socket is non-blocking and you call send() , it should be able to accept all the data provided at the same time or receive at least SO_SNDLOWAT data bytes; if this is not possible, it does not accept any data, and send() fails with an error.
So, if you set SO_SNDLOWAT to 100 and try to send 50 bytes, it will send 50 bytes or nothing. If you set SO_SNDLOWAT to 100 and try to send 200 bytes, it should at least receive 100 bytes of data, it can take more, up to 200 bytes, and also any value from 100 to 200, not less than 100. Keep in mind that the default value of SO_SNDLOWAT is 1, as well as the default behavior of a non-blocking socket (it should take at least 1 byte or crash with EWOULDBLOCK )
Please note that UDP sockets are always all or nothing, they never accept only a “part of the data”, therefore setting SO_SNDLOWAT applicable only for TCP sockets, which can accept only a part of the proposed data.
If the socket is blocked, setting SO_SNDLOWAT does not have a real effect on the send() call, since in this case the socket will always accept all data or it will be blocked, and then it will be blocked until all the data (if the send timeout has been set using SO_SNDTIMEO or the underlying protocol has its own timeout to send).
Regardless of whether the socket is blocked or not, regardless of whether it is UDP or TCP, the poll() or select() call will state that this socket is writable if at least SO_SNDLOWAT bytes can be received by the send() call .
So why is this option really good? It is usually used to avoid your process supplying data in bytes for a byte after the socket buffer is full, but in large fragments, as with the default behavior, select() and poll() will say that the socket is available for entries, even if there is one byte in the socket buffer. In other words, it’s just a performance optimization, because code that works correctly with arbitrary socket SO_SNDLOWAT will work correctly, regardless of whether SO_SNDLOWAT is SO_SNDLOWAT and no matter what value, it may take much less CPU time in some extreme situations. if SO_SNDLOWAT is reasonable. But, like in all performance settings, if you do not know exactly what you are doing, you can easily aggravate the situation by setting the wrong values, so if in doubt, do not touch this setting.
Mecki source share