Skip to content

listener,stream: add OwnedFd integration#72

Merged
jalil-salame merged 1 commit into
rust-vsock:masterfrom
mvo5:from-fd
Mar 30, 2026
Merged

listener,stream: add OwnedFd integration#72
jalil-salame merged 1 commit into
rust-vsock:masterfrom
mvo5:from-fd

Conversation

@mvo5
Copy link
Copy Markdown
Contributor

@mvo5 mvo5 commented Mar 27, 2026

This commit makes working with OwnedFds easier by providing
implementations for
From<OwnedFd> for Vsock{Listener,Stream}
and
From<Vsock{Listener,Stream}> for OwnedFd

This is useful for e.g. socket-activated services that get
passed a fd and avoids the need for the caller to use the
unsafe FromRawFd.

Copy link
Copy Markdown
Contributor

@qwandor qwandor left a comment

Choose a reason for hiding this comment

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

Thanks! Would it make sense to implement the reverse conversion too? And what about VsockStream, and the synchronous versions of these in the vsock crate?

@mvo5
Copy link
Copy Markdown
Contributor Author

mvo5 commented Mar 28, 2026

Thanks! Would it make sense to implement the reverse conversion too? And what about VsockStream, and the synchronous versions of these in the vsock crate?

Sure! Happy to add those too, honestly I was just focus on "my" use-case (and this is all I need there) but it make sense to widen it a bit. I added the reverse conversion now. I'm happy to add the others too. Do you want them in separate PRs or in this PR?

For the stream I would do something like:

+impl FromRawFd for VsockStream {
+    unsafe fn from_raw_fd(fd: RawFd) -> Self {
+        Self::new(vsock::VsockStream::from_raw_fd(fd)).unwrap()
+    }
+}

which mimics the VsockListener code - I assume the unwarp() there is okay here too (just like in VsockListener)?

@qwandor
Copy link
Copy Markdown
Contributor

qwandor commented Mar 30, 2026

I've sent rust-vsock/vsock-rs#65 to add the equivalent conversions to the underlying vsock crate. Once that's released you should be able to update this to avoid the unsafe blocks.

@qwandor
Copy link
Copy Markdown
Contributor

qwandor commented Mar 30, 2026

vsock 0.5.4 is now released, please update this change to use that.

@qwandor
Copy link
Copy Markdown
Contributor

qwandor commented Mar 30, 2026

And you can go ahead and add the conversions for VsockStream in this PR too.

This commit makes working with OwnedFds easier by providing
implementations for
`From<OwnedFd> for Vsock{Listener,Stream}`
and
`From<Vsock{Listener,Stream}> for OwnedFd`

This is useful for e.g. socket-activated services that get
passed a fd and avoids the need for the caller to use the
unsafe FromRawFd.

Signed-off-by: Michael Vogt <michael@amutable.com>
@mvo5 mvo5 changed the title listener: add From<OwnedFd> for VsockListener listener,stream: add OwnedFd integration Mar 30, 2026
@qwandor qwandor requested a review from jalil-salame March 30, 2026 15:50
@jalil-salame jalil-salame merged commit 13a3004 into rust-vsock:master Mar 30, 2026
3 checks passed
mvo5 added a commit to mvo5/varlink-http-bridge that referenced this pull request Mar 30, 2026
With rust-vsock/tokio-vsock#72 being merged
we can remove the unsafe block and use the From<OwnedFd> in the
vsock listener code.
mvo5 added a commit to mvo5/varlink-http-bridge that referenced this pull request Apr 15, 2026
With rust-vsock/tokio-vsock#72 being merged
we can remove the unsafe block and use the From<OwnedFd> in the
vsock listener code.
mvo5 added a commit to mvo5/varlink-http-bridge that referenced this pull request Apr 16, 2026
With rust-vsock/tokio-vsock#72 being merged
we can remove the unsafe block and use the From<OwnedFd> in the
vsock listener code.
mvo5 added a commit to mvo5/varlink-http-bridge that referenced this pull request Apr 20, 2026
With rust-vsock/tokio-vsock#72 being merged
we can remove the unsafe block and use the From<OwnedFd> in the
vsock listener code.
mvo5 added a commit to mvo5/varlink-http-bridge that referenced this pull request Apr 22, 2026
With rust-vsock/tokio-vsock#72 being merged
we can remove the unsafe block and use the From<OwnedFd> in the
vsock listener code.
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.

3 participants