[staging] Sockets prototype: use Span#292
Conversation
Adds in sendmsg and recvmsg using Span types for the API and URBP for ABI. Uses AncillaryMessageBuffer (previously unused by a syscall).
| /// - Complexity: Amortized O(`data.count`), when averaged over multiple | ||
| /// calls. This method reallocates the buffer if there isn't enough | ||
| /// capacity or if the storage is shared with another value. | ||
| @available(macOS 15, iOS 18, watchOS 11, tvOS 18, visionOS 2, *) |
There was a problem hiding this comment.
Note: we'll want to switch to a Span availability macro before landing on main, similar to the file I/O work.
|
|
||
| import Testing | ||
|
|
||
| #if SYSTEM_PACKAGE_DARWIN |
There was a problem hiding this comment.
Note: This is due to some missing constants, will look more into that.
|
|
||
| @testable import SystemSockets | ||
| @testable import SystemPackage | ||
|
|
There was a problem hiding this comment.
Note for this file: I'm working on cleaning it up and expanding coverage a bit.
| try _receive(into: buffer, flags: flags, retryOnInterrupt: retryOnInterrupt).get() | ||
| ) throws(Errno) -> Int { | ||
| try buffer.withUnsafeMutableBytes { buf, count throws(Errno) -> Int in | ||
| let bytesRead = try _receive(into: buf, flags: flags, retryOnInterrupt: retryOnInterrupt).get() |
There was a problem hiding this comment.
In cases like this, I think you likely want to offset buf by count and then add bytesRead to count. That way instead of overwriting anything already initialized into the buffer, you only fill in the uninitialized space which is important for cases where you've realloc'ed to grow a buffer and call this function again on the same, now partially initialized buffer.
Also adds support for
sendmsgandrecvmsg.