Skip to content

Commit 40c1f29

Browse files
committed
Rename Host* things to avoid name conflicts with bindings.
1 parent ae79894 commit 40c1f29

File tree

6 files changed

+42
-36
lines changed

6 files changed

+42
-36
lines changed

crates/wasi/src/preview2/host/instance_network.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::preview2::bindings::sockets::instance_network::{self, Network};
2-
use crate::preview2::network::{HostNetwork, TableNetworkExt};
2+
use crate::preview2::network::{HostNetworkState, TableNetworkExt};
33
use crate::preview2::WasiView;
44

55
impl<T: WasiView> instance_network::Host for T {
66
fn instance_network(&mut self) -> Result<Network, anyhow::Error> {
7-
let network = HostNetwork::new(self.ctx().pool.clone());
7+
let network = HostNetworkState::new(self.ctx().pool.clone());
88
let network = self.table_mut().push_network(network)?;
99
Ok(network)
1010
}

crates/wasi/src/preview2/host/tcp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::preview2::bindings::{
77
use crate::preview2::network::TableNetworkExt;
88
use crate::preview2::poll::TablePollableExt;
99
use crate::preview2::stream::TableStreamExt;
10-
use crate::preview2::tcp::{HostTcpSocket, HostTcpState, TableTcpSocketExt};
10+
use crate::preview2::tcp::{HostTcpSocketState, HostTcpState, TableTcpSocketExt};
1111
use crate::preview2::{HostPollable, PollableFuture, WasiView};
1212
use cap_net_ext::{Blocking, PoolExt, TcpListenerExt};
1313
use cap_std::net::TcpListener;
@@ -202,7 +202,7 @@ impl<T: WasiView> tcp::Host for T {
202202
.as_socketlike_view::<TcpListener>()
203203
.accept_with(Blocking::No)
204204
})?;
205-
let mut tcp_socket = HostTcpSocket::from_tcp_stream(connection)?;
205+
let mut tcp_socket = HostTcpSocketState::from_tcp_stream(connection)?;
206206

207207
// Mark the socket as connected so that we can exit early from methods like `start-bind`.
208208
tcp_socket.tcp_state = HostTcpState::Connected;
@@ -415,7 +415,7 @@ impl<T: WasiView> tcp::Host for T {
415415
fn subscribe(&mut self, this: tcp::TcpSocket) -> anyhow::Result<Pollable> {
416416
fn make_tcp_socket_future<'a>(stream: &'a mut dyn Any) -> PollableFuture<'a> {
417417
let socket = stream
418-
.downcast_mut::<HostTcpSocket>()
418+
.downcast_mut::<HostTcpSocketState>()
419419
.expect("downcast to HostTcpSocket failed");
420420

421421
// Some states are ready immediately.

crates/wasi/src/preview2/host/tcp_create_socket.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use crate::preview2::bindings::{
33
sockets::tcp::TcpSocket,
44
sockets::tcp_create_socket,
55
};
6-
use crate::preview2::tcp::{HostTcpSocket, TableTcpSocketExt};
6+
use crate::preview2::tcp::{HostTcpSocketState, TableTcpSocketExt};
77
use crate::preview2::WasiView;
88

99
impl<T: WasiView> tcp_create_socket::Host for T {
1010
fn create_tcp_socket(
1111
&mut self,
1212
address_family: IpAddressFamily,
1313
) -> Result<TcpSocket, network::Error> {
14-
let socket = HostTcpSocket::new(address_family.into())?;
14+
let socket = HostTcpSocketState::new(address_family.into())?;
1515
let socket = self.table_mut().push_tcp_socket(socket)?;
1616
Ok(socket)
1717
}

crates/wasi/src/preview2/network.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
use crate::preview2::{Table, TableError};
22
use cap_std::net::Pool;
33

4-
pub(crate) struct HostNetwork(pub(crate) Pool);
4+
pub(crate) struct HostNetworkState(pub(crate) Pool);
55

6-
impl HostNetwork {
6+
impl HostNetworkState {
77
pub fn new(pool: Pool) -> Self {
88
Self(pool)
99
}
1010
}
1111

1212
pub(crate) trait TableNetworkExt {
13-
fn push_network(&mut self, network: HostNetwork) -> Result<u32, TableError>;
14-
fn delete_network(&mut self, fd: u32) -> Result<HostNetwork, TableError>;
13+
fn push_network(&mut self, network: HostNetworkState) -> Result<u32, TableError>;
14+
fn delete_network(&mut self, fd: u32) -> Result<HostNetworkState, TableError>;
1515
fn is_network(&self, fd: u32) -> bool;
16-
fn get_network(&self, fd: u32) -> Result<&HostNetwork, TableError>;
16+
fn get_network(&self, fd: u32) -> Result<&HostNetworkState, TableError>;
1717
}
1818

1919
impl TableNetworkExt for Table {
20-
fn push_network(&mut self, network: HostNetwork) -> Result<u32, TableError> {
20+
fn push_network(&mut self, network: HostNetworkState) -> Result<u32, TableError> {
2121
self.push(Box::new(network))
2222
}
23-
fn delete_network(&mut self, fd: u32) -> Result<HostNetwork, TableError> {
23+
fn delete_network(&mut self, fd: u32) -> Result<HostNetworkState, TableError> {
2424
self.delete(fd)
2525
}
2626
fn is_network(&self, fd: u32) -> bool {
27-
self.is::<HostNetwork>(fd)
27+
self.is::<HostNetworkState>(fd)
2828
}
29-
fn get_network(&self, fd: u32) -> Result<&HostNetwork, TableError> {
29+
fn get_network(&self, fd: u32) -> Result<&HostNetworkState, TableError> {
3030
self.get(fd)
3131
}
3232
}

crates/wasi/src/preview2/stdio.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,25 +110,27 @@ impl<T: WasiView> stderr::Host for T {
110110
}
111111
}
112112

113-
struct HostTerminalInput;
114-
struct HostTerminalOutput;
113+
struct HostTerminalInputState;
114+
struct HostTerminalOutputState;
115115

116116
impl<T: WasiView> terminal_input::Host for T {
117117
fn drop_terminal_input(&mut self, r: terminal_input::TerminalInput) -> anyhow::Result<()> {
118-
self.table_mut().delete::<HostTerminalInput>(r)?;
118+
self.table_mut().delete::<HostTerminalInputState>(r)?;
119119
Ok(())
120120
}
121121
}
122122
impl<T: WasiView> terminal_output::Host for T {
123123
fn drop_terminal_output(&mut self, r: terminal_output::TerminalOutput) -> anyhow::Result<()> {
124-
self.table_mut().delete::<HostTerminalOutput>(r)?;
124+
self.table_mut().delete::<HostTerminalOutputState>(r)?;
125125
Ok(())
126126
}
127127
}
128128
impl<T: WasiView> terminal_stdin::Host for T {
129129
fn get_terminal_stdin(&mut self) -> anyhow::Result<Option<terminal_input::TerminalInput>> {
130130
if let IsATTY::Yes = self.ctx().stdin.isatty {
131-
Ok(Some(self.table_mut().push(Box::new(HostTerminalInput))?))
131+
Ok(Some(
132+
self.table_mut().push(Box::new(HostTerminalInputState))?,
133+
))
132134
} else {
133135
Ok(None)
134136
}
@@ -137,7 +139,9 @@ impl<T: WasiView> terminal_stdin::Host for T {
137139
impl<T: WasiView> terminal_stdout::Host for T {
138140
fn get_terminal_stdout(&mut self) -> anyhow::Result<Option<terminal_output::TerminalOutput>> {
139141
if let IsATTY::Yes = self.ctx().stdout.isatty {
140-
Ok(Some(self.table_mut().push(Box::new(HostTerminalOutput))?))
142+
Ok(Some(
143+
self.table_mut().push(Box::new(HostTerminalOutputState))?,
144+
))
141145
} else {
142146
Ok(None)
143147
}
@@ -146,7 +150,9 @@ impl<T: WasiView> terminal_stdout::Host for T {
146150
impl<T: WasiView> terminal_stderr::Host for T {
147151
fn get_terminal_stderr(&mut self) -> anyhow::Result<Option<terminal_output::TerminalOutput>> {
148152
if let IsATTY::Yes = self.ctx().stderr.isatty {
149-
Ok(Some(self.table_mut().push(Box::new(HostTerminalOutput))?))
153+
Ok(Some(
154+
self.table_mut().push(Box::new(HostTerminalOutputState))?,
155+
))
150156
} else {
151157
Ok(None)
152158
}

crates/wasi/src/preview2/tcp.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ pub(crate) enum HostTcpState {
4343
///
4444
/// The inner state is wrapped in an Arc because the same underlying socket is
4545
/// used for implementing the stream types.
46-
pub(crate) struct HostTcpSocket {
47-
/// The part of a `HostTcpSocket` which is reference-counted so that we
46+
pub(crate) struct HostTcpSocketState {
47+
/// The part of a `HostTcpSocketState` which is reference-counted so that we
4848
/// can pass it to async tasks.
4949
pub(crate) inner: Arc<tokio::net::TcpStream>,
5050

@@ -213,7 +213,7 @@ impl HostOutputStream for TcpWriteStream {
213213
}
214214
}
215215

216-
impl HostTcpSocket {
216+
impl HostTcpSocketState {
217217
/// Create a new socket in the given family.
218218
pub fn new(family: AddressFamily) -> io::Result<Self> {
219219
// Create a new host socket and set it to non-blocking, which is needed
@@ -222,7 +222,7 @@ impl HostTcpSocket {
222222
Self::from_tcp_listener(tcp_listener)
223223
}
224224

225-
/// Create a `HostTcpSocket` from an existing socket.
225+
/// Create a `HostTcpSocketState` from an existing socket.
226226
///
227227
/// The socket must be in non-blocking mode.
228228
pub fn from_tcp_stream(tcp_socket: cap_std::net::TcpStream) -> io::Result<Self> {
@@ -254,27 +254,27 @@ impl HostTcpSocket {
254254
}
255255

256256
pub(crate) trait TableTcpSocketExt {
257-
fn push_tcp_socket(&mut self, tcp_socket: HostTcpSocket) -> Result<u32, TableError>;
258-
fn delete_tcp_socket(&mut self, fd: u32) -> Result<HostTcpSocket, TableError>;
257+
fn push_tcp_socket(&mut self, tcp_socket: HostTcpSocketState) -> Result<u32, TableError>;
258+
fn delete_tcp_socket(&mut self, fd: u32) -> Result<HostTcpSocketState, TableError>;
259259
fn is_tcp_socket(&self, fd: u32) -> bool;
260-
fn get_tcp_socket(&self, fd: u32) -> Result<&HostTcpSocket, TableError>;
261-
fn get_tcp_socket_mut(&mut self, fd: u32) -> Result<&mut HostTcpSocket, TableError>;
260+
fn get_tcp_socket(&self, fd: u32) -> Result<&HostTcpSocketState, TableError>;
261+
fn get_tcp_socket_mut(&mut self, fd: u32) -> Result<&mut HostTcpSocketState, TableError>;
262262
}
263263

264264
impl TableTcpSocketExt for Table {
265-
fn push_tcp_socket(&mut self, tcp_socket: HostTcpSocket) -> Result<u32, TableError> {
265+
fn push_tcp_socket(&mut self, tcp_socket: HostTcpSocketState) -> Result<u32, TableError> {
266266
self.push(Box::new(tcp_socket))
267267
}
268-
fn delete_tcp_socket(&mut self, fd: u32) -> Result<HostTcpSocket, TableError> {
268+
fn delete_tcp_socket(&mut self, fd: u32) -> Result<HostTcpSocketState, TableError> {
269269
self.delete(fd)
270270
}
271271
fn is_tcp_socket(&self, fd: u32) -> bool {
272-
self.is::<HostTcpSocket>(fd)
272+
self.is::<HostTcpSocketState>(fd)
273273
}
274-
fn get_tcp_socket(&self, fd: u32) -> Result<&HostTcpSocket, TableError> {
274+
fn get_tcp_socket(&self, fd: u32) -> Result<&HostTcpSocketState, TableError> {
275275
self.get(fd)
276276
}
277-
fn get_tcp_socket_mut(&mut self, fd: u32) -> Result<&mut HostTcpSocket, TableError> {
277+
fn get_tcp_socket_mut(&mut self, fd: u32) -> Result<&mut HostTcpSocketState, TableError> {
278278
self.get_mut(fd)
279279
}
280280
}

0 commit comments

Comments
 (0)