Skip to content

Commit

Permalink
Remove unimplemented sockets from preview1 adapter (#7543)
Browse files Browse the repository at this point in the history
This commit removes the usage of wasi:sockets from the preview1 adapter.
It's never been implemented but has the side effect of requiring TCP
support to be imported into components even though it's never used. This
commit removes the stubs in the adapter to get filled in at a later date
if necessary.
  • Loading branch information
alexcrichton authored Nov 15, 2023
1 parent 15ca47d commit 82c3e0a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 81 deletions.
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

0 comments on commit 82c3e0a

Please sign in to comment.