Re: [PATCH v2 05/10] compat/posix: introduce writev(3p) wrapper
- From
brian m. carlson <sandals@crustytoothpaste.net>
- Date
- Mar 5, 2026, 02:16 UTC
- Message-ID
- <aajnZZI5yqL9CYeR@fruit.crustytoothpaste.net>
- In-Reply-To
- <20260305003745.GA4943@coredump.intra.peff.net>
On 2026-03-05 at 00:37:45, Jeff King wrote:
Show 5 quoted lines
> I like that writev() can work as a drop-in replacement for write() at > the lowest level. But given that our main use is likely to be pkt-lines, > I do kind of wonder if we should just try to be more clever in forming > our buffers. That makes all of the portability and compat questions go > away (and gives the benefit to platforms that don't even have writev).
This does work and it is clever, but I think the writev is clearer and more explicit. In addition, this is literally the kind of use case that it's designed for and the kernel will have a highly optimized implementation handling it. I could also see myself making use of writev in my future work as well, although I don't have any concrete code depending on it at the moment (but I could probably add it in the interop code).
There is a Windows equivalent as well (according to the Rust documentation[0]) which doesn't have to be added at this point, but could in the future as a quality-of-implementation issue. And almost all Unix systems will support this, with the possible exception of NonStop, since it's part of XSI and effectively everyone implements those C functions. (Also, writev was in 4.2BSD, released in 1983, so you'd have to be really behind the times to not support it.)
[0] Rust defines the `std::io::IoSlice` type which is documented as follows:
A buffer type used with `Write::write_vectored`.
It is semantically a wrapper around a `&[u8]`, but is guaranteed to
be ABI compatible with the `iovec` type on Unix platforms and
`WSABUF` on Windows.-- brian m. carlson (they/them) Toronto, Ontario, CA