I am trying to solve the problem of being able to read from one socket and then write to another socket without blocking and without buffering for cases where I cannot use splice().
As a first pass solution what I have in mind is to query the remaining size of the send buffer on the write socket, read that much from the reading socket, then write that much to the write socket knowing we can't block.
I have found someone claim at https://stackoverflow.com/a/9982492/4598583 that to query the remaining buffer size you can do the following:
getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &send_buf, &optlen);
However, I cannot find a reference to whether SO_SNDBUF will return the maximum buffer size or the remaining buffer size.
Can anyone confirm if querying the remaining (not maximum) buffer size is possible?
Alternatively, when a write socket indicates that that socket is writable (via poll() or some other mechanism) is there a minimum size of data defined anywhere that you can write without blocking or truncation in this case?