Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unimplemented sockets from preview1 adapter #7543

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions crates/wasi-preview1-component-adapter/src/descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::bindings::wasi::cli::{
};
use crate::bindings::wasi::filesystem::types as filesystem;
use crate::bindings::wasi::io::streams::{InputStream, OutputStream};
use crate::bindings::wasi::sockets::tcp;
use crate::{BlockingMode, BumpArena, File, ImportAlloc, TrappingUnwrap, WasmStr};
use core::cell::{Cell, OnceCell, UnsafeCell};
use core::mem::MaybeUninit;
Expand Down Expand Up @@ -93,16 +92,12 @@ impl Streams {
}
}

#[allow(dead_code)] // until Socket is implemented
pub enum StreamType {
/// Streams for implementing stdio.
Stdio(IsATTY),

/// Streaming data with a file.
File(File),

/// Streaming data with a socket connection.
Socket(tcp::TcpSocket),
}

pub enum IsATTY {
Expand Down Expand Up @@ -370,18 +365,6 @@ impl Descriptors {
}
}

#[allow(dead_code)] // until Socket is implemented
pub fn get_socket(&self, fd: Fd) -> Result<&tcp::TcpSocket, Errno> {
match self.get(fd)? {
Descriptor::Streams(Streams {
type_: StreamType::Socket(socket),
..
}) => Ok(&*socket),
Descriptor::Closed(_) => Err(wasi::ERRNO_BADF),
_ => Err(wasi::ERRNO_INVAL),
}
}

pub fn get_file(&self, fd: Fd) -> Result<&File, Errno> {
self.get_file_with_error(fd, wasi::ERRNO_INVAL)
}
Expand Down
64 changes: 0 additions & 64 deletions crates/wasi-preview1-component-adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::bindings::wasi::filesystem::types as filesystem;
use crate::bindings::wasi::io::poll;
use crate::bindings::wasi::io::streams;
use crate::bindings::wasi::random::random;
use crate::bindings::wasi::sockets::network;
use core::cell::OnceCell;
use core::cell::{Cell, RefCell, RefMut, UnsafeCell};
use core::cmp::min;
Expand Down Expand Up @@ -589,11 +588,6 @@ pub unsafe extern "C" fn fd_fdstat_get(fd: Fd, stat: *mut Fdstat) -> Errno {
Ok(())
}
Descriptor::Closed(_) => Err(ERRNO_BADF),
Descriptor::Streams(Streams {
input: _,
output: _,
type_: StreamType::Socket(_),
}) => unreachable!(),
}
})
}
Expand Down Expand Up @@ -1645,26 +1639,6 @@ impl Drop for Pollables {
}
}

impl From<network::ErrorCode> for Errno {
fn from(error: network::ErrorCode) -> Errno {
match error {
network::ErrorCode::Unknown => unreachable!(), // TODO
/* TODO
// Use a black box to prevent the optimizer from generating a
// lookup table, which would require a static initializer.
ConnectionAborted => black_box(ERRNO_CONNABORTED),
ConnectionRefused => ERRNO_CONNREFUSED,
ConnectionReset => ERRNO_CONNRESET,
HostUnreachable => ERRNO_HOSTUNREACH,
NetworkDown => ERRNO_NETDOWN,
NetworkUnreachable => ERRNO_NETUNREACH,
Timedout => ERRNO_TIMEDOUT,
*/
_ => unreachable!(),
}
}
}

/// Concurrently poll for the occurrence of a set of events.
#[no_mangle]
pub unsafe extern "C" fn poll_oneoff(
Expand Down Expand Up @@ -1852,25 +1826,6 @@ pub unsafe extern "C" fn poll_oneoff(
}
Err(e) => (e.into(), 1, 0),
},
StreamType::Socket(_connection) => {
unreachable!() // TODO
/*
match tcp::bytes_readable(*connection) {
Ok(result) => (
ERRNO_SUCCESS,
result.0,
if result.1 {
EVENTRWFLAGS_FD_READWRITE_HANGUP
} else {
0
}
)
Err(e) => {
(e.into(), 1, 0)
}
}
*/
}
StreamType::Stdio(_) => (ERRNO_SUCCESS, 1, 0),
},
_ => unreachable!(),
Expand All @@ -1885,25 +1840,6 @@ pub unsafe extern "C" fn poll_oneoff(
match desc {
Descriptor::Streams(streams) => match &streams.type_ {
StreamType::File(_) | StreamType::Stdio(_) => (ERRNO_SUCCESS, 1, 0),
StreamType::Socket(_connection) => {
unreachable!() // TODO
/*
match tcp::bytes_writable(connection) {
Ok(result) => (
ERRNO_SUCCESS,
result.0,
if result.1 {
EVENTRWFLAGS_FD_READWRITE_HANGUP
} else {
0
}
)
Err(e) => {
(e.into(), 0, 0)
}
}
*/
}
},
_ => unreachable!(),
}
Expand Down