From 13091a5039d928cc9ba16892f86de682806ddc18 Mon Sep 17 00:00:00 2001 From: csh <458761603@qq.com> Date: Mon, 2 Sep 2024 14:53:02 +0800 Subject: [PATCH 1/2] [Lib] Add the implementation of `AsFd` Signed-off-by: csh <458761603@qq.com> --- src/lib.rs | 20 +++++++++++++++++++- src/socket.rs | 8 +++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6edd2d1d..58fb3227 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ pub use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr}; use std::{ io::{self, Read, Write}, net::{SocketAddrV4, SocketAddrV6}, - os::wasi::prelude::{AsRawFd, FromRawFd, IntoRawFd}, + os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd}, }; #[derive(Debug)] @@ -28,6 +28,12 @@ impl AsMut for TcpStream { } } +impl AsFd for TcpStream { + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + #[derive(Debug)] pub struct TcpListener { s: socket::Socket, @@ -47,6 +53,12 @@ impl AsMut for TcpListener { } } +impl AsFd for TcpListener { + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + #[derive(Debug)] pub struct UdpSocket { s: socket::Socket, @@ -64,6 +76,12 @@ impl AsMut for UdpSocket { } } +impl AsFd for UdpSocket { + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + impl TcpStream { /// Create TCP socket and connect to the given address. /// diff --git a/src/socket.rs b/src/socket.rs index 7754ef1d..96b0ee1c 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -1,7 +1,7 @@ use std::io; use std::mem::MaybeUninit; use std::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr, SocketAddrV4, SocketAddrV6}; -use std::os::wasi::prelude::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; +use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; #[derive(Copy, Clone, Debug)] #[repr(u8, align(1))] @@ -1307,6 +1307,12 @@ impl AsRawFd for Socket { } } +impl AsFd for Socket { + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + impl IntoRawFd for Socket { fn into_raw_fd(self) -> RawFd { let fd = self.fd; From 2252a1e21ebc8d9eb9c2de992f362001cf308a34 Mon Sep 17 00:00:00 2001 From: csh <458761603@qq.com> Date: Mon, 2 Sep 2024 14:55:06 +0800 Subject: [PATCH 2/2] [CI] fix install wasmedge Signed-off-by: csh <458761603@qq.com> --- .github/workflows/example_0.13.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/example_0.13.yml b/.github/workflows/example_0.13.yml index aceba364..1b442307 100644 --- a/.github/workflows/example_0.13.yml +++ b/.github/workflows/example_0.13.yml @@ -31,8 +31,7 @@ jobs: - name: Install WasmEdge run: | VERSION=0.13.5 - curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | sudo bash -s -- -e all --version=$VERSION --tf-version=$VERSION --tf-deps-version=$VERSION --tf-tools-version=$VERSION --image-version=$VERSION -p /usr/local - + curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | sudo bash -s -- --version=$VERSION -p /usr/local # Disable this example due to it relies on wasmedge_http_req, which is a cyclic dependence # - name: HTTP client example # run: |