Skip to content

Commit be2d331

Browse files
yoshuawuytsCopilot
andcommitted
adapt p3 backend to modular facades
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 889ec7b commit be2d331

8 files changed

Lines changed: 26 additions & 42 deletions

File tree

src/runtime.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
1010
pub use ::async_task::Task;
1111

12-
pub use crate::sys::runtime::{AsyncPollable, Reactor, WaitFor, block_on};
12+
#[cfg(wstd_p3)]
13+
#[doc(hidden)]
14+
pub use crate::sys::runtime::{__MainReturn, __finish_main};
15+
#[cfg(wstd_p2)]
16+
pub use crate::sys::runtime::{AsyncPollable, WaitFor};
17+
pub use crate::sys::runtime::{Reactor, block_on};
1318

1419
/// Spawn a `Future` as a `Task` on the current `Reactor`.
1520
///

src/sys/p3/io.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ use std::pin::Pin;
33
use std::task::{Context, Poll};
44
use wasip3::wit_bindgen::rt::async_support::{StreamReader, StreamResult, StreamWriter};
55

6+
mod stdio;
7+
8+
pub use stdio::*;
9+
610
/// A wrapper for a p3 `StreamReader<u8>` that provides `AsyncRead`.
711
pub struct AsyncInputStream {
812
reader: StreamReader<u8>,

src/sys/p3/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
pub mod http;
22
pub mod io;
33
pub mod net;
4-
pub mod random;
4+
pub mod rand;
55
pub mod runtime;
6-
pub mod stdio;
76
pub mod time;

src/sys/p3/net/tcp_stream.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ impl TcpStream {
9393
}
9494

9595
/// Returns the socket address of the remote peer of this TCP connection.
96-
pub fn peer_addr(&self) -> io::Result<SocketAddr> {
96+
pub fn peer_addr(&self) -> io::Result<String> {
9797
self.socket
9898
.get_remote_address()
9999
.map_err(to_io_err)
100100
.map(sockaddr_from_wasi)
101+
.map(|addr| addr.to_string())
101102
}
102103

103104
pub fn split(&self) -> (ReadHalf<'_>, WriteHalf<'_>) {

src/sys/p3/rand.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! Random number generation.
2+
3+
use wasip3::random;
4+
5+
/// Return `len` cryptographically secure random bytes.
6+
pub fn random_bytes(len: u64) -> Vec<u8> {
7+
random::random::get_random_bytes(len)
8+
}
9+
10+
/// Return `len` insecure, non-cryptographic random bytes.
11+
pub fn insecure_random_bytes(len: u64) -> Vec<u8> {
12+
random::insecure::get_insecure_random_bytes(len)
13+
}

src/sys/p3/random.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/sys/p3/runtime.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
pub use ::async_task::Task;
2-
31
use async_task::{Runnable, Task as AsyncTask};
42
use core::future::Future;
53
use std::cell::RefCell;
@@ -72,17 +70,6 @@ impl<E: core::fmt::Debug> __MainReturn for Result<(), E> {
7270
}
7371
}
7472

75-
/// Spawn a `Future` as a `Task` on the current `Reactor`.
76-
///
77-
/// Panics if called from outside `block_on`.
78-
pub fn spawn<F, T>(fut: F) -> Task<T>
79-
where
80-
F: std::future::Future<Output = T> + 'static,
81-
T: 'static,
82-
{
83-
Reactor::current().spawn(fut)
84-
}
85-
8673
/// Manage async task scheduling for WASI 0.3
8774
#[derive(Debug, Clone)]
8875
pub struct Reactor {

0 commit comments

Comments
 (0)