Skip to content

[staging] Sockets prototype: use Span#292

Open
milseman wants to merge 3 commits intoapple:stagingfrom
milseman:sprocket_io
Open

[staging] Sockets prototype: use Span#292
milseman wants to merge 3 commits intoapple:stagingfrom
milseman:sprocket_io

Conversation

@milseman
Copy link
Contributor

Also adds support for sendmsg and recvmsg.

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, *)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This is due to some missing constants, will look more into that.


@testable import SystemSockets
@testable import SystemPackage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants