3 ms·
Ah, I see, you were referring to saving `setsockopt()`, not data-carrying syscalls. Yes that makes sense. But I guess that in most cases where you have control
by nh2 6y ago
Ah, I see, you were referring to saving `setsockopt()`, not data-carrying syscalls.
Yes that makes sense. But I guess that in most cases where you have control over the `sendmsg()`'s calls flags, you'd also have control over its buffer, so you may be able to build the buffer in userspace in many situations, thus even saving multiple data-carrying syscalls.
The `setsockopt()` approach has the benefit that it works even when you have no control over the sending syscalls, e.g. when some library does it for you that you cannot modify or configure.
- jlokier 6y agoMSG_MORE comes in useful for these examples, where you can't use writev() alone, but do control the sending syscalls: - HTTP (unencrypted) serving static files or cache files, to combine sendmsg() for the headers followed by sendfile() for the body. You can't batch using writev() in that case, if you want the benefit of sendfile(). - Transmitting a stream of data that is being forwarded or generated. For example a HTTPS reverse proxy which forwards incoming unencrypted data and formats it into TLS progressively. It can't buffer the whole response as that would add too much delay, so it can send using sendmsg() with MSG_MORE until it reaches the end of the forwarded data.
- nh2 6y agoThat makes sense, thanks!