Make our implementation return error for such setsockopt(2) and
document that. This unties our hands with coding protocol
independent socket buffers.
The specification [1] doesn't explicitly limit use of these options
to SOCK_STREAM. However, the wording suggests that context belongs
to a stream socket. For example:
"Receive calls may still return less than the low water mark if an
error occurs, a signal is caught, or the type of data next in the receive queue is different from that returned (for example, out-of-band data)."
For a datagram/packet socket, this can't be applied, as a read on
such socket must return full datagram.
Until this change current implementation favored watermarks for
datagram sockets, resulting in quite odd behavior. You will get
notification for a socket only if overall length of datagrams is
above watermark. Once you read enough datagrams to get below
watermark, notifications would stop. In practice this yields in an
indefinite delay in receiving data.
Modern Linux implementation ignores watermarks for datagram sockets,
however doesn't return error for setsockopt().
It is very unlikely there exist an application that would use
watermarks for non-stream sockets.
[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html