| 1 |
// Generated by `wit-bindgen` 0.46.0. DO NOT EDIT! |
| 2 |
// Options used: |
| 3 |
// * std_feature |
| 4 |
// * type_section_suffix: "rust-wasip2-1.0.1+wasi-0.2.4-from-crates-io" |
| 5 |
#[rustfmt::skip] |
| 6 |
#[allow(dead_code, clippy::all)] |
| 7 |
pub mod wasi { |
| 8 |
pub mod cli { |
| 9 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 10 |
pub mod environment { |
| 11 |
#[used] |
| 12 |
#[doc(hidden)] |
| 13 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 14 |
use super::super::super::_rt; |
| 15 |
#[allow(unused_unsafe, clippy::all)] |
| 16 |
/// Get the POSIX-style environment variables. |
| 17 |
/// |
| 18 |
/// Each environment variable is provided as a pair of string variable names |
| 19 |
/// and string value. |
| 20 |
/// |
| 21 |
/// Morally, these are a value import, but until value imports are available |
| 22 |
/// in the component model, this import function should return the same |
| 23 |
/// values each time it is called. |
| 24 |
#[allow(async_fn_in_trait)] |
| 25 |
pub fn get_environment() -> _rt::Vec<(_rt::String, _rt::String)> { |
| 26 |
unsafe { |
| 27 |
#[cfg_attr(target_pointer_width = "64", repr(align(8)))] |
| 28 |
#[cfg_attr(target_pointer_width = "32", repr(align(4)))] |
| 29 |
struct RetArea( |
| 30 |
[::core::mem::MaybeUninit< |
| 31 |
u8, |
| 32 |
>; 2 * ::core::mem::size_of::<*const u8>()], |
| 33 |
); |
| 34 |
let mut ret_area = RetArea( |
| 35 |
[::core::mem::MaybeUninit::uninit(); 2 |
| 36 |
* ::core::mem::size_of::<*const u8>()], |
| 37 |
); |
| 38 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 39 |
#[cfg(target_arch = "wasm32")] |
| 40 |
#[link(wasm_import_module = "wasi:cli/[email protected]")] |
| 41 |
unsafe extern "C" { |
| 42 |
#[link_name = "get-environment"] |
| 43 |
fn wit_import1(_: *mut u8); |
| 44 |
} |
| 45 |
#[cfg(not(target_arch = "wasm32"))] |
| 46 |
unsafe extern "C" fn wit_import1(_: *mut u8) { |
| 47 |
unreachable!() |
| 48 |
} |
| 49 |
wit_import1(ptr0); |
| 50 |
let l2 = *ptr0.add(0).cast::<*mut u8>(); |
| 51 |
let l3 = *ptr0 |
| 52 |
.add(::core::mem::size_of::<*const u8>()) |
| 53 |
.cast::<usize>(); |
| 54 |
let base10 = l2; |
| 55 |
let len10 = l3; |
| 56 |
let mut result10 = _rt::Vec::with_capacity(len10); |
| 57 |
for i in 0..len10 { |
| 58 |
let base = base10 |
| 59 |
.add(i * (4 * ::core::mem::size_of::<*const u8>())); |
| 60 |
let e10 = { |
| 61 |
let l4 = *base.add(0).cast::<*mut u8>(); |
| 62 |
let l5 = *base |
| 63 |
.add(::core::mem::size_of::<*const u8>()) |
| 64 |
.cast::<usize>(); |
| 65 |
let len6 = l5; |
| 66 |
let bytes6 = _rt::Vec::from_raw_parts(l4.cast(), len6, len6); |
| 67 |
let l7 = *base |
| 68 |
.add(2 * ::core::mem::size_of::<*const u8>()) |
| 69 |
.cast::<*mut u8>(); |
| 70 |
let l8 = *base |
| 71 |
.add(3 * ::core::mem::size_of::<*const u8>()) |
| 72 |
.cast::<usize>(); |
| 73 |
let len9 = l8; |
| 74 |
let bytes9 = _rt::Vec::from_raw_parts(l7.cast(), len9, len9); |
| 75 |
(_rt::string_lift(bytes6), _rt::string_lift(bytes9)) |
| 76 |
}; |
| 77 |
result10.push(e10); |
| 78 |
} |
| 79 |
_rt::cabi_dealloc( |
| 80 |
base10, |
| 81 |
len10 * (4 * ::core::mem::size_of::<*const u8>()), |
| 82 |
::core::mem::size_of::<*const u8>(), |
| 83 |
); |
| 84 |
let result11 = result10; |
| 85 |
result11 |
| 86 |
} |
| 87 |
} |
| 88 |
#[allow(unused_unsafe, clippy::all)] |
| 89 |
/// Get the POSIX-style arguments to the program. |
| 90 |
#[allow(async_fn_in_trait)] |
| 91 |
pub fn get_arguments() -> _rt::Vec<_rt::String> { |
| 92 |
unsafe { |
| 93 |
#[cfg_attr(target_pointer_width = "64", repr(align(8)))] |
| 94 |
#[cfg_attr(target_pointer_width = "32", repr(align(4)))] |
| 95 |
struct RetArea( |
| 96 |
[::core::mem::MaybeUninit< |
| 97 |
u8, |
| 98 |
>; 2 * ::core::mem::size_of::<*const u8>()], |
| 99 |
); |
| 100 |
let mut ret_area = RetArea( |
| 101 |
[::core::mem::MaybeUninit::uninit(); 2 |
| 102 |
* ::core::mem::size_of::<*const u8>()], |
| 103 |
); |
| 104 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 105 |
#[cfg(target_arch = "wasm32")] |
| 106 |
#[link(wasm_import_module = "wasi:cli/[email protected]")] |
| 107 |
unsafe extern "C" { |
| 108 |
#[link_name = "get-arguments"] |
| 109 |
fn wit_import1(_: *mut u8); |
| 110 |
} |
| 111 |
#[cfg(not(target_arch = "wasm32"))] |
| 112 |
unsafe extern "C" fn wit_import1(_: *mut u8) { |
| 113 |
unreachable!() |
| 114 |
} |
| 115 |
wit_import1(ptr0); |
| 116 |
let l2 = *ptr0.add(0).cast::<*mut u8>(); |
| 117 |
let l3 = *ptr0 |
| 118 |
.add(::core::mem::size_of::<*const u8>()) |
| 119 |
.cast::<usize>(); |
| 120 |
let base7 = l2; |
| 121 |
let len7 = l3; |
| 122 |
let mut result7 = _rt::Vec::with_capacity(len7); |
| 123 |
for i in 0..len7 { |
| 124 |
let base = base7 |
| 125 |
.add(i * (2 * ::core::mem::size_of::<*const u8>())); |
| 126 |
let e7 = { |
| 127 |
let l4 = *base.add(0).cast::<*mut u8>(); |
| 128 |
let l5 = *base |
| 129 |
.add(::core::mem::size_of::<*const u8>()) |
| 130 |
.cast::<usize>(); |
| 131 |
let len6 = l5; |
| 132 |
let bytes6 = _rt::Vec::from_raw_parts(l4.cast(), len6, len6); |
| 133 |
_rt::string_lift(bytes6) |
| 134 |
}; |
| 135 |
result7.push(e7); |
| 136 |
} |
| 137 |
_rt::cabi_dealloc( |
| 138 |
base7, |
| 139 |
len7 * (2 * ::core::mem::size_of::<*const u8>()), |
| 140 |
::core::mem::size_of::<*const u8>(), |
| 141 |
); |
| 142 |
let result8 = result7; |
| 143 |
result8 |
| 144 |
} |
| 145 |
} |
| 146 |
#[allow(unused_unsafe, clippy::all)] |
| 147 |
/// Return a path that programs should use as their initial current working |
| 148 |
/// directory, interpreting `.` as shorthand for this. |
| 149 |
#[allow(async_fn_in_trait)] |
| 150 |
pub fn initial_cwd() -> Option<_rt::String> { |
| 151 |
unsafe { |
| 152 |
#[cfg_attr(target_pointer_width = "64", repr(align(8)))] |
| 153 |
#[cfg_attr(target_pointer_width = "32", repr(align(4)))] |
| 154 |
struct RetArea( |
| 155 |
[::core::mem::MaybeUninit< |
| 156 |
u8, |
| 157 |
>; 3 * ::core::mem::size_of::<*const u8>()], |
| 158 |
); |
| 159 |
let mut ret_area = RetArea( |
| 160 |
[::core::mem::MaybeUninit::uninit(); 3 |
| 161 |
* ::core::mem::size_of::<*const u8>()], |
| 162 |
); |
| 163 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 164 |
#[cfg(target_arch = "wasm32")] |
| 165 |
#[link(wasm_import_module = "wasi:cli/[email protected]")] |
| 166 |
unsafe extern "C" { |
| 167 |
#[link_name = "initial-cwd"] |
| 168 |
fn wit_import1(_: *mut u8); |
| 169 |
} |
| 170 |
#[cfg(not(target_arch = "wasm32"))] |
| 171 |
unsafe extern "C" fn wit_import1(_: *mut u8) { |
| 172 |
unreachable!() |
| 173 |
} |
| 174 |
wit_import1(ptr0); |
| 175 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 176 |
let result6 = match l2 { |
| 177 |
0 => None, |
| 178 |
1 => { |
| 179 |
let e = { |
| 180 |
let l3 = *ptr0 |
| 181 |
.add(::core::mem::size_of::<*const u8>()) |
| 182 |
.cast::<*mut u8>(); |
| 183 |
let l4 = *ptr0 |
| 184 |
.add(2 * ::core::mem::size_of::<*const u8>()) |
| 185 |
.cast::<usize>(); |
| 186 |
let len5 = l4; |
| 187 |
let bytes5 = _rt::Vec::from_raw_parts( |
| 188 |
l3.cast(), |
| 189 |
len5, |
| 190 |
len5, |
| 191 |
); |
| 192 |
_rt::string_lift(bytes5) |
| 193 |
}; |
| 194 |
Some(e) |
| 195 |
} |
| 196 |
_ => _rt::invalid_enum_discriminant(), |
| 197 |
}; |
| 198 |
result6 |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 203 |
pub mod exit { |
| 204 |
#[used] |
| 205 |
#[doc(hidden)] |
| 206 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 207 |
#[allow(unused_unsafe, clippy::all)] |
| 208 |
/// Exit the current instance and any linked instances. |
| 209 |
#[allow(async_fn_in_trait)] |
| 210 |
pub fn exit(status: Result<(), ()>) -> () { |
| 211 |
unsafe { |
| 212 |
let result0 = match status { |
| 213 |
Ok(_) => 0i32, |
| 214 |
Err(_) => 1i32, |
| 215 |
}; |
| 216 |
#[cfg(target_arch = "wasm32")] |
| 217 |
#[link(wasm_import_module = "wasi:cli/[email protected]")] |
| 218 |
unsafe extern "C" { |
| 219 |
#[link_name = "exit"] |
| 220 |
fn wit_import1(_: i32); |
| 221 |
} |
| 222 |
#[cfg(not(target_arch = "wasm32"))] |
| 223 |
unsafe extern "C" fn wit_import1(_: i32) { |
| 224 |
unreachable!() |
| 225 |
} |
| 226 |
wit_import1(result0); |
| 227 |
} |
| 228 |
} |
| 229 |
} |
| 230 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 231 |
pub mod stdin { |
| 232 |
#[used] |
| 233 |
#[doc(hidden)] |
| 234 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 235 |
pub type InputStream = super::super::super::wasi::io::streams::InputStream; |
| 236 |
#[allow(unused_unsafe, clippy::all)] |
| 237 |
#[allow(async_fn_in_trait)] |
| 238 |
pub fn get_stdin() -> InputStream { |
| 239 |
unsafe { |
| 240 |
#[cfg(target_arch = "wasm32")] |
| 241 |
#[link(wasm_import_module = "wasi:cli/[email protected]")] |
| 242 |
unsafe extern "C" { |
| 243 |
#[link_name = "get-stdin"] |
| 244 |
fn wit_import0() -> i32; |
| 245 |
} |
| 246 |
#[cfg(not(target_arch = "wasm32"))] |
| 247 |
unsafe extern "C" fn wit_import0() -> i32 { |
| 248 |
unreachable!() |
| 249 |
} |
| 250 |
let ret = wit_import0(); |
| 251 |
super::super::super::wasi::io::streams::InputStream::from_handle( |
| 252 |
ret as u32, |
| 253 |
) |
| 254 |
} |
| 255 |
} |
| 256 |
} |
| 257 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 258 |
pub mod stdout { |
| 259 |
#[used] |
| 260 |
#[doc(hidden)] |
| 261 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 262 |
pub type OutputStream = super::super::super::wasi::io::streams::OutputStream; |
| 263 |
#[allow(unused_unsafe, clippy::all)] |
| 264 |
#[allow(async_fn_in_trait)] |
| 265 |
pub fn get_stdout() -> OutputStream { |
| 266 |
unsafe { |
| 267 |
#[cfg(target_arch = "wasm32")] |
| 268 |
#[link(wasm_import_module = "wasi:cli/[email protected]")] |
| 269 |
unsafe extern "C" { |
| 270 |
#[link_name = "get-stdout"] |
| 271 |
fn wit_import0() -> i32; |
| 272 |
} |
| 273 |
#[cfg(not(target_arch = "wasm32"))] |
| 274 |
unsafe extern "C" fn wit_import0() -> i32 { |
| 275 |
unreachable!() |
| 276 |
} |
| 277 |
let ret = wit_import0(); |
| 278 |
super::super::super::wasi::io::streams::OutputStream::from_handle( |
| 279 |
ret as u32, |
| 280 |
) |
| 281 |
} |
| 282 |
} |
| 283 |
} |
| 284 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 285 |
pub mod stderr { |
| 286 |
#[used] |
| 287 |
#[doc(hidden)] |
| 288 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 289 |
pub type OutputStream = super::super::super::wasi::io::streams::OutputStream; |
| 290 |
#[allow(unused_unsafe, clippy::all)] |
| 291 |
#[allow(async_fn_in_trait)] |
| 292 |
pub fn get_stderr() -> OutputStream { |
| 293 |
unsafe { |
| 294 |
#[cfg(target_arch = "wasm32")] |
| 295 |
#[link(wasm_import_module = "wasi:cli/[email protected]")] |
| 296 |
unsafe extern "C" { |
| 297 |
#[link_name = "get-stderr"] |
| 298 |
fn wit_import0() -> i32; |
| 299 |
} |
| 300 |
#[cfg(not(target_arch = "wasm32"))] |
| 301 |
unsafe extern "C" fn wit_import0() -> i32 { |
| 302 |
unreachable!() |
| 303 |
} |
| 304 |
let ret = wit_import0(); |
| 305 |
super::super::super::wasi::io::streams::OutputStream::from_handle( |
| 306 |
ret as u32, |
| 307 |
) |
| 308 |
} |
| 309 |
} |
| 310 |
} |
| 311 |
/// Terminal input. |
| 312 |
/// |
| 313 |
/// In the future, this may include functions for disabling echoing, |
| 314 |
/// disabling input buffering so that keyboard events are sent through |
| 315 |
/// immediately, querying supported features, and so on. |
| 316 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 317 |
pub mod terminal_input { |
| 318 |
#[used] |
| 319 |
#[doc(hidden)] |
| 320 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 321 |
use super::super::super::_rt; |
| 322 |
/// The input side of a terminal. |
| 323 |
#[derive(Debug)] |
| 324 |
#[repr(transparent)] |
| 325 |
pub struct TerminalInput { |
| 326 |
handle: _rt::Resource<TerminalInput>, |
| 327 |
} |
| 328 |
impl TerminalInput { |
| 329 |
#[doc(hidden)] |
| 330 |
pub unsafe fn from_handle(handle: u32) -> Self { |
| 331 |
Self { |
| 332 |
handle: unsafe { _rt::Resource::from_handle(handle) }, |
| 333 |
} |
| 334 |
} |
| 335 |
#[doc(hidden)] |
| 336 |
pub fn take_handle(&self) -> u32 { |
| 337 |
_rt::Resource::take_handle(&self.handle) |
| 338 |
} |
| 339 |
#[doc(hidden)] |
| 340 |
pub fn handle(&self) -> u32 { |
| 341 |
_rt::Resource::handle(&self.handle) |
| 342 |
} |
| 343 |
} |
| 344 |
unsafe impl _rt::WasmResource for TerminalInput { |
| 345 |
#[inline] |
| 346 |
unsafe fn drop(_handle: u32) { |
| 347 |
#[cfg(target_arch = "wasm32")] |
| 348 |
#[link(wasm_import_module = "wasi:cli/[email protected]")] |
| 349 |
unsafe extern "C" { |
| 350 |
#[link_name = "[resource-drop]terminal-input"] |
| 351 |
fn drop(_: i32); |
| 352 |
} |
| 353 |
#[cfg(not(target_arch = "wasm32"))] |
| 354 |
unsafe extern "C" fn drop(_: i32) { |
| 355 |
unreachable!() |
| 356 |
} |
| 357 |
unsafe { |
| 358 |
drop(_handle as i32); |
| 359 |
} |
| 360 |
} |
| 361 |
} |
| 362 |
} |
| 363 |
/// Terminal output. |
| 364 |
/// |
| 365 |
/// In the future, this may include functions for querying the terminal |
| 366 |
/// size, being notified of terminal size changes, querying supported |
| 367 |
/// features, and so on. |
| 368 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 369 |
pub mod terminal_output { |
| 370 |
#[used] |
| 371 |
#[doc(hidden)] |
| 372 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 373 |
use super::super::super::_rt; |
| 374 |
/// The output side of a terminal. |
| 375 |
#[derive(Debug)] |
| 376 |
#[repr(transparent)] |
| 377 |
pub struct TerminalOutput { |
| 378 |
handle: _rt::Resource<TerminalOutput>, |
| 379 |
} |
| 380 |
impl TerminalOutput { |
| 381 |
#[doc(hidden)] |
| 382 |
pub unsafe fn from_handle(handle: u32) -> Self { |
| 383 |
Self { |
| 384 |
handle: unsafe { _rt::Resource::from_handle(handle) }, |
| 385 |
} |
| 386 |
} |
| 387 |
#[doc(hidden)] |
| 388 |
pub fn take_handle(&self) -> u32 { |
| 389 |
_rt::Resource::take_handle(&self.handle) |
| 390 |
} |
| 391 |
#[doc(hidden)] |
| 392 |
pub fn handle(&self) -> u32 { |
| 393 |
_rt::Resource::handle(&self.handle) |
| 394 |
} |
| 395 |
} |
| 396 |
unsafe impl _rt::WasmResource for TerminalOutput { |
| 397 |
#[inline] |
| 398 |
unsafe fn drop(_handle: u32) { |
| 399 |
#[cfg(target_arch = "wasm32")] |
| 400 |
#[link(wasm_import_module = "wasi:cli/[email protected]")] |
| 401 |
unsafe extern "C" { |
| 402 |
#[link_name = "[resource-drop]terminal-output"] |
| 403 |
fn drop(_: i32); |
| 404 |
} |
| 405 |
#[cfg(not(target_arch = "wasm32"))] |
| 406 |
unsafe extern "C" fn drop(_: i32) { |
| 407 |
unreachable!() |
| 408 |
} |
| 409 |
unsafe { |
| 410 |
drop(_handle as i32); |
| 411 |
} |
| 412 |
} |
| 413 |
} |
| 414 |
} |
| 415 |
/// An interface providing an optional `terminal-input` for stdin as a |
| 416 |
/// link-time authority. |
| 417 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 418 |
pub mod terminal_stdin { |
| 419 |
#[used] |
| 420 |
#[doc(hidden)] |
| 421 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 422 |
use super::super::super::_rt; |
| 423 |
pub type TerminalInput = super::super::super::wasi::cli::terminal_input::TerminalInput; |
| 424 |
#[allow(unused_unsafe, clippy::all)] |
| 425 |
/// If stdin is connected to a terminal, return a `terminal-input` handle |
| 426 |
/// allowing further interaction with it. |
| 427 |
#[allow(async_fn_in_trait)] |
| 428 |
pub fn get_terminal_stdin() -> Option<TerminalInput> { |
| 429 |
unsafe { |
| 430 |
#[repr(align(4))] |
| 431 |
struct RetArea([::core::mem::MaybeUninit<u8>; 8]); |
| 432 |
let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); |
| 433 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 434 |
#[cfg(target_arch = "wasm32")] |
| 435 |
#[link(wasm_import_module = "wasi:cli/[email protected]")] |
| 436 |
unsafe extern "C" { |
| 437 |
#[link_name = "get-terminal-stdin"] |
| 438 |
fn wit_import1(_: *mut u8); |
| 439 |
} |
| 440 |
#[cfg(not(target_arch = "wasm32"))] |
| 441 |
unsafe extern "C" fn wit_import1(_: *mut u8) { |
| 442 |
unreachable!() |
| 443 |
} |
| 444 |
wit_import1(ptr0); |
| 445 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 446 |
let result4 = match l2 { |
| 447 |
0 => None, |
| 448 |
1 => { |
| 449 |
let e = { |
| 450 |
let l3 = *ptr0.add(4).cast::<i32>(); |
| 451 |
super::super::super::wasi::cli::terminal_input::TerminalInput::from_handle( |
| 452 |
l3 as u32, |
| 453 |
) |
| 454 |
}; |
| 455 |
Some(e) |
| 456 |
} |
| 457 |
_ => _rt::invalid_enum_discriminant(), |
| 458 |
}; |
| 459 |
result4 |
| 460 |
} |
| 461 |
} |
| 462 |
} |
| 463 |
/// An interface providing an optional `terminal-output` for stdout as a |
| 464 |
/// link-time authority. |
| 465 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 466 |
pub mod terminal_stdout { |
| 467 |
#[used] |
| 468 |
#[doc(hidden)] |
| 469 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 470 |
use super::super::super::_rt; |
| 471 |
pub type TerminalOutput = super::super::super::wasi::cli::terminal_output::TerminalOutput; |
| 472 |
#[allow(unused_unsafe, clippy::all)] |
| 473 |
/// If stdout is connected to a terminal, return a `terminal-output` handle |
| 474 |
/// allowing further interaction with it. |
| 475 |
#[allow(async_fn_in_trait)] |
| 476 |
pub fn get_terminal_stdout() -> Option<TerminalOutput> { |
| 477 |
unsafe { |
| 478 |
#[repr(align(4))] |
| 479 |
struct RetArea([::core::mem::MaybeUninit<u8>; 8]); |
| 480 |
let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); |
| 481 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 482 |
#[cfg(target_arch = "wasm32")] |
| 483 |
#[link(wasm_import_module = "wasi:cli/[email protected]")] |
| 484 |
unsafe extern "C" { |
| 485 |
#[link_name = "get-terminal-stdout"] |
| 486 |
fn wit_import1(_: *mut u8); |
| 487 |
} |
| 488 |
#[cfg(not(target_arch = "wasm32"))] |
| 489 |
unsafe extern "C" fn wit_import1(_: *mut u8) { |
| 490 |
unreachable!() |
| 491 |
} |
| 492 |
wit_import1(ptr0); |
| 493 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 494 |
let result4 = match l2 { |
| 495 |
0 => None, |
| 496 |
1 => { |
| 497 |
let e = { |
| 498 |
let l3 = *ptr0.add(4).cast::<i32>(); |
| 499 |
super::super::super::wasi::cli::terminal_output::TerminalOutput::from_handle( |
| 500 |
l3 as u32, |
| 501 |
) |
| 502 |
}; |
| 503 |
Some(e) |
| 504 |
} |
| 505 |
_ => _rt::invalid_enum_discriminant(), |
| 506 |
}; |
| 507 |
result4 |
| 508 |
} |
| 509 |
} |
| 510 |
} |
| 511 |
/// An interface providing an optional `terminal-output` for stderr as a |
| 512 |
/// link-time authority. |
| 513 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 514 |
pub mod terminal_stderr { |
| 515 |
#[used] |
| 516 |
#[doc(hidden)] |
| 517 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 518 |
use super::super::super::_rt; |
| 519 |
pub type TerminalOutput = super::super::super::wasi::cli::terminal_output::TerminalOutput; |
| 520 |
#[allow(unused_unsafe, clippy::all)] |
| 521 |
/// If stderr is connected to a terminal, return a `terminal-output` handle |
| 522 |
/// allowing further interaction with it. |
| 523 |
#[allow(async_fn_in_trait)] |
| 524 |
pub fn get_terminal_stderr() -> Option<TerminalOutput> { |
| 525 |
unsafe { |
| 526 |
#[repr(align(4))] |
| 527 |
struct RetArea([::core::mem::MaybeUninit<u8>; 8]); |
| 528 |
let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); |
| 529 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 530 |
#[cfg(target_arch = "wasm32")] |
| 531 |
#[link(wasm_import_module = "wasi:cli/[email protected]")] |
| 532 |
unsafe extern "C" { |
| 533 |
#[link_name = "get-terminal-stderr"] |
| 534 |
fn wit_import1(_: *mut u8); |
| 535 |
} |
| 536 |
#[cfg(not(target_arch = "wasm32"))] |
| 537 |
unsafe extern "C" fn wit_import1(_: *mut u8) { |
| 538 |
unreachable!() |
| 539 |
} |
| 540 |
wit_import1(ptr0); |
| 541 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 542 |
let result4 = match l2 { |
| 543 |
0 => None, |
| 544 |
1 => { |
| 545 |
let e = { |
| 546 |
let l3 = *ptr0.add(4).cast::<i32>(); |
| 547 |
super::super::super::wasi::cli::terminal_output::TerminalOutput::from_handle( |
| 548 |
l3 as u32, |
| 549 |
) |
| 550 |
}; |
| 551 |
Some(e) |
| 552 |
} |
| 553 |
_ => _rt::invalid_enum_discriminant(), |
| 554 |
}; |
| 555 |
result4 |
| 556 |
} |
| 557 |
} |
| 558 |
} |
| 559 |
} |
| 560 |
pub mod clocks { |
| 561 |
/// WASI Monotonic Clock is a clock API intended to let users measure elapsed |
| 562 |
/// time. |
| 563 |
/// |
| 564 |
/// It is intended to be portable at least between Unix-family platforms and |
| 565 |
/// Windows. |
| 566 |
/// |
| 567 |
/// A monotonic clock is a clock which has an unspecified initial value, and |
| 568 |
/// successive reads of the clock will produce non-decreasing values. |
| 569 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 570 |
pub mod monotonic_clock { |
| 571 |
#[used] |
| 572 |
#[doc(hidden)] |
| 573 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 574 |
use super::super::super::_rt; |
| 575 |
pub type Pollable = super::super::super::wasi::io::poll::Pollable; |
| 576 |
/// An instant in time, in nanoseconds. An instant is relative to an |
| 577 |
/// unspecified initial value, and can only be compared to instances from |
| 578 |
/// the same monotonic-clock. |
| 579 |
pub type Instant = u64; |
| 580 |
/// A duration of time, in nanoseconds. |
| 581 |
pub type Duration = u64; |
| 582 |
#[allow(unused_unsafe, clippy::all)] |
| 583 |
/// Read the current value of the clock. |
| 584 |
/// |
| 585 |
/// The clock is monotonic, therefore calling this function repeatedly will |
| 586 |
/// produce a sequence of non-decreasing values. |
| 587 |
#[allow(async_fn_in_trait)] |
| 588 |
pub fn now() -> Instant { |
| 589 |
unsafe { |
| 590 |
#[cfg(target_arch = "wasm32")] |
| 591 |
#[link(wasm_import_module = "wasi:clocks/[email protected]")] |
| 592 |
unsafe extern "C" { |
| 593 |
#[link_name = "now"] |
| 594 |
fn wit_import0() -> i64; |
| 595 |
} |
| 596 |
#[cfg(not(target_arch = "wasm32"))] |
| 597 |
unsafe extern "C" fn wit_import0() -> i64 { |
| 598 |
unreachable!() |
| 599 |
} |
| 600 |
let ret = wit_import0(); |
| 601 |
ret as u64 |
| 602 |
} |
| 603 |
} |
| 604 |
#[allow(unused_unsafe, clippy::all)] |
| 605 |
/// Query the resolution of the clock. Returns the duration of time |
| 606 |
/// corresponding to a clock tick. |
| 607 |
#[allow(async_fn_in_trait)] |
| 608 |
pub fn resolution() -> Duration { |
| 609 |
unsafe { |
| 610 |
#[cfg(target_arch = "wasm32")] |
| 611 |
#[link(wasm_import_module = "wasi:clocks/[email protected]")] |
| 612 |
unsafe extern "C" { |
| 613 |
#[link_name = "resolution"] |
| 614 |
fn wit_import0() -> i64; |
| 615 |
} |
| 616 |
#[cfg(not(target_arch = "wasm32"))] |
| 617 |
unsafe extern "C" fn wit_import0() -> i64 { |
| 618 |
unreachable!() |
| 619 |
} |
| 620 |
let ret = wit_import0(); |
| 621 |
ret as u64 |
| 622 |
} |
| 623 |
} |
| 624 |
#[allow(unused_unsafe, clippy::all)] |
| 625 |
/// Create a `pollable` which will resolve once the specified instant |
| 626 |
/// has occurred. |
| 627 |
#[allow(async_fn_in_trait)] |
| 628 |
pub fn subscribe_instant(when: Instant) -> Pollable { |
| 629 |
unsafe { |
| 630 |
#[cfg(target_arch = "wasm32")] |
| 631 |
#[link(wasm_import_module = "wasi:clocks/[email protected]")] |
| 632 |
unsafe extern "C" { |
| 633 |
#[link_name = "subscribe-instant"] |
| 634 |
fn wit_import0(_: i64) -> i32; |
| 635 |
} |
| 636 |
#[cfg(not(target_arch = "wasm32"))] |
| 637 |
unsafe extern "C" fn wit_import0(_: i64) -> i32 { |
| 638 |
unreachable!() |
| 639 |
} |
| 640 |
let ret = wit_import0(_rt::as_i64(when)); |
| 641 |
super::super::super::wasi::io::poll::Pollable::from_handle( |
| 642 |
ret as u32, |
| 643 |
) |
| 644 |
} |
| 645 |
} |
| 646 |
#[allow(unused_unsafe, clippy::all)] |
| 647 |
/// Create a `pollable` that will resolve after the specified duration has |
| 648 |
/// elapsed from the time this function is invoked. |
| 649 |
#[allow(async_fn_in_trait)] |
| 650 |
pub fn subscribe_duration(when: Duration) -> Pollable { |
| 651 |
unsafe { |
| 652 |
#[cfg(target_arch = "wasm32")] |
| 653 |
#[link(wasm_import_module = "wasi:clocks/[email protected]")] |
| 654 |
unsafe extern "C" { |
| 655 |
#[link_name = "subscribe-duration"] |
| 656 |
fn wit_import0(_: i64) -> i32; |
| 657 |
} |
| 658 |
#[cfg(not(target_arch = "wasm32"))] |
| 659 |
unsafe extern "C" fn wit_import0(_: i64) -> i32 { |
| 660 |
unreachable!() |
| 661 |
} |
| 662 |
let ret = wit_import0(_rt::as_i64(when)); |
| 663 |
super::super::super::wasi::io::poll::Pollable::from_handle( |
| 664 |
ret as u32, |
| 665 |
) |
| 666 |
} |
| 667 |
} |
| 668 |
} |
| 669 |
/// WASI Wall Clock is a clock API intended to let users query the current |
| 670 |
/// time. The name "wall" makes an analogy to a "clock on the wall", which |
| 671 |
/// is not necessarily monotonic as it may be reset. |
| 672 |
/// |
| 673 |
/// It is intended to be portable at least between Unix-family platforms and |
| 674 |
/// Windows. |
| 675 |
/// |
| 676 |
/// A wall clock is a clock which measures the date and time according to |
| 677 |
/// some external reference. |
| 678 |
/// |
| 679 |
/// External references may be reset, so this clock is not necessarily |
| 680 |
/// monotonic, making it unsuitable for measuring elapsed time. |
| 681 |
/// |
| 682 |
/// It is intended for reporting the current date and time for humans. |
| 683 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 684 |
pub mod wall_clock { |
| 685 |
#[used] |
| 686 |
#[doc(hidden)] |
| 687 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 688 |
/// A time and date in seconds plus nanoseconds. |
| 689 |
#[repr(C)] |
| 690 |
#[derive(Clone, Copy)] |
| 691 |
pub struct Datetime { |
| 692 |
pub seconds: u64, |
| 693 |
pub nanoseconds: u32, |
| 694 |
} |
| 695 |
impl ::core::fmt::Debug for Datetime { |
| 696 |
fn fmt( |
| 697 |
&self, |
| 698 |
f: &mut ::core::fmt::Formatter<'_>, |
| 699 |
) -> ::core::fmt::Result { |
| 700 |
f.debug_struct("Datetime") |
| 701 |
.field("seconds", &self.seconds) |
| 702 |
.field("nanoseconds", &self.nanoseconds) |
| 703 |
.finish() |
| 704 |
} |
| 705 |
} |
| 706 |
#[allow(unused_unsafe, clippy::all)] |
| 707 |
/// Read the current value of the clock. |
| 708 |
/// |
| 709 |
/// This clock is not monotonic, therefore calling this function repeatedly |
| 710 |
/// will not necessarily produce a sequence of non-decreasing values. |
| 711 |
/// |
| 712 |
/// The returned timestamps represent the number of seconds since |
| 713 |
/// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], |
| 714 |
/// also known as [Unix Time]. |
| 715 |
/// |
| 716 |
/// The nanoseconds field of the output is always less than 1000000000. |
| 717 |
/// |
| 718 |
/// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 |
| 719 |
/// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time |
| 720 |
#[allow(async_fn_in_trait)] |
| 721 |
pub fn now() -> Datetime { |
| 722 |
unsafe { |
| 723 |
#[repr(align(8))] |
| 724 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 725 |
let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); |
| 726 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 727 |
#[cfg(target_arch = "wasm32")] |
| 728 |
#[link(wasm_import_module = "wasi:clocks/[email protected]")] |
| 729 |
unsafe extern "C" { |
| 730 |
#[link_name = "now"] |
| 731 |
fn wit_import1(_: *mut u8); |
| 732 |
} |
| 733 |
#[cfg(not(target_arch = "wasm32"))] |
| 734 |
unsafe extern "C" fn wit_import1(_: *mut u8) { |
| 735 |
unreachable!() |
| 736 |
} |
| 737 |
wit_import1(ptr0); |
| 738 |
let l2 = *ptr0.add(0).cast::<i64>(); |
| 739 |
let l3 = *ptr0.add(8).cast::<i32>(); |
| 740 |
let result4 = Datetime { |
| 741 |
seconds: l2 as u64, |
| 742 |
nanoseconds: l3 as u32, |
| 743 |
}; |
| 744 |
result4 |
| 745 |
} |
| 746 |
} |
| 747 |
#[allow(unused_unsafe, clippy::all)] |
| 748 |
/// Query the resolution of the clock. |
| 749 |
/// |
| 750 |
/// The nanoseconds field of the output is always less than 1000000000. |
| 751 |
#[allow(async_fn_in_trait)] |
| 752 |
pub fn resolution() -> Datetime { |
| 753 |
unsafe { |
| 754 |
#[repr(align(8))] |
| 755 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 756 |
let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); |
| 757 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 758 |
#[cfg(target_arch = "wasm32")] |
| 759 |
#[link(wasm_import_module = "wasi:clocks/[email protected]")] |
| 760 |
unsafe extern "C" { |
| 761 |
#[link_name = "resolution"] |
| 762 |
fn wit_import1(_: *mut u8); |
| 763 |
} |
| 764 |
#[cfg(not(target_arch = "wasm32"))] |
| 765 |
unsafe extern "C" fn wit_import1(_: *mut u8) { |
| 766 |
unreachable!() |
| 767 |
} |
| 768 |
wit_import1(ptr0); |
| 769 |
let l2 = *ptr0.add(0).cast::<i64>(); |
| 770 |
let l3 = *ptr0.add(8).cast::<i32>(); |
| 771 |
let result4 = Datetime { |
| 772 |
seconds: l2 as u64, |
| 773 |
nanoseconds: l3 as u32, |
| 774 |
}; |
| 775 |
result4 |
| 776 |
} |
| 777 |
} |
| 778 |
} |
| 779 |
} |
| 780 |
pub mod filesystem { |
| 781 |
/// WASI filesystem is a filesystem API primarily intended to let users run WASI |
| 782 |
/// programs that access their files on their existing filesystems, without |
| 783 |
/// significant overhead. |
| 784 |
/// |
| 785 |
/// It is intended to be roughly portable between Unix-family platforms and |
| 786 |
/// Windows, though it does not hide many of the major differences. |
| 787 |
/// |
| 788 |
/// Paths are passed as interface-type `string`s, meaning they must consist of |
| 789 |
/// a sequence of Unicode Scalar Values (USVs). Some filesystems may contain |
| 790 |
/// paths which are not accessible by this API. |
| 791 |
/// |
| 792 |
/// The directory separator in WASI is always the forward-slash (`/`). |
| 793 |
/// |
| 794 |
/// All paths in WASI are relative paths, and are interpreted relative to a |
| 795 |
/// `descriptor` referring to a base directory. If a `path` argument to any WASI |
| 796 |
/// function starts with `/`, or if any step of resolving a `path`, including |
| 797 |
/// `..` and symbolic link steps, reaches a directory outside of the base |
| 798 |
/// directory, or reaches a symlink to an absolute or rooted path in the |
| 799 |
/// underlying filesystem, the function fails with `error-code::not-permitted`. |
| 800 |
/// |
| 801 |
/// For more information about WASI path resolution and sandboxing, see |
| 802 |
/// [WASI filesystem path resolution]. |
| 803 |
/// |
| 804 |
/// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md |
| 805 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 806 |
pub mod types { |
| 807 |
#[used] |
| 808 |
#[doc(hidden)] |
| 809 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 810 |
use super::super::super::_rt; |
| 811 |
pub type InputStream = super::super::super::wasi::io::streams::InputStream; |
| 812 |
pub type OutputStream = super::super::super::wasi::io::streams::OutputStream; |
| 813 |
pub type Error = super::super::super::wasi::io::streams::Error; |
| 814 |
pub type Datetime = super::super::super::wasi::clocks::wall_clock::Datetime; |
| 815 |
/// File size or length of a region within a file. |
| 816 |
pub type Filesize = u64; |
| 817 |
/// The type of a filesystem object referenced by a descriptor. |
| 818 |
/// |
| 819 |
/// Note: This was called `filetype` in earlier versions of WASI. |
| 820 |
#[repr(u8)] |
| 821 |
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)] |
| 822 |
pub enum DescriptorType { |
| 823 |
/// The type of the descriptor or file is unknown or is different from |
| 824 |
/// any of the other types specified. |
| 825 |
Unknown, |
| 826 |
/// The descriptor refers to a block device inode. |
| 827 |
BlockDevice, |
| 828 |
/// The descriptor refers to a character device inode. |
| 829 |
CharacterDevice, |
| 830 |
/// The descriptor refers to a directory inode. |
| 831 |
Directory, |
| 832 |
/// The descriptor refers to a named pipe. |
| 833 |
Fifo, |
| 834 |
/// The file refers to a symbolic link inode. |
| 835 |
SymbolicLink, |
| 836 |
/// The descriptor refers to a regular file inode. |
| 837 |
RegularFile, |
| 838 |
/// The descriptor refers to a socket. |
| 839 |
Socket, |
| 840 |
} |
| 841 |
impl ::core::fmt::Debug for DescriptorType { |
| 842 |
fn fmt( |
| 843 |
&self, |
| 844 |
f: &mut ::core::fmt::Formatter<'_>, |
| 845 |
) -> ::core::fmt::Result { |
| 846 |
match self { |
| 847 |
DescriptorType::Unknown => { |
| 848 |
f.debug_tuple("DescriptorType::Unknown").finish() |
| 849 |
} |
| 850 |
DescriptorType::BlockDevice => { |
| 851 |
f.debug_tuple("DescriptorType::BlockDevice").finish() |
| 852 |
} |
| 853 |
DescriptorType::CharacterDevice => { |
| 854 |
f.debug_tuple("DescriptorType::CharacterDevice").finish() |
| 855 |
} |
| 856 |
DescriptorType::Directory => { |
| 857 |
f.debug_tuple("DescriptorType::Directory").finish() |
| 858 |
} |
| 859 |
DescriptorType::Fifo => { |
| 860 |
f.debug_tuple("DescriptorType::Fifo").finish() |
| 861 |
} |
| 862 |
DescriptorType::SymbolicLink => { |
| 863 |
f.debug_tuple("DescriptorType::SymbolicLink").finish() |
| 864 |
} |
| 865 |
DescriptorType::RegularFile => { |
| 866 |
f.debug_tuple("DescriptorType::RegularFile").finish() |
| 867 |
} |
| 868 |
DescriptorType::Socket => { |
| 869 |
f.debug_tuple("DescriptorType::Socket").finish() |
| 870 |
} |
| 871 |
} |
| 872 |
} |
| 873 |
} |
| 874 |
impl DescriptorType { |
| 875 |
#[doc(hidden)] |
| 876 |
pub unsafe fn _lift(val: u8) -> DescriptorType { |
| 877 |
if !cfg!(debug_assertions) { |
| 878 |
return unsafe { ::core::mem::transmute(val) }; |
| 879 |
} |
| 880 |
match val { |
| 881 |
0 => DescriptorType::Unknown, |
| 882 |
1 => DescriptorType::BlockDevice, |
| 883 |
2 => DescriptorType::CharacterDevice, |
| 884 |
3 => DescriptorType::Directory, |
| 885 |
4 => DescriptorType::Fifo, |
| 886 |
5 => DescriptorType::SymbolicLink, |
| 887 |
6 => DescriptorType::RegularFile, |
| 888 |
7 => DescriptorType::Socket, |
| 889 |
_ => panic!("invalid enum discriminant"), |
| 890 |
} |
| 891 |
} |
| 892 |
} |
| 893 |
wit_bindgen::rt::bitflags::bitflags! { |
| 894 |
#[doc = " Descriptor flags."] #[doc = ""] #[doc = |
| 895 |
" Note: This was called `fdflags` in earlier versions of WASI."] |
| 896 |
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)] pub |
| 897 |
struct DescriptorFlags : u8 { #[doc = " Read mode: Data can be read."] |
| 898 |
const READ = 1 << 0; #[doc = " Write mode: Data can be written to."] |
| 899 |
const WRITE = 1 << 1; #[doc = |
| 900 |
" Request that writes be performed according to synchronized I/O file"] |
| 901 |
#[doc = |
| 902 |
" integrity completion. The data stored in the file and the file's"] |
| 903 |
#[doc = |
| 904 |
" metadata are synchronized. This is similar to `O_SYNC` in POSIX."] |
| 905 |
#[doc = ""] #[doc = |
| 906 |
" The precise semantics of this operation have not yet been defined for"] |
| 907 |
#[doc = |
| 908 |
" WASI. At this time, it should be interpreted as a request, and not a"] |
| 909 |
#[doc = " requirement."] const FILE_INTEGRITY_SYNC = 1 << 2; #[doc = |
| 910 |
" Request that writes be performed according to synchronized I/O data"] |
| 911 |
#[doc = " integrity completion. Only the data stored in the file is"] |
| 912 |
#[doc = " synchronized. This is similar to `O_DSYNC` in POSIX."] #[doc = |
| 913 |
""] #[doc = |
| 914 |
" The precise semantics of this operation have not yet been defined for"] |
| 915 |
#[doc = |
| 916 |
" WASI. At this time, it should be interpreted as a request, and not a"] |
| 917 |
#[doc = " requirement."] const DATA_INTEGRITY_SYNC = 1 << 3; #[doc = |
| 918 |
" Requests that reads be performed at the same level of integrity"] #[doc |
| 919 |
= " requested for writes. This is similar to `O_RSYNC` in POSIX."] #[doc |
| 920 |
= ""] #[doc = |
| 921 |
" The precise semantics of this operation have not yet been defined for"] |
| 922 |
#[doc = |
| 923 |
" WASI. At this time, it should be interpreted as a request, and not a"] |
| 924 |
#[doc = " requirement."] const REQUESTED_WRITE_SYNC = 1 << 4; #[doc = |
| 925 |
" Mutating directories mode: Directory contents may be mutated."] #[doc = |
| 926 |
""] #[doc = |
| 927 |
" When this flag is unset on a descriptor, operations using the"] #[doc = |
| 928 |
" descriptor which would create, rename, delete, modify the data or"] |
| 929 |
#[doc = |
| 930 |
" metadata of filesystem objects, or obtain another handle which"] #[doc |
| 931 |
= |
| 932 |
" would permit any of those, shall fail with `error-code::read-only` if"] |
| 933 |
#[doc = " they would otherwise succeed."] #[doc = ""] #[doc = |
| 934 |
" This may only be set on directories."] const MUTATE_DIRECTORY = 1 << 5; |
| 935 |
} |
| 936 |
} |
| 937 |
wit_bindgen::rt::bitflags::bitflags! { |
| 938 |
#[doc = " Flags determining the method of how paths are resolved."] |
| 939 |
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)] pub |
| 940 |
struct PathFlags : u8 { #[doc = |
| 941 |
" As long as the resolved path corresponds to a symbolic link, it is"] |
| 942 |
#[doc = " expanded."] const SYMLINK_FOLLOW = 1 << 0; } |
| 943 |
} |
| 944 |
wit_bindgen::rt::bitflags::bitflags! { |
| 945 |
#[doc = " Open flags used by `open-at`."] #[derive(PartialEq, Eq, |
| 946 |
PartialOrd, Ord, Hash, Debug, Clone, Copy)] pub struct OpenFlags : u8 { |
| 947 |
#[doc = |
| 948 |
" Create file if it does not exist, similar to `O_CREAT` in POSIX."] |
| 949 |
const CREATE = 1 << 0; #[doc = |
| 950 |
" Fail if not a directory, similar to `O_DIRECTORY` in POSIX."] const |
| 951 |
DIRECTORY = 1 << 1; #[doc = |
| 952 |
" Fail if file already exists, similar to `O_EXCL` in POSIX."] const |
| 953 |
EXCLUSIVE = 1 << 2; #[doc = |
| 954 |
" Truncate file to size 0, similar to `O_TRUNC` in POSIX."] const |
| 955 |
TRUNCATE = 1 << 3; } |
| 956 |
} |
| 957 |
/// Number of hard links to an inode. |
| 958 |
pub type LinkCount = u64; |
| 959 |
/// File attributes. |
| 960 |
/// |
| 961 |
/// Note: This was called `filestat` in earlier versions of WASI. |
| 962 |
#[repr(C)] |
| 963 |
#[derive(Clone, Copy)] |
| 964 |
pub struct DescriptorStat { |
| 965 |
/// File type. |
| 966 |
pub type_: DescriptorType, |
| 967 |
/// Number of hard links to the file. |
| 968 |
pub link_count: LinkCount, |
| 969 |
/// For regular files, the file size in bytes. For symbolic links, the |
| 970 |
/// length in bytes of the pathname contained in the symbolic link. |
| 971 |
pub size: Filesize, |
| 972 |
/// Last data access timestamp. |
| 973 |
/// |
| 974 |
/// If the `option` is none, the platform doesn't maintain an access |
| 975 |
/// timestamp for this file. |
| 976 |
pub data_access_timestamp: Option<Datetime>, |
| 977 |
/// Last data modification timestamp. |
| 978 |
/// |
| 979 |
/// If the `option` is none, the platform doesn't maintain a |
| 980 |
/// modification timestamp for this file. |
| 981 |
pub data_modification_timestamp: Option<Datetime>, |
| 982 |
/// Last file status-change timestamp. |
| 983 |
/// |
| 984 |
/// If the `option` is none, the platform doesn't maintain a |
| 985 |
/// status-change timestamp for this file. |
| 986 |
pub status_change_timestamp: Option<Datetime>, |
| 987 |
} |
| 988 |
impl ::core::fmt::Debug for DescriptorStat { |
| 989 |
fn fmt( |
| 990 |
&self, |
| 991 |
f: &mut ::core::fmt::Formatter<'_>, |
| 992 |
) -> ::core::fmt::Result { |
| 993 |
f.debug_struct("DescriptorStat") |
| 994 |
.field("type", &self.type_) |
| 995 |
.field("link-count", &self.link_count) |
| 996 |
.field("size", &self.size) |
| 997 |
.field("data-access-timestamp", &self.data_access_timestamp) |
| 998 |
.field( |
| 999 |
"data-modification-timestamp", |
| 1000 |
&self.data_modification_timestamp, |
| 1001 |
) |
| 1002 |
.field("status-change-timestamp", &self.status_change_timestamp) |
| 1003 |
.finish() |
| 1004 |
} |
| 1005 |
} |
| 1006 |
/// When setting a timestamp, this gives the value to set it to. |
| 1007 |
#[derive(Clone, Copy)] |
| 1008 |
pub enum NewTimestamp { |
| 1009 |
/// Leave the timestamp set to its previous value. |
| 1010 |
NoChange, |
| 1011 |
/// Set the timestamp to the current time of the system clock associated |
| 1012 |
/// with the filesystem. |
| 1013 |
Now, |
| 1014 |
/// Set the timestamp to the given value. |
| 1015 |
Timestamp(Datetime), |
| 1016 |
} |
| 1017 |
impl ::core::fmt::Debug for NewTimestamp { |
| 1018 |
fn fmt( |
| 1019 |
&self, |
| 1020 |
f: &mut ::core::fmt::Formatter<'_>, |
| 1021 |
) -> ::core::fmt::Result { |
| 1022 |
match self { |
| 1023 |
NewTimestamp::NoChange => { |
| 1024 |
f.debug_tuple("NewTimestamp::NoChange").finish() |
| 1025 |
} |
| 1026 |
NewTimestamp::Now => f.debug_tuple("NewTimestamp::Now").finish(), |
| 1027 |
NewTimestamp::Timestamp(e) => { |
| 1028 |
f.debug_tuple("NewTimestamp::Timestamp").field(e).finish() |
| 1029 |
} |
| 1030 |
} |
| 1031 |
} |
| 1032 |
} |
| 1033 |
/// A directory entry. |
| 1034 |
#[derive(Clone)] |
| 1035 |
pub struct DirectoryEntry { |
| 1036 |
/// The type of the file referred to by this directory entry. |
| 1037 |
pub type_: DescriptorType, |
| 1038 |
/// The name of the object. |
| 1039 |
pub name: _rt::String, |
| 1040 |
} |
| 1041 |
impl ::core::fmt::Debug for DirectoryEntry { |
| 1042 |
fn fmt( |
| 1043 |
&self, |
| 1044 |
f: &mut ::core::fmt::Formatter<'_>, |
| 1045 |
) -> ::core::fmt::Result { |
| 1046 |
f.debug_struct("DirectoryEntry") |
| 1047 |
.field("type", &self.type_) |
| 1048 |
.field("name", &self.name) |
| 1049 |
.finish() |
| 1050 |
} |
| 1051 |
} |
| 1052 |
/// Error codes returned by functions, similar to `errno` in POSIX. |
| 1053 |
/// Not all of these error codes are returned by the functions provided by this |
| 1054 |
/// API; some are used in higher-level library layers, and others are provided |
| 1055 |
/// merely for alignment with POSIX. |
| 1056 |
#[repr(u8)] |
| 1057 |
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)] |
| 1058 |
pub enum ErrorCode { |
| 1059 |
/// Permission denied, similar to `EACCES` in POSIX. |
| 1060 |
Access, |
| 1061 |
/// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX. |
| 1062 |
WouldBlock, |
| 1063 |
/// Connection already in progress, similar to `EALREADY` in POSIX. |
| 1064 |
Already, |
| 1065 |
/// Bad descriptor, similar to `EBADF` in POSIX. |
| 1066 |
BadDescriptor, |
| 1067 |
/// Device or resource busy, similar to `EBUSY` in POSIX. |
| 1068 |
Busy, |
| 1069 |
/// Resource deadlock would occur, similar to `EDEADLK` in POSIX. |
| 1070 |
Deadlock, |
| 1071 |
/// Storage quota exceeded, similar to `EDQUOT` in POSIX. |
| 1072 |
Quota, |
| 1073 |
/// File exists, similar to `EEXIST` in POSIX. |
| 1074 |
Exist, |
| 1075 |
/// File too large, similar to `EFBIG` in POSIX. |
| 1076 |
FileTooLarge, |
| 1077 |
/// Illegal byte sequence, similar to `EILSEQ` in POSIX. |
| 1078 |
IllegalByteSequence, |
| 1079 |
/// Operation in progress, similar to `EINPROGRESS` in POSIX. |
| 1080 |
InProgress, |
| 1081 |
/// Interrupted function, similar to `EINTR` in POSIX. |
| 1082 |
Interrupted, |
| 1083 |
/// Invalid argument, similar to `EINVAL` in POSIX. |
| 1084 |
Invalid, |
| 1085 |
/// I/O error, similar to `EIO` in POSIX. |
| 1086 |
Io, |
| 1087 |
/// Is a directory, similar to `EISDIR` in POSIX. |
| 1088 |
IsDirectory, |
| 1089 |
/// Too many levels of symbolic links, similar to `ELOOP` in POSIX. |
| 1090 |
Loop, |
| 1091 |
/// Too many links, similar to `EMLINK` in POSIX. |
| 1092 |
TooManyLinks, |
| 1093 |
/// Message too large, similar to `EMSGSIZE` in POSIX. |
| 1094 |
MessageSize, |
| 1095 |
/// Filename too long, similar to `ENAMETOOLONG` in POSIX. |
| 1096 |
NameTooLong, |
| 1097 |
/// No such device, similar to `ENODEV` in POSIX. |
| 1098 |
NoDevice, |
| 1099 |
/// No such file or directory, similar to `ENOENT` in POSIX. |
| 1100 |
NoEntry, |
| 1101 |
/// No locks available, similar to `ENOLCK` in POSIX. |
| 1102 |
NoLock, |
| 1103 |
/// Not enough space, similar to `ENOMEM` in POSIX. |
| 1104 |
InsufficientMemory, |
| 1105 |
/// No space left on device, similar to `ENOSPC` in POSIX. |
| 1106 |
InsufficientSpace, |
| 1107 |
/// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. |
| 1108 |
NotDirectory, |
| 1109 |
/// Directory not empty, similar to `ENOTEMPTY` in POSIX. |
| 1110 |
NotEmpty, |
| 1111 |
/// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. |
| 1112 |
NotRecoverable, |
| 1113 |
/// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. |
| 1114 |
Unsupported, |
| 1115 |
/// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. |
| 1116 |
NoTty, |
| 1117 |
/// No such device or address, similar to `ENXIO` in POSIX. |
| 1118 |
NoSuchDevice, |
| 1119 |
/// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. |
| 1120 |
Overflow, |
| 1121 |
/// Operation not permitted, similar to `EPERM` in POSIX. |
| 1122 |
NotPermitted, |
| 1123 |
/// Broken pipe, similar to `EPIPE` in POSIX. |
| 1124 |
Pipe, |
| 1125 |
/// Read-only file system, similar to `EROFS` in POSIX. |
| 1126 |
ReadOnly, |
| 1127 |
/// Invalid seek, similar to `ESPIPE` in POSIX. |
| 1128 |
InvalidSeek, |
| 1129 |
/// Text file busy, similar to `ETXTBSY` in POSIX. |
| 1130 |
TextFileBusy, |
| 1131 |
/// Cross-device link, similar to `EXDEV` in POSIX. |
| 1132 |
CrossDevice, |
| 1133 |
} |
| 1134 |
impl ErrorCode { |
| 1135 |
pub fn name(&self) -> &'static str { |
| 1136 |
match self { |
| 1137 |
ErrorCode::Access => "access", |
| 1138 |
ErrorCode::WouldBlock => "would-block", |
| 1139 |
ErrorCode::Already => "already", |
| 1140 |
ErrorCode::BadDescriptor => "bad-descriptor", |
| 1141 |
ErrorCode::Busy => "busy", |
| 1142 |
ErrorCode::Deadlock => "deadlock", |
| 1143 |
ErrorCode::Quota => "quota", |
| 1144 |
ErrorCode::Exist => "exist", |
| 1145 |
ErrorCode::FileTooLarge => "file-too-large", |
| 1146 |
ErrorCode::IllegalByteSequence => "illegal-byte-sequence", |
| 1147 |
ErrorCode::InProgress => "in-progress", |
| 1148 |
ErrorCode::Interrupted => "interrupted", |
| 1149 |
ErrorCode::Invalid => "invalid", |
| 1150 |
ErrorCode::Io => "io", |
| 1151 |
ErrorCode::IsDirectory => "is-directory", |
| 1152 |
ErrorCode::Loop => "loop", |
| 1153 |
ErrorCode::TooManyLinks => "too-many-links", |
| 1154 |
ErrorCode::MessageSize => "message-size", |
| 1155 |
ErrorCode::NameTooLong => "name-too-long", |
| 1156 |
ErrorCode::NoDevice => "no-device", |
| 1157 |
ErrorCode::NoEntry => "no-entry", |
| 1158 |
ErrorCode::NoLock => "no-lock", |
| 1159 |
ErrorCode::InsufficientMemory => "insufficient-memory", |
| 1160 |
ErrorCode::InsufficientSpace => "insufficient-space", |
| 1161 |
ErrorCode::NotDirectory => "not-directory", |
| 1162 |
ErrorCode::NotEmpty => "not-empty", |
| 1163 |
ErrorCode::NotRecoverable => "not-recoverable", |
| 1164 |
ErrorCode::Unsupported => "unsupported", |
| 1165 |
ErrorCode::NoTty => "no-tty", |
| 1166 |
ErrorCode::NoSuchDevice => "no-such-device", |
| 1167 |
ErrorCode::Overflow => "overflow", |
| 1168 |
ErrorCode::NotPermitted => "not-permitted", |
| 1169 |
ErrorCode::Pipe => "pipe", |
| 1170 |
ErrorCode::ReadOnly => "read-only", |
| 1171 |
ErrorCode::InvalidSeek => "invalid-seek", |
| 1172 |
ErrorCode::TextFileBusy => "text-file-busy", |
| 1173 |
ErrorCode::CrossDevice => "cross-device", |
| 1174 |
} |
| 1175 |
} |
| 1176 |
pub fn message(&self) -> &'static str { |
| 1177 |
match self { |
| 1178 |
ErrorCode::Access => { |
| 1179 |
"Permission denied, similar to `EACCES` in POSIX." |
| 1180 |
} |
| 1181 |
ErrorCode::WouldBlock => { |
| 1182 |
"Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX." |
| 1183 |
} |
| 1184 |
ErrorCode::Already => { |
| 1185 |
"Connection already in progress, similar to `EALREADY` in POSIX." |
| 1186 |
} |
| 1187 |
ErrorCode::BadDescriptor => { |
| 1188 |
"Bad descriptor, similar to `EBADF` in POSIX." |
| 1189 |
} |
| 1190 |
ErrorCode::Busy => { |
| 1191 |
"Device or resource busy, similar to `EBUSY` in POSIX." |
| 1192 |
} |
| 1193 |
ErrorCode::Deadlock => { |
| 1194 |
"Resource deadlock would occur, similar to `EDEADLK` in POSIX." |
| 1195 |
} |
| 1196 |
ErrorCode::Quota => { |
| 1197 |
"Storage quota exceeded, similar to `EDQUOT` in POSIX." |
| 1198 |
} |
| 1199 |
ErrorCode::Exist => "File exists, similar to `EEXIST` in POSIX.", |
| 1200 |
ErrorCode::FileTooLarge => { |
| 1201 |
"File too large, similar to `EFBIG` in POSIX." |
| 1202 |
} |
| 1203 |
ErrorCode::IllegalByteSequence => { |
| 1204 |
"Illegal byte sequence, similar to `EILSEQ` in POSIX." |
| 1205 |
} |
| 1206 |
ErrorCode::InProgress => { |
| 1207 |
"Operation in progress, similar to `EINPROGRESS` in POSIX." |
| 1208 |
} |
| 1209 |
ErrorCode::Interrupted => { |
| 1210 |
"Interrupted function, similar to `EINTR` in POSIX." |
| 1211 |
} |
| 1212 |
ErrorCode::Invalid => { |
| 1213 |
"Invalid argument, similar to `EINVAL` in POSIX." |
| 1214 |
} |
| 1215 |
ErrorCode::Io => "I/O error, similar to `EIO` in POSIX.", |
| 1216 |
ErrorCode::IsDirectory => { |
| 1217 |
"Is a directory, similar to `EISDIR` in POSIX." |
| 1218 |
} |
| 1219 |
ErrorCode::Loop => { |
| 1220 |
"Too many levels of symbolic links, similar to `ELOOP` in POSIX." |
| 1221 |
} |
| 1222 |
ErrorCode::TooManyLinks => { |
| 1223 |
"Too many links, similar to `EMLINK` in POSIX." |
| 1224 |
} |
| 1225 |
ErrorCode::MessageSize => { |
| 1226 |
"Message too large, similar to `EMSGSIZE` in POSIX." |
| 1227 |
} |
| 1228 |
ErrorCode::NameTooLong => { |
| 1229 |
"Filename too long, similar to `ENAMETOOLONG` in POSIX." |
| 1230 |
} |
| 1231 |
ErrorCode::NoDevice => { |
| 1232 |
"No such device, similar to `ENODEV` in POSIX." |
| 1233 |
} |
| 1234 |
ErrorCode::NoEntry => { |
| 1235 |
"No such file or directory, similar to `ENOENT` in POSIX." |
| 1236 |
} |
| 1237 |
ErrorCode::NoLock => { |
| 1238 |
"No locks available, similar to `ENOLCK` in POSIX." |
| 1239 |
} |
| 1240 |
ErrorCode::InsufficientMemory => { |
| 1241 |
"Not enough space, similar to `ENOMEM` in POSIX." |
| 1242 |
} |
| 1243 |
ErrorCode::InsufficientSpace => { |
| 1244 |
"No space left on device, similar to `ENOSPC` in POSIX." |
| 1245 |
} |
| 1246 |
ErrorCode::NotDirectory => { |
| 1247 |
"Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX." |
| 1248 |
} |
| 1249 |
ErrorCode::NotEmpty => { |
| 1250 |
"Directory not empty, similar to `ENOTEMPTY` in POSIX." |
| 1251 |
} |
| 1252 |
ErrorCode::NotRecoverable => { |
| 1253 |
"State not recoverable, similar to `ENOTRECOVERABLE` in POSIX." |
| 1254 |
} |
| 1255 |
ErrorCode::Unsupported => { |
| 1256 |
"Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX." |
| 1257 |
} |
| 1258 |
ErrorCode::NoTty => { |
| 1259 |
"Inappropriate I/O control operation, similar to `ENOTTY` in POSIX." |
| 1260 |
} |
| 1261 |
ErrorCode::NoSuchDevice => { |
| 1262 |
"No such device or address, similar to `ENXIO` in POSIX." |
| 1263 |
} |
| 1264 |
ErrorCode::Overflow => { |
| 1265 |
"Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX." |
| 1266 |
} |
| 1267 |
ErrorCode::NotPermitted => { |
| 1268 |
"Operation not permitted, similar to `EPERM` in POSIX." |
| 1269 |
} |
| 1270 |
ErrorCode::Pipe => "Broken pipe, similar to `EPIPE` in POSIX.", |
| 1271 |
ErrorCode::ReadOnly => { |
| 1272 |
"Read-only file system, similar to `EROFS` in POSIX." |
| 1273 |
} |
| 1274 |
ErrorCode::InvalidSeek => { |
| 1275 |
"Invalid seek, similar to `ESPIPE` in POSIX." |
| 1276 |
} |
| 1277 |
ErrorCode::TextFileBusy => { |
| 1278 |
"Text file busy, similar to `ETXTBSY` in POSIX." |
| 1279 |
} |
| 1280 |
ErrorCode::CrossDevice => { |
| 1281 |
"Cross-device link, similar to `EXDEV` in POSIX." |
| 1282 |
} |
| 1283 |
} |
| 1284 |
} |
| 1285 |
} |
| 1286 |
impl ::core::fmt::Debug for ErrorCode { |
| 1287 |
fn fmt( |
| 1288 |
&self, |
| 1289 |
f: &mut ::core::fmt::Formatter<'_>, |
| 1290 |
) -> ::core::fmt::Result { |
| 1291 |
f.debug_struct("ErrorCode") |
| 1292 |
.field("code", &(*self as i32)) |
| 1293 |
.field("name", &self.name()) |
| 1294 |
.field("message", &self.message()) |
| 1295 |
.finish() |
| 1296 |
} |
| 1297 |
} |
| 1298 |
impl ::core::fmt::Display for ErrorCode { |
| 1299 |
fn fmt( |
| 1300 |
&self, |
| 1301 |
f: &mut ::core::fmt::Formatter<'_>, |
| 1302 |
) -> ::core::fmt::Result { |
| 1303 |
write!(f, "{} (error {})", self.name(), * self as i32) |
| 1304 |
} |
| 1305 |
} |
| 1306 |
#[cfg(feature = "std")] |
| 1307 |
impl std::error::Error for ErrorCode {} |
| 1308 |
impl ErrorCode { |
| 1309 |
#[doc(hidden)] |
| 1310 |
pub unsafe fn _lift(val: u8) -> ErrorCode { |
| 1311 |
if !cfg!(debug_assertions) { |
| 1312 |
return unsafe { ::core::mem::transmute(val) }; |
| 1313 |
} |
| 1314 |
match val { |
| 1315 |
0 => ErrorCode::Access, |
| 1316 |
1 => ErrorCode::WouldBlock, |
| 1317 |
2 => ErrorCode::Already, |
| 1318 |
3 => ErrorCode::BadDescriptor, |
| 1319 |
4 => ErrorCode::Busy, |
| 1320 |
5 => ErrorCode::Deadlock, |
| 1321 |
6 => ErrorCode::Quota, |
| 1322 |
7 => ErrorCode::Exist, |
| 1323 |
8 => ErrorCode::FileTooLarge, |
| 1324 |
9 => ErrorCode::IllegalByteSequence, |
| 1325 |
10 => ErrorCode::InProgress, |
| 1326 |
11 => ErrorCode::Interrupted, |
| 1327 |
12 => ErrorCode::Invalid, |
| 1328 |
13 => ErrorCode::Io, |
| 1329 |
14 => ErrorCode::IsDirectory, |
| 1330 |
15 => ErrorCode::Loop, |
| 1331 |
16 => ErrorCode::TooManyLinks, |
| 1332 |
17 => ErrorCode::MessageSize, |
| 1333 |
18 => ErrorCode::NameTooLong, |
| 1334 |
19 => ErrorCode::NoDevice, |
| 1335 |
20 => ErrorCode::NoEntry, |
| 1336 |
21 => ErrorCode::NoLock, |
| 1337 |
22 => ErrorCode::InsufficientMemory, |
| 1338 |
23 => ErrorCode::InsufficientSpace, |
| 1339 |
24 => ErrorCode::NotDirectory, |
| 1340 |
25 => ErrorCode::NotEmpty, |
| 1341 |
26 => ErrorCode::NotRecoverable, |
| 1342 |
27 => ErrorCode::Unsupported, |
| 1343 |
28 => ErrorCode::NoTty, |
| 1344 |
29 => ErrorCode::NoSuchDevice, |
| 1345 |
30 => ErrorCode::Overflow, |
| 1346 |
31 => ErrorCode::NotPermitted, |
| 1347 |
32 => ErrorCode::Pipe, |
| 1348 |
33 => ErrorCode::ReadOnly, |
| 1349 |
34 => ErrorCode::InvalidSeek, |
| 1350 |
35 => ErrorCode::TextFileBusy, |
| 1351 |
36 => ErrorCode::CrossDevice, |
| 1352 |
_ => panic!("invalid enum discriminant"), |
| 1353 |
} |
| 1354 |
} |
| 1355 |
} |
| 1356 |
/// File or memory access pattern advisory information. |
| 1357 |
#[repr(u8)] |
| 1358 |
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)] |
| 1359 |
pub enum Advice { |
| 1360 |
/// The application has no advice to give on its behavior with respect |
| 1361 |
/// to the specified data. |
| 1362 |
Normal, |
| 1363 |
/// The application expects to access the specified data sequentially |
| 1364 |
/// from lower offsets to higher offsets. |
| 1365 |
Sequential, |
| 1366 |
/// The application expects to access the specified data in a random |
| 1367 |
/// order. |
| 1368 |
Random, |
| 1369 |
/// The application expects to access the specified data in the near |
| 1370 |
/// future. |
| 1371 |
WillNeed, |
| 1372 |
/// The application expects that it will not access the specified data |
| 1373 |
/// in the near future. |
| 1374 |
DontNeed, |
| 1375 |
/// The application expects to access the specified data once and then |
| 1376 |
/// not reuse it thereafter. |
| 1377 |
NoReuse, |
| 1378 |
} |
| 1379 |
impl ::core::fmt::Debug for Advice { |
| 1380 |
fn fmt( |
| 1381 |
&self, |
| 1382 |
f: &mut ::core::fmt::Formatter<'_>, |
| 1383 |
) -> ::core::fmt::Result { |
| 1384 |
match self { |
| 1385 |
Advice::Normal => f.debug_tuple("Advice::Normal").finish(), |
| 1386 |
Advice::Sequential => { |
| 1387 |
f.debug_tuple("Advice::Sequential").finish() |
| 1388 |
} |
| 1389 |
Advice::Random => f.debug_tuple("Advice::Random").finish(), |
| 1390 |
Advice::WillNeed => f.debug_tuple("Advice::WillNeed").finish(), |
| 1391 |
Advice::DontNeed => f.debug_tuple("Advice::DontNeed").finish(), |
| 1392 |
Advice::NoReuse => f.debug_tuple("Advice::NoReuse").finish(), |
| 1393 |
} |
| 1394 |
} |
| 1395 |
} |
| 1396 |
impl Advice { |
| 1397 |
#[doc(hidden)] |
| 1398 |
pub unsafe fn _lift(val: u8) -> Advice { |
| 1399 |
if !cfg!(debug_assertions) { |
| 1400 |
return unsafe { ::core::mem::transmute(val) }; |
| 1401 |
} |
| 1402 |
match val { |
| 1403 |
0 => Advice::Normal, |
| 1404 |
1 => Advice::Sequential, |
| 1405 |
2 => Advice::Random, |
| 1406 |
3 => Advice::WillNeed, |
| 1407 |
4 => Advice::DontNeed, |
| 1408 |
5 => Advice::NoReuse, |
| 1409 |
_ => panic!("invalid enum discriminant"), |
| 1410 |
} |
| 1411 |
} |
| 1412 |
} |
| 1413 |
/// A 128-bit hash value, split into parts because wasm doesn't have a |
| 1414 |
/// 128-bit integer type. |
| 1415 |
#[repr(C)] |
| 1416 |
#[derive(Clone, Copy)] |
| 1417 |
pub struct MetadataHashValue { |
| 1418 |
/// 64 bits of a 128-bit hash value. |
| 1419 |
pub lower: u64, |
| 1420 |
/// Another 64 bits of a 128-bit hash value. |
| 1421 |
pub upper: u64, |
| 1422 |
} |
| 1423 |
impl ::core::fmt::Debug for MetadataHashValue { |
| 1424 |
fn fmt( |
| 1425 |
&self, |
| 1426 |
f: &mut ::core::fmt::Formatter<'_>, |
| 1427 |
) -> ::core::fmt::Result { |
| 1428 |
f.debug_struct("MetadataHashValue") |
| 1429 |
.field("lower", &self.lower) |
| 1430 |
.field("upper", &self.upper) |
| 1431 |
.finish() |
| 1432 |
} |
| 1433 |
} |
| 1434 |
/// A descriptor is a reference to a filesystem object, which may be a file, |
| 1435 |
/// directory, named pipe, special file, or other object on which filesystem |
| 1436 |
/// calls may be made. |
| 1437 |
#[derive(Debug)] |
| 1438 |
#[repr(transparent)] |
| 1439 |
pub struct Descriptor { |
| 1440 |
handle: _rt::Resource<Descriptor>, |
| 1441 |
} |
| 1442 |
impl Descriptor { |
| 1443 |
#[doc(hidden)] |
| 1444 |
pub unsafe fn from_handle(handle: u32) -> Self { |
| 1445 |
Self { |
| 1446 |
handle: unsafe { _rt::Resource::from_handle(handle) }, |
| 1447 |
} |
| 1448 |
} |
| 1449 |
#[doc(hidden)] |
| 1450 |
pub fn take_handle(&self) -> u32 { |
| 1451 |
_rt::Resource::take_handle(&self.handle) |
| 1452 |
} |
| 1453 |
#[doc(hidden)] |
| 1454 |
pub fn handle(&self) -> u32 { |
| 1455 |
_rt::Resource::handle(&self.handle) |
| 1456 |
} |
| 1457 |
} |
| 1458 |
unsafe impl _rt::WasmResource for Descriptor { |
| 1459 |
#[inline] |
| 1460 |
unsafe fn drop(_handle: u32) { |
| 1461 |
#[cfg(target_arch = "wasm32")] |
| 1462 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 1463 |
unsafe extern "C" { |
| 1464 |
#[link_name = "[resource-drop]descriptor"] |
| 1465 |
fn drop(_: i32); |
| 1466 |
} |
| 1467 |
#[cfg(not(target_arch = "wasm32"))] |
| 1468 |
unsafe extern "C" fn drop(_: i32) { |
| 1469 |
unreachable!() |
| 1470 |
} |
| 1471 |
unsafe { |
| 1472 |
drop(_handle as i32); |
| 1473 |
} |
| 1474 |
} |
| 1475 |
} |
| 1476 |
/// A stream of directory entries. |
| 1477 |
#[derive(Debug)] |
| 1478 |
#[repr(transparent)] |
| 1479 |
pub struct DirectoryEntryStream { |
| 1480 |
handle: _rt::Resource<DirectoryEntryStream>, |
| 1481 |
} |
| 1482 |
impl DirectoryEntryStream { |
| 1483 |
#[doc(hidden)] |
| 1484 |
pub unsafe fn from_handle(handle: u32) -> Self { |
| 1485 |
Self { |
| 1486 |
handle: unsafe { _rt::Resource::from_handle(handle) }, |
| 1487 |
} |
| 1488 |
} |
| 1489 |
#[doc(hidden)] |
| 1490 |
pub fn take_handle(&self) -> u32 { |
| 1491 |
_rt::Resource::take_handle(&self.handle) |
| 1492 |
} |
| 1493 |
#[doc(hidden)] |
| 1494 |
pub fn handle(&self) -> u32 { |
| 1495 |
_rt::Resource::handle(&self.handle) |
| 1496 |
} |
| 1497 |
} |
| 1498 |
unsafe impl _rt::WasmResource for DirectoryEntryStream { |
| 1499 |
#[inline] |
| 1500 |
unsafe fn drop(_handle: u32) { |
| 1501 |
#[cfg(target_arch = "wasm32")] |
| 1502 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 1503 |
unsafe extern "C" { |
| 1504 |
#[link_name = "[resource-drop]directory-entry-stream"] |
| 1505 |
fn drop(_: i32); |
| 1506 |
} |
| 1507 |
#[cfg(not(target_arch = "wasm32"))] |
| 1508 |
unsafe extern "C" fn drop(_: i32) { |
| 1509 |
unreachable!() |
| 1510 |
} |
| 1511 |
unsafe { |
| 1512 |
drop(_handle as i32); |
| 1513 |
} |
| 1514 |
} |
| 1515 |
} |
| 1516 |
impl Descriptor { |
| 1517 |
#[allow(unused_unsafe, clippy::all)] |
| 1518 |
/// Return a stream for reading from a file, if available. |
| 1519 |
/// |
| 1520 |
/// May fail with an error-code describing why the file cannot be read. |
| 1521 |
/// |
| 1522 |
/// Multiple read, write, and append streams may be active on the same open |
| 1523 |
/// file and they do not interfere with each other. |
| 1524 |
/// |
| 1525 |
/// Note: This allows using `read-stream`, which is similar to `read` in POSIX. |
| 1526 |
#[allow(async_fn_in_trait)] |
| 1527 |
pub fn read_via_stream( |
| 1528 |
&self, |
| 1529 |
offset: Filesize, |
| 1530 |
) -> Result<InputStream, ErrorCode> { |
| 1531 |
unsafe { |
| 1532 |
#[repr(align(4))] |
| 1533 |
struct RetArea([::core::mem::MaybeUninit<u8>; 8]); |
| 1534 |
let mut ret_area = RetArea( |
| 1535 |
[::core::mem::MaybeUninit::uninit(); 8], |
| 1536 |
); |
| 1537 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 1538 |
#[cfg(target_arch = "wasm32")] |
| 1539 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 1540 |
unsafe extern "C" { |
| 1541 |
#[link_name = "[method]descriptor.read-via-stream"] |
| 1542 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 1543 |
} |
| 1544 |
#[cfg(not(target_arch = "wasm32"))] |
| 1545 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 1546 |
unreachable!() |
| 1547 |
} |
| 1548 |
wit_import1((self).handle() as i32, _rt::as_i64(offset), ptr0); |
| 1549 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 1550 |
let result5 = match l2 { |
| 1551 |
0 => { |
| 1552 |
let e = { |
| 1553 |
let l3 = *ptr0.add(4).cast::<i32>(); |
| 1554 |
super::super::super::wasi::io::streams::InputStream::from_handle( |
| 1555 |
l3 as u32, |
| 1556 |
) |
| 1557 |
}; |
| 1558 |
Ok(e) |
| 1559 |
} |
| 1560 |
1 => { |
| 1561 |
let e = { |
| 1562 |
let l4 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 1563 |
ErrorCode::_lift(l4 as u8) |
| 1564 |
}; |
| 1565 |
Err(e) |
| 1566 |
} |
| 1567 |
_ => _rt::invalid_enum_discriminant(), |
| 1568 |
}; |
| 1569 |
result5 |
| 1570 |
} |
| 1571 |
} |
| 1572 |
} |
| 1573 |
impl Descriptor { |
| 1574 |
#[allow(unused_unsafe, clippy::all)] |
| 1575 |
/// Return a stream for writing to a file, if available. |
| 1576 |
/// |
| 1577 |
/// May fail with an error-code describing why the file cannot be written. |
| 1578 |
/// |
| 1579 |
/// Note: This allows using `write-stream`, which is similar to `write` in |
| 1580 |
/// POSIX. |
| 1581 |
#[allow(async_fn_in_trait)] |
| 1582 |
pub fn write_via_stream( |
| 1583 |
&self, |
| 1584 |
offset: Filesize, |
| 1585 |
) -> Result<OutputStream, ErrorCode> { |
| 1586 |
unsafe { |
| 1587 |
#[repr(align(4))] |
| 1588 |
struct RetArea([::core::mem::MaybeUninit<u8>; 8]); |
| 1589 |
let mut ret_area = RetArea( |
| 1590 |
[::core::mem::MaybeUninit::uninit(); 8], |
| 1591 |
); |
| 1592 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 1593 |
#[cfg(target_arch = "wasm32")] |
| 1594 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 1595 |
unsafe extern "C" { |
| 1596 |
#[link_name = "[method]descriptor.write-via-stream"] |
| 1597 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 1598 |
} |
| 1599 |
#[cfg(not(target_arch = "wasm32"))] |
| 1600 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 1601 |
unreachable!() |
| 1602 |
} |
| 1603 |
wit_import1((self).handle() as i32, _rt::as_i64(offset), ptr0); |
| 1604 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 1605 |
let result5 = match l2 { |
| 1606 |
0 => { |
| 1607 |
let e = { |
| 1608 |
let l3 = *ptr0.add(4).cast::<i32>(); |
| 1609 |
super::super::super::wasi::io::streams::OutputStream::from_handle( |
| 1610 |
l3 as u32, |
| 1611 |
) |
| 1612 |
}; |
| 1613 |
Ok(e) |
| 1614 |
} |
| 1615 |
1 => { |
| 1616 |
let e = { |
| 1617 |
let l4 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 1618 |
ErrorCode::_lift(l4 as u8) |
| 1619 |
}; |
| 1620 |
Err(e) |
| 1621 |
} |
| 1622 |
_ => _rt::invalid_enum_discriminant(), |
| 1623 |
}; |
| 1624 |
result5 |
| 1625 |
} |
| 1626 |
} |
| 1627 |
} |
| 1628 |
impl Descriptor { |
| 1629 |
#[allow(unused_unsafe, clippy::all)] |
| 1630 |
/// Return a stream for appending to a file, if available. |
| 1631 |
/// |
| 1632 |
/// May fail with an error-code describing why the file cannot be appended. |
| 1633 |
/// |
| 1634 |
/// Note: This allows using `write-stream`, which is similar to `write` with |
| 1635 |
/// `O_APPEND` in POSIX. |
| 1636 |
#[allow(async_fn_in_trait)] |
| 1637 |
pub fn append_via_stream(&self) -> Result<OutputStream, ErrorCode> { |
| 1638 |
unsafe { |
| 1639 |
#[repr(align(4))] |
| 1640 |
struct RetArea([::core::mem::MaybeUninit<u8>; 8]); |
| 1641 |
let mut ret_area = RetArea( |
| 1642 |
[::core::mem::MaybeUninit::uninit(); 8], |
| 1643 |
); |
| 1644 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 1645 |
#[cfg(target_arch = "wasm32")] |
| 1646 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 1647 |
unsafe extern "C" { |
| 1648 |
#[link_name = "[method]descriptor.append-via-stream"] |
| 1649 |
fn wit_import1(_: i32, _: *mut u8); |
| 1650 |
} |
| 1651 |
#[cfg(not(target_arch = "wasm32"))] |
| 1652 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 1653 |
unreachable!() |
| 1654 |
} |
| 1655 |
wit_import1((self).handle() as i32, ptr0); |
| 1656 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 1657 |
let result5 = match l2 { |
| 1658 |
0 => { |
| 1659 |
let e = { |
| 1660 |
let l3 = *ptr0.add(4).cast::<i32>(); |
| 1661 |
super::super::super::wasi::io::streams::OutputStream::from_handle( |
| 1662 |
l3 as u32, |
| 1663 |
) |
| 1664 |
}; |
| 1665 |
Ok(e) |
| 1666 |
} |
| 1667 |
1 => { |
| 1668 |
let e = { |
| 1669 |
let l4 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 1670 |
ErrorCode::_lift(l4 as u8) |
| 1671 |
}; |
| 1672 |
Err(e) |
| 1673 |
} |
| 1674 |
_ => _rt::invalid_enum_discriminant(), |
| 1675 |
}; |
| 1676 |
result5 |
| 1677 |
} |
| 1678 |
} |
| 1679 |
} |
| 1680 |
impl Descriptor { |
| 1681 |
#[allow(unused_unsafe, clippy::all)] |
| 1682 |
/// Provide file advisory information on a descriptor. |
| 1683 |
/// |
| 1684 |
/// This is similar to `posix_fadvise` in POSIX. |
| 1685 |
#[allow(async_fn_in_trait)] |
| 1686 |
pub fn advise( |
| 1687 |
&self, |
| 1688 |
offset: Filesize, |
| 1689 |
length: Filesize, |
| 1690 |
advice: Advice, |
| 1691 |
) -> Result<(), ErrorCode> { |
| 1692 |
unsafe { |
| 1693 |
#[repr(align(1))] |
| 1694 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 1695 |
let mut ret_area = RetArea( |
| 1696 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 1697 |
); |
| 1698 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 1699 |
#[cfg(target_arch = "wasm32")] |
| 1700 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 1701 |
unsafe extern "C" { |
| 1702 |
#[link_name = "[method]descriptor.advise"] |
| 1703 |
fn wit_import1(_: i32, _: i64, _: i64, _: i32, _: *mut u8); |
| 1704 |
} |
| 1705 |
#[cfg(not(target_arch = "wasm32"))] |
| 1706 |
unsafe extern "C" fn wit_import1( |
| 1707 |
_: i32, |
| 1708 |
_: i64, |
| 1709 |
_: i64, |
| 1710 |
_: i32, |
| 1711 |
_: *mut u8, |
| 1712 |
) { |
| 1713 |
unreachable!() |
| 1714 |
} |
| 1715 |
wit_import1( |
| 1716 |
(self).handle() as i32, |
| 1717 |
_rt::as_i64(offset), |
| 1718 |
_rt::as_i64(length), |
| 1719 |
advice.clone() as i32, |
| 1720 |
ptr0, |
| 1721 |
); |
| 1722 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 1723 |
let result4 = match l2 { |
| 1724 |
0 => { |
| 1725 |
let e = (); |
| 1726 |
Ok(e) |
| 1727 |
} |
| 1728 |
1 => { |
| 1729 |
let e = { |
| 1730 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 1731 |
ErrorCode::_lift(l3 as u8) |
| 1732 |
}; |
| 1733 |
Err(e) |
| 1734 |
} |
| 1735 |
_ => _rt::invalid_enum_discriminant(), |
| 1736 |
}; |
| 1737 |
result4 |
| 1738 |
} |
| 1739 |
} |
| 1740 |
} |
| 1741 |
impl Descriptor { |
| 1742 |
#[allow(unused_unsafe, clippy::all)] |
| 1743 |
/// Synchronize the data of a file to disk. |
| 1744 |
/// |
| 1745 |
/// This function succeeds with no effect if the file descriptor is not |
| 1746 |
/// opened for writing. |
| 1747 |
/// |
| 1748 |
/// Note: This is similar to `fdatasync` in POSIX. |
| 1749 |
#[allow(async_fn_in_trait)] |
| 1750 |
pub fn sync_data(&self) -> Result<(), ErrorCode> { |
| 1751 |
unsafe { |
| 1752 |
#[repr(align(1))] |
| 1753 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 1754 |
let mut ret_area = RetArea( |
| 1755 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 1756 |
); |
| 1757 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 1758 |
#[cfg(target_arch = "wasm32")] |
| 1759 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 1760 |
unsafe extern "C" { |
| 1761 |
#[link_name = "[method]descriptor.sync-data"] |
| 1762 |
fn wit_import1(_: i32, _: *mut u8); |
| 1763 |
} |
| 1764 |
#[cfg(not(target_arch = "wasm32"))] |
| 1765 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 1766 |
unreachable!() |
| 1767 |
} |
| 1768 |
wit_import1((self).handle() as i32, ptr0); |
| 1769 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 1770 |
let result4 = match l2 { |
| 1771 |
0 => { |
| 1772 |
let e = (); |
| 1773 |
Ok(e) |
| 1774 |
} |
| 1775 |
1 => { |
| 1776 |
let e = { |
| 1777 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 1778 |
ErrorCode::_lift(l3 as u8) |
| 1779 |
}; |
| 1780 |
Err(e) |
| 1781 |
} |
| 1782 |
_ => _rt::invalid_enum_discriminant(), |
| 1783 |
}; |
| 1784 |
result4 |
| 1785 |
} |
| 1786 |
} |
| 1787 |
} |
| 1788 |
impl Descriptor { |
| 1789 |
#[allow(unused_unsafe, clippy::all)] |
| 1790 |
/// Get flags associated with a descriptor. |
| 1791 |
/// |
| 1792 |
/// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. |
| 1793 |
/// |
| 1794 |
/// Note: This returns the value that was the `fs_flags` value returned |
| 1795 |
/// from `fdstat_get` in earlier versions of WASI. |
| 1796 |
#[allow(async_fn_in_trait)] |
| 1797 |
pub fn get_flags(&self) -> Result<DescriptorFlags, ErrorCode> { |
| 1798 |
unsafe { |
| 1799 |
#[repr(align(1))] |
| 1800 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 1801 |
let mut ret_area = RetArea( |
| 1802 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 1803 |
); |
| 1804 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 1805 |
#[cfg(target_arch = "wasm32")] |
| 1806 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 1807 |
unsafe extern "C" { |
| 1808 |
#[link_name = "[method]descriptor.get-flags"] |
| 1809 |
fn wit_import1(_: i32, _: *mut u8); |
| 1810 |
} |
| 1811 |
#[cfg(not(target_arch = "wasm32"))] |
| 1812 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 1813 |
unreachable!() |
| 1814 |
} |
| 1815 |
wit_import1((self).handle() as i32, ptr0); |
| 1816 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 1817 |
let result5 = match l2 { |
| 1818 |
0 => { |
| 1819 |
let e = { |
| 1820 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 1821 |
DescriptorFlags::empty() |
| 1822 |
| DescriptorFlags::from_bits_retain(((l3 as u8) << 0) as _) |
| 1823 |
}; |
| 1824 |
Ok(e) |
| 1825 |
} |
| 1826 |
1 => { |
| 1827 |
let e = { |
| 1828 |
let l4 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 1829 |
ErrorCode::_lift(l4 as u8) |
| 1830 |
}; |
| 1831 |
Err(e) |
| 1832 |
} |
| 1833 |
_ => _rt::invalid_enum_discriminant(), |
| 1834 |
}; |
| 1835 |
result5 |
| 1836 |
} |
| 1837 |
} |
| 1838 |
} |
| 1839 |
impl Descriptor { |
| 1840 |
#[allow(unused_unsafe, clippy::all)] |
| 1841 |
/// Get the dynamic type of a descriptor. |
| 1842 |
/// |
| 1843 |
/// Note: This returns the same value as the `type` field of the `fd-stat` |
| 1844 |
/// returned by `stat`, `stat-at` and similar. |
| 1845 |
/// |
| 1846 |
/// Note: This returns similar flags to the `st_mode & S_IFMT` value provided |
| 1847 |
/// by `fstat` in POSIX. |
| 1848 |
/// |
| 1849 |
/// Note: This returns the value that was the `fs_filetype` value returned |
| 1850 |
/// from `fdstat_get` in earlier versions of WASI. |
| 1851 |
#[allow(async_fn_in_trait)] |
| 1852 |
pub fn get_type(&self) -> Result<DescriptorType, ErrorCode> { |
| 1853 |
unsafe { |
| 1854 |
#[repr(align(1))] |
| 1855 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 1856 |
let mut ret_area = RetArea( |
| 1857 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 1858 |
); |
| 1859 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 1860 |
#[cfg(target_arch = "wasm32")] |
| 1861 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 1862 |
unsafe extern "C" { |
| 1863 |
#[link_name = "[method]descriptor.get-type"] |
| 1864 |
fn wit_import1(_: i32, _: *mut u8); |
| 1865 |
} |
| 1866 |
#[cfg(not(target_arch = "wasm32"))] |
| 1867 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 1868 |
unreachable!() |
| 1869 |
} |
| 1870 |
wit_import1((self).handle() as i32, ptr0); |
| 1871 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 1872 |
let result5 = match l2 { |
| 1873 |
0 => { |
| 1874 |
let e = { |
| 1875 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 1876 |
DescriptorType::_lift(l3 as u8) |
| 1877 |
}; |
| 1878 |
Ok(e) |
| 1879 |
} |
| 1880 |
1 => { |
| 1881 |
let e = { |
| 1882 |
let l4 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 1883 |
ErrorCode::_lift(l4 as u8) |
| 1884 |
}; |
| 1885 |
Err(e) |
| 1886 |
} |
| 1887 |
_ => _rt::invalid_enum_discriminant(), |
| 1888 |
}; |
| 1889 |
result5 |
| 1890 |
} |
| 1891 |
} |
| 1892 |
} |
| 1893 |
impl Descriptor { |
| 1894 |
#[allow(unused_unsafe, clippy::all)] |
| 1895 |
/// Adjust the size of an open file. If this increases the file's size, the |
| 1896 |
/// extra bytes are filled with zeros. |
| 1897 |
/// |
| 1898 |
/// Note: This was called `fd_filestat_set_size` in earlier versions of WASI. |
| 1899 |
#[allow(async_fn_in_trait)] |
| 1900 |
pub fn set_size(&self, size: Filesize) -> Result<(), ErrorCode> { |
| 1901 |
unsafe { |
| 1902 |
#[repr(align(1))] |
| 1903 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 1904 |
let mut ret_area = RetArea( |
| 1905 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 1906 |
); |
| 1907 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 1908 |
#[cfg(target_arch = "wasm32")] |
| 1909 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 1910 |
unsafe extern "C" { |
| 1911 |
#[link_name = "[method]descriptor.set-size"] |
| 1912 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 1913 |
} |
| 1914 |
#[cfg(not(target_arch = "wasm32"))] |
| 1915 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 1916 |
unreachable!() |
| 1917 |
} |
| 1918 |
wit_import1((self).handle() as i32, _rt::as_i64(size), ptr0); |
| 1919 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 1920 |
let result4 = match l2 { |
| 1921 |
0 => { |
| 1922 |
let e = (); |
| 1923 |
Ok(e) |
| 1924 |
} |
| 1925 |
1 => { |
| 1926 |
let e = { |
| 1927 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 1928 |
ErrorCode::_lift(l3 as u8) |
| 1929 |
}; |
| 1930 |
Err(e) |
| 1931 |
} |
| 1932 |
_ => _rt::invalid_enum_discriminant(), |
| 1933 |
}; |
| 1934 |
result4 |
| 1935 |
} |
| 1936 |
} |
| 1937 |
} |
| 1938 |
impl Descriptor { |
| 1939 |
#[allow(unused_unsafe, clippy::all)] |
| 1940 |
/// Adjust the timestamps of an open file or directory. |
| 1941 |
/// |
| 1942 |
/// Note: This is similar to `futimens` in POSIX. |
| 1943 |
/// |
| 1944 |
/// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. |
| 1945 |
#[allow(async_fn_in_trait)] |
| 1946 |
pub fn set_times( |
| 1947 |
&self, |
| 1948 |
data_access_timestamp: NewTimestamp, |
| 1949 |
data_modification_timestamp: NewTimestamp, |
| 1950 |
) -> Result<(), ErrorCode> { |
| 1951 |
unsafe { |
| 1952 |
#[repr(align(1))] |
| 1953 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 1954 |
let mut ret_area = RetArea( |
| 1955 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 1956 |
); |
| 1957 |
let (result1_0, result1_1, result1_2) = match data_access_timestamp { |
| 1958 |
NewTimestamp::NoChange => (0i32, 0i64, 0i32), |
| 1959 |
NewTimestamp::Now => (1i32, 0i64, 0i32), |
| 1960 |
NewTimestamp::Timestamp(e) => { |
| 1961 |
let super::super::super::wasi::clocks::wall_clock::Datetime { |
| 1962 |
seconds: seconds0, |
| 1963 |
nanoseconds: nanoseconds0, |
| 1964 |
} = e; |
| 1965 |
(2i32, _rt::as_i64(seconds0), _rt::as_i32(nanoseconds0)) |
| 1966 |
} |
| 1967 |
}; |
| 1968 |
let (result3_0, result3_1, result3_2) = match data_modification_timestamp { |
| 1969 |
NewTimestamp::NoChange => (0i32, 0i64, 0i32), |
| 1970 |
NewTimestamp::Now => (1i32, 0i64, 0i32), |
| 1971 |
NewTimestamp::Timestamp(e) => { |
| 1972 |
let super::super::super::wasi::clocks::wall_clock::Datetime { |
| 1973 |
seconds: seconds2, |
| 1974 |
nanoseconds: nanoseconds2, |
| 1975 |
} = e; |
| 1976 |
(2i32, _rt::as_i64(seconds2), _rt::as_i32(nanoseconds2)) |
| 1977 |
} |
| 1978 |
}; |
| 1979 |
let ptr4 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 1980 |
#[cfg(target_arch = "wasm32")] |
| 1981 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 1982 |
unsafe extern "C" { |
| 1983 |
#[link_name = "[method]descriptor.set-times"] |
| 1984 |
fn wit_import5( |
| 1985 |
_: i32, |
| 1986 |
_: i32, |
| 1987 |
_: i64, |
| 1988 |
_: i32, |
| 1989 |
_: i32, |
| 1990 |
_: i64, |
| 1991 |
_: i32, |
| 1992 |
_: *mut u8, |
| 1993 |
); |
| 1994 |
} |
| 1995 |
#[cfg(not(target_arch = "wasm32"))] |
| 1996 |
unsafe extern "C" fn wit_import5( |
| 1997 |
_: i32, |
| 1998 |
_: i32, |
| 1999 |
_: i64, |
| 2000 |
_: i32, |
| 2001 |
_: i32, |
| 2002 |
_: i64, |
| 2003 |
_: i32, |
| 2004 |
_: *mut u8, |
| 2005 |
) { |
| 2006 |
unreachable!() |
| 2007 |
} |
| 2008 |
wit_import5( |
| 2009 |
(self).handle() as i32, |
| 2010 |
result1_0, |
| 2011 |
result1_1, |
| 2012 |
result1_2, |
| 2013 |
result3_0, |
| 2014 |
result3_1, |
| 2015 |
result3_2, |
| 2016 |
ptr4, |
| 2017 |
); |
| 2018 |
let l6 = i32::from(*ptr4.add(0).cast::<u8>()); |
| 2019 |
let result8 = match l6 { |
| 2020 |
0 => { |
| 2021 |
let e = (); |
| 2022 |
Ok(e) |
| 2023 |
} |
| 2024 |
1 => { |
| 2025 |
let e = { |
| 2026 |
let l7 = i32::from(*ptr4.add(1).cast::<u8>()); |
| 2027 |
ErrorCode::_lift(l7 as u8) |
| 2028 |
}; |
| 2029 |
Err(e) |
| 2030 |
} |
| 2031 |
_ => _rt::invalid_enum_discriminant(), |
| 2032 |
}; |
| 2033 |
result8 |
| 2034 |
} |
| 2035 |
} |
| 2036 |
} |
| 2037 |
impl Descriptor { |
| 2038 |
#[allow(unused_unsafe, clippy::all)] |
| 2039 |
/// Read from a descriptor, without using and updating the descriptor's offset. |
| 2040 |
/// |
| 2041 |
/// This function returns a list of bytes containing the data that was |
| 2042 |
/// read, along with a bool which, when true, indicates that the end of the |
| 2043 |
/// file was reached. The returned list will contain up to `length` bytes; it |
| 2044 |
/// may return fewer than requested, if the end of the file is reached or |
| 2045 |
/// if the I/O operation is interrupted. |
| 2046 |
/// |
| 2047 |
/// In the future, this may change to return a `stream<u8, error-code>`. |
| 2048 |
/// |
| 2049 |
/// Note: This is similar to `pread` in POSIX. |
| 2050 |
#[allow(async_fn_in_trait)] |
| 2051 |
pub fn read( |
| 2052 |
&self, |
| 2053 |
length: Filesize, |
| 2054 |
offset: Filesize, |
| 2055 |
) -> Result<(_rt::Vec<u8>, bool), ErrorCode> { |
| 2056 |
unsafe { |
| 2057 |
#[cfg_attr(target_pointer_width = "64", repr(align(8)))] |
| 2058 |
#[cfg_attr(target_pointer_width = "32", repr(align(4)))] |
| 2059 |
struct RetArea( |
| 2060 |
[::core::mem::MaybeUninit< |
| 2061 |
u8, |
| 2062 |
>; 4 * ::core::mem::size_of::<*const u8>()], |
| 2063 |
); |
| 2064 |
let mut ret_area = RetArea( |
| 2065 |
[::core::mem::MaybeUninit::uninit(); 4 |
| 2066 |
* ::core::mem::size_of::<*const u8>()], |
| 2067 |
); |
| 2068 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 2069 |
#[cfg(target_arch = "wasm32")] |
| 2070 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 2071 |
unsafe extern "C" { |
| 2072 |
#[link_name = "[method]descriptor.read"] |
| 2073 |
fn wit_import1(_: i32, _: i64, _: i64, _: *mut u8); |
| 2074 |
} |
| 2075 |
#[cfg(not(target_arch = "wasm32"))] |
| 2076 |
unsafe extern "C" fn wit_import1( |
| 2077 |
_: i32, |
| 2078 |
_: i64, |
| 2079 |
_: i64, |
| 2080 |
_: *mut u8, |
| 2081 |
) { |
| 2082 |
unreachable!() |
| 2083 |
} |
| 2084 |
wit_import1( |
| 2085 |
(self).handle() as i32, |
| 2086 |
_rt::as_i64(length), |
| 2087 |
_rt::as_i64(offset), |
| 2088 |
ptr0, |
| 2089 |
); |
| 2090 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 2091 |
let result8 = match l2 { |
| 2092 |
0 => { |
| 2093 |
let e = { |
| 2094 |
let l3 = *ptr0 |
| 2095 |
.add(::core::mem::size_of::<*const u8>()) |
| 2096 |
.cast::<*mut u8>(); |
| 2097 |
let l4 = *ptr0 |
| 2098 |
.add(2 * ::core::mem::size_of::<*const u8>()) |
| 2099 |
.cast::<usize>(); |
| 2100 |
let len5 = l4; |
| 2101 |
let l6 = i32::from( |
| 2102 |
*ptr0 |
| 2103 |
.add(3 * ::core::mem::size_of::<*const u8>()) |
| 2104 |
.cast::<u8>(), |
| 2105 |
); |
| 2106 |
( |
| 2107 |
_rt::Vec::from_raw_parts(l3.cast(), len5, len5), |
| 2108 |
_rt::bool_lift(l6 as u8), |
| 2109 |
) |
| 2110 |
}; |
| 2111 |
Ok(e) |
| 2112 |
} |
| 2113 |
1 => { |
| 2114 |
let e = { |
| 2115 |
let l7 = i32::from( |
| 2116 |
*ptr0.add(::core::mem::size_of::<*const u8>()).cast::<u8>(), |
| 2117 |
); |
| 2118 |
ErrorCode::_lift(l7 as u8) |
| 2119 |
}; |
| 2120 |
Err(e) |
| 2121 |
} |
| 2122 |
_ => _rt::invalid_enum_discriminant(), |
| 2123 |
}; |
| 2124 |
result8 |
| 2125 |
} |
| 2126 |
} |
| 2127 |
} |
| 2128 |
impl Descriptor { |
| 2129 |
#[allow(unused_unsafe, clippy::all)] |
| 2130 |
/// Write to a descriptor, without using and updating the descriptor's offset. |
| 2131 |
/// |
| 2132 |
/// It is valid to write past the end of a file; the file is extended to the |
| 2133 |
/// extent of the write, with bytes between the previous end and the start of |
| 2134 |
/// the write set to zero. |
| 2135 |
/// |
| 2136 |
/// In the future, this may change to take a `stream<u8, error-code>`. |
| 2137 |
/// |
| 2138 |
/// Note: This is similar to `pwrite` in POSIX. |
| 2139 |
#[allow(async_fn_in_trait)] |
| 2140 |
pub fn write( |
| 2141 |
&self, |
| 2142 |
buffer: &[u8], |
| 2143 |
offset: Filesize, |
| 2144 |
) -> Result<Filesize, ErrorCode> { |
| 2145 |
unsafe { |
| 2146 |
#[repr(align(8))] |
| 2147 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 2148 |
let mut ret_area = RetArea( |
| 2149 |
[::core::mem::MaybeUninit::uninit(); 16], |
| 2150 |
); |
| 2151 |
let vec0 = buffer; |
| 2152 |
let ptr0 = vec0.as_ptr().cast::<u8>(); |
| 2153 |
let len0 = vec0.len(); |
| 2154 |
let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 2155 |
#[cfg(target_arch = "wasm32")] |
| 2156 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 2157 |
unsafe extern "C" { |
| 2158 |
#[link_name = "[method]descriptor.write"] |
| 2159 |
fn wit_import2( |
| 2160 |
_: i32, |
| 2161 |
_: *mut u8, |
| 2162 |
_: usize, |
| 2163 |
_: i64, |
| 2164 |
_: *mut u8, |
| 2165 |
); |
| 2166 |
} |
| 2167 |
#[cfg(not(target_arch = "wasm32"))] |
| 2168 |
unsafe extern "C" fn wit_import2( |
| 2169 |
_: i32, |
| 2170 |
_: *mut u8, |
| 2171 |
_: usize, |
| 2172 |
_: i64, |
| 2173 |
_: *mut u8, |
| 2174 |
) { |
| 2175 |
unreachable!() |
| 2176 |
} |
| 2177 |
wit_import2( |
| 2178 |
(self).handle() as i32, |
| 2179 |
ptr0.cast_mut(), |
| 2180 |
len0, |
| 2181 |
_rt::as_i64(offset), |
| 2182 |
ptr1, |
| 2183 |
); |
| 2184 |
let l3 = i32::from(*ptr1.add(0).cast::<u8>()); |
| 2185 |
let result6 = match l3 { |
| 2186 |
0 => { |
| 2187 |
let e = { |
| 2188 |
let l4 = *ptr1.add(8).cast::<i64>(); |
| 2189 |
l4 as u64 |
| 2190 |
}; |
| 2191 |
Ok(e) |
| 2192 |
} |
| 2193 |
1 => { |
| 2194 |
let e = { |
| 2195 |
let l5 = i32::from(*ptr1.add(8).cast::<u8>()); |
| 2196 |
ErrorCode::_lift(l5 as u8) |
| 2197 |
}; |
| 2198 |
Err(e) |
| 2199 |
} |
| 2200 |
_ => _rt::invalid_enum_discriminant(), |
| 2201 |
}; |
| 2202 |
result6 |
| 2203 |
} |
| 2204 |
} |
| 2205 |
} |
| 2206 |
impl Descriptor { |
| 2207 |
#[allow(unused_unsafe, clippy::all)] |
| 2208 |
/// Read directory entries from a directory. |
| 2209 |
/// |
| 2210 |
/// On filesystems where directories contain entries referring to themselves |
| 2211 |
/// and their parents, often named `.` and `..` respectively, these entries |
| 2212 |
/// are omitted. |
| 2213 |
/// |
| 2214 |
/// This always returns a new stream which starts at the beginning of the |
| 2215 |
/// directory. Multiple streams may be active on the same directory, and they |
| 2216 |
/// do not interfere with each other. |
| 2217 |
#[allow(async_fn_in_trait)] |
| 2218 |
pub fn read_directory(&self) -> Result<DirectoryEntryStream, ErrorCode> { |
| 2219 |
unsafe { |
| 2220 |
#[repr(align(4))] |
| 2221 |
struct RetArea([::core::mem::MaybeUninit<u8>; 8]); |
| 2222 |
let mut ret_area = RetArea( |
| 2223 |
[::core::mem::MaybeUninit::uninit(); 8], |
| 2224 |
); |
| 2225 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 2226 |
#[cfg(target_arch = "wasm32")] |
| 2227 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 2228 |
unsafe extern "C" { |
| 2229 |
#[link_name = "[method]descriptor.read-directory"] |
| 2230 |
fn wit_import1(_: i32, _: *mut u8); |
| 2231 |
} |
| 2232 |
#[cfg(not(target_arch = "wasm32"))] |
| 2233 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 2234 |
unreachable!() |
| 2235 |
} |
| 2236 |
wit_import1((self).handle() as i32, ptr0); |
| 2237 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 2238 |
let result5 = match l2 { |
| 2239 |
0 => { |
| 2240 |
let e = { |
| 2241 |
let l3 = *ptr0.add(4).cast::<i32>(); |
| 2242 |
DirectoryEntryStream::from_handle(l3 as u32) |
| 2243 |
}; |
| 2244 |
Ok(e) |
| 2245 |
} |
| 2246 |
1 => { |
| 2247 |
let e = { |
| 2248 |
let l4 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 2249 |
ErrorCode::_lift(l4 as u8) |
| 2250 |
}; |
| 2251 |
Err(e) |
| 2252 |
} |
| 2253 |
_ => _rt::invalid_enum_discriminant(), |
| 2254 |
}; |
| 2255 |
result5 |
| 2256 |
} |
| 2257 |
} |
| 2258 |
} |
| 2259 |
impl Descriptor { |
| 2260 |
#[allow(unused_unsafe, clippy::all)] |
| 2261 |
/// Synchronize the data and metadata of a file to disk. |
| 2262 |
/// |
| 2263 |
/// This function succeeds with no effect if the file descriptor is not |
| 2264 |
/// opened for writing. |
| 2265 |
/// |
| 2266 |
/// Note: This is similar to `fsync` in POSIX. |
| 2267 |
#[allow(async_fn_in_trait)] |
| 2268 |
pub fn sync(&self) -> Result<(), ErrorCode> { |
| 2269 |
unsafe { |
| 2270 |
#[repr(align(1))] |
| 2271 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 2272 |
let mut ret_area = RetArea( |
| 2273 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 2274 |
); |
| 2275 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 2276 |
#[cfg(target_arch = "wasm32")] |
| 2277 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 2278 |
unsafe extern "C" { |
| 2279 |
#[link_name = "[method]descriptor.sync"] |
| 2280 |
fn wit_import1(_: i32, _: *mut u8); |
| 2281 |
} |
| 2282 |
#[cfg(not(target_arch = "wasm32"))] |
| 2283 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 2284 |
unreachable!() |
| 2285 |
} |
| 2286 |
wit_import1((self).handle() as i32, ptr0); |
| 2287 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 2288 |
let result4 = match l2 { |
| 2289 |
0 => { |
| 2290 |
let e = (); |
| 2291 |
Ok(e) |
| 2292 |
} |
| 2293 |
1 => { |
| 2294 |
let e = { |
| 2295 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 2296 |
ErrorCode::_lift(l3 as u8) |
| 2297 |
}; |
| 2298 |
Err(e) |
| 2299 |
} |
| 2300 |
_ => _rt::invalid_enum_discriminant(), |
| 2301 |
}; |
| 2302 |
result4 |
| 2303 |
} |
| 2304 |
} |
| 2305 |
} |
| 2306 |
impl Descriptor { |
| 2307 |
#[allow(unused_unsafe, clippy::all)] |
| 2308 |
/// Create a directory. |
| 2309 |
/// |
| 2310 |
/// Note: This is similar to `mkdirat` in POSIX. |
| 2311 |
#[allow(async_fn_in_trait)] |
| 2312 |
pub fn create_directory_at(&self, path: &str) -> Result<(), ErrorCode> { |
| 2313 |
unsafe { |
| 2314 |
#[repr(align(1))] |
| 2315 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 2316 |
let mut ret_area = RetArea( |
| 2317 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 2318 |
); |
| 2319 |
let vec0 = path; |
| 2320 |
let ptr0 = vec0.as_ptr().cast::<u8>(); |
| 2321 |
let len0 = vec0.len(); |
| 2322 |
let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 2323 |
#[cfg(target_arch = "wasm32")] |
| 2324 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 2325 |
unsafe extern "C" { |
| 2326 |
#[link_name = "[method]descriptor.create-directory-at"] |
| 2327 |
fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8); |
| 2328 |
} |
| 2329 |
#[cfg(not(target_arch = "wasm32"))] |
| 2330 |
unsafe extern "C" fn wit_import2( |
| 2331 |
_: i32, |
| 2332 |
_: *mut u8, |
| 2333 |
_: usize, |
| 2334 |
_: *mut u8, |
| 2335 |
) { |
| 2336 |
unreachable!() |
| 2337 |
} |
| 2338 |
wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1); |
| 2339 |
let l3 = i32::from(*ptr1.add(0).cast::<u8>()); |
| 2340 |
let result5 = match l3 { |
| 2341 |
0 => { |
| 2342 |
let e = (); |
| 2343 |
Ok(e) |
| 2344 |
} |
| 2345 |
1 => { |
| 2346 |
let e = { |
| 2347 |
let l4 = i32::from(*ptr1.add(1).cast::<u8>()); |
| 2348 |
ErrorCode::_lift(l4 as u8) |
| 2349 |
}; |
| 2350 |
Err(e) |
| 2351 |
} |
| 2352 |
_ => _rt::invalid_enum_discriminant(), |
| 2353 |
}; |
| 2354 |
result5 |
| 2355 |
} |
| 2356 |
} |
| 2357 |
} |
| 2358 |
impl Descriptor { |
| 2359 |
#[allow(unused_unsafe, clippy::all)] |
| 2360 |
/// Return the attributes of an open file or directory. |
| 2361 |
/// |
| 2362 |
/// Note: This is similar to `fstat` in POSIX, except that it does not return |
| 2363 |
/// device and inode information. For testing whether two descriptors refer to |
| 2364 |
/// the same underlying filesystem object, use `is-same-object`. To obtain |
| 2365 |
/// additional data that can be used do determine whether a file has been |
| 2366 |
/// modified, use `metadata-hash`. |
| 2367 |
/// |
| 2368 |
/// Note: This was called `fd_filestat_get` in earlier versions of WASI. |
| 2369 |
#[allow(async_fn_in_trait)] |
| 2370 |
pub fn stat(&self) -> Result<DescriptorStat, ErrorCode> { |
| 2371 |
unsafe { |
| 2372 |
#[repr(align(8))] |
| 2373 |
struct RetArea([::core::mem::MaybeUninit<u8>; 104]); |
| 2374 |
let mut ret_area = RetArea( |
| 2375 |
[::core::mem::MaybeUninit::uninit(); 104], |
| 2376 |
); |
| 2377 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 2378 |
#[cfg(target_arch = "wasm32")] |
| 2379 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 2380 |
unsafe extern "C" { |
| 2381 |
#[link_name = "[method]descriptor.stat"] |
| 2382 |
fn wit_import1(_: i32, _: *mut u8); |
| 2383 |
} |
| 2384 |
#[cfg(not(target_arch = "wasm32"))] |
| 2385 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 2386 |
unreachable!() |
| 2387 |
} |
| 2388 |
wit_import1((self).handle() as i32, ptr0); |
| 2389 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 2390 |
let result16 = match l2 { |
| 2391 |
0 => { |
| 2392 |
let e = { |
| 2393 |
let l3 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 2394 |
let l4 = *ptr0.add(16).cast::<i64>(); |
| 2395 |
let l5 = *ptr0.add(24).cast::<i64>(); |
| 2396 |
let l6 = i32::from(*ptr0.add(32).cast::<u8>()); |
| 2397 |
let l9 = i32::from(*ptr0.add(56).cast::<u8>()); |
| 2398 |
let l12 = i32::from(*ptr0.add(80).cast::<u8>()); |
| 2399 |
DescriptorStat { |
| 2400 |
type_: DescriptorType::_lift(l3 as u8), |
| 2401 |
link_count: l4 as u64, |
| 2402 |
size: l5 as u64, |
| 2403 |
data_access_timestamp: match l6 { |
| 2404 |
0 => None, |
| 2405 |
1 => { |
| 2406 |
let e = { |
| 2407 |
let l7 = *ptr0.add(40).cast::<i64>(); |
| 2408 |
let l8 = *ptr0.add(48).cast::<i32>(); |
| 2409 |
super::super::super::wasi::clocks::wall_clock::Datetime { |
| 2410 |
seconds: l7 as u64, |
| 2411 |
nanoseconds: l8 as u32, |
| 2412 |
} |
| 2413 |
}; |
| 2414 |
Some(e) |
| 2415 |
} |
| 2416 |
_ => _rt::invalid_enum_discriminant(), |
| 2417 |
}, |
| 2418 |
data_modification_timestamp: match l9 { |
| 2419 |
0 => None, |
| 2420 |
1 => { |
| 2421 |
let e = { |
| 2422 |
let l10 = *ptr0.add(64).cast::<i64>(); |
| 2423 |
let l11 = *ptr0.add(72).cast::<i32>(); |
| 2424 |
super::super::super::wasi::clocks::wall_clock::Datetime { |
| 2425 |
seconds: l10 as u64, |
| 2426 |
nanoseconds: l11 as u32, |
| 2427 |
} |
| 2428 |
}; |
| 2429 |
Some(e) |
| 2430 |
} |
| 2431 |
_ => _rt::invalid_enum_discriminant(), |
| 2432 |
}, |
| 2433 |
status_change_timestamp: match l12 { |
| 2434 |
0 => None, |
| 2435 |
1 => { |
| 2436 |
let e = { |
| 2437 |
let l13 = *ptr0.add(88).cast::<i64>(); |
| 2438 |
let l14 = *ptr0.add(96).cast::<i32>(); |
| 2439 |
super::super::super::wasi::clocks::wall_clock::Datetime { |
| 2440 |
seconds: l13 as u64, |
| 2441 |
nanoseconds: l14 as u32, |
| 2442 |
} |
| 2443 |
}; |
| 2444 |
Some(e) |
| 2445 |
} |
| 2446 |
_ => _rt::invalid_enum_discriminant(), |
| 2447 |
}, |
| 2448 |
} |
| 2449 |
}; |
| 2450 |
Ok(e) |
| 2451 |
} |
| 2452 |
1 => { |
| 2453 |
let e = { |
| 2454 |
let l15 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 2455 |
ErrorCode::_lift(l15 as u8) |
| 2456 |
}; |
| 2457 |
Err(e) |
| 2458 |
} |
| 2459 |
_ => _rt::invalid_enum_discriminant(), |
| 2460 |
}; |
| 2461 |
result16 |
| 2462 |
} |
| 2463 |
} |
| 2464 |
} |
| 2465 |
impl Descriptor { |
| 2466 |
#[allow(unused_unsafe, clippy::all)] |
| 2467 |
/// Return the attributes of a file or directory. |
| 2468 |
/// |
| 2469 |
/// Note: This is similar to `fstatat` in POSIX, except that it does not |
| 2470 |
/// return device and inode information. See the `stat` description for a |
| 2471 |
/// discussion of alternatives. |
| 2472 |
/// |
| 2473 |
/// Note: This was called `path_filestat_get` in earlier versions of WASI. |
| 2474 |
#[allow(async_fn_in_trait)] |
| 2475 |
pub fn stat_at( |
| 2476 |
&self, |
| 2477 |
path_flags: PathFlags, |
| 2478 |
path: &str, |
| 2479 |
) -> Result<DescriptorStat, ErrorCode> { |
| 2480 |
unsafe { |
| 2481 |
#[repr(align(8))] |
| 2482 |
struct RetArea([::core::mem::MaybeUninit<u8>; 104]); |
| 2483 |
let mut ret_area = RetArea( |
| 2484 |
[::core::mem::MaybeUninit::uninit(); 104], |
| 2485 |
); |
| 2486 |
let flags0 = path_flags; |
| 2487 |
let vec1 = path; |
| 2488 |
let ptr1 = vec1.as_ptr().cast::<u8>(); |
| 2489 |
let len1 = vec1.len(); |
| 2490 |
let ptr2 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 2491 |
#[cfg(target_arch = "wasm32")] |
| 2492 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 2493 |
unsafe extern "C" { |
| 2494 |
#[link_name = "[method]descriptor.stat-at"] |
| 2495 |
fn wit_import3( |
| 2496 |
_: i32, |
| 2497 |
_: i32, |
| 2498 |
_: *mut u8, |
| 2499 |
_: usize, |
| 2500 |
_: *mut u8, |
| 2501 |
); |
| 2502 |
} |
| 2503 |
#[cfg(not(target_arch = "wasm32"))] |
| 2504 |
unsafe extern "C" fn wit_import3( |
| 2505 |
_: i32, |
| 2506 |
_: i32, |
| 2507 |
_: *mut u8, |
| 2508 |
_: usize, |
| 2509 |
_: *mut u8, |
| 2510 |
) { |
| 2511 |
unreachable!() |
| 2512 |
} |
| 2513 |
wit_import3( |
| 2514 |
(self).handle() as i32, |
| 2515 |
(flags0.bits() >> 0) as i32, |
| 2516 |
ptr1.cast_mut(), |
| 2517 |
len1, |
| 2518 |
ptr2, |
| 2519 |
); |
| 2520 |
let l4 = i32::from(*ptr2.add(0).cast::<u8>()); |
| 2521 |
let result18 = match l4 { |
| 2522 |
0 => { |
| 2523 |
let e = { |
| 2524 |
let l5 = i32::from(*ptr2.add(8).cast::<u8>()); |
| 2525 |
let l6 = *ptr2.add(16).cast::<i64>(); |
| 2526 |
let l7 = *ptr2.add(24).cast::<i64>(); |
| 2527 |
let l8 = i32::from(*ptr2.add(32).cast::<u8>()); |
| 2528 |
let l11 = i32::from(*ptr2.add(56).cast::<u8>()); |
| 2529 |
let l14 = i32::from(*ptr2.add(80).cast::<u8>()); |
| 2530 |
DescriptorStat { |
| 2531 |
type_: DescriptorType::_lift(l5 as u8), |
| 2532 |
link_count: l6 as u64, |
| 2533 |
size: l7 as u64, |
| 2534 |
data_access_timestamp: match l8 { |
| 2535 |
0 => None, |
| 2536 |
1 => { |
| 2537 |
let e = { |
| 2538 |
let l9 = *ptr2.add(40).cast::<i64>(); |
| 2539 |
let l10 = *ptr2.add(48).cast::<i32>(); |
| 2540 |
super::super::super::wasi::clocks::wall_clock::Datetime { |
| 2541 |
seconds: l9 as u64, |
| 2542 |
nanoseconds: l10 as u32, |
| 2543 |
} |
| 2544 |
}; |
| 2545 |
Some(e) |
| 2546 |
} |
| 2547 |
_ => _rt::invalid_enum_discriminant(), |
| 2548 |
}, |
| 2549 |
data_modification_timestamp: match l11 { |
| 2550 |
0 => None, |
| 2551 |
1 => { |
| 2552 |
let e = { |
| 2553 |
let l12 = *ptr2.add(64).cast::<i64>(); |
| 2554 |
let l13 = *ptr2.add(72).cast::<i32>(); |
| 2555 |
super::super::super::wasi::clocks::wall_clock::Datetime { |
| 2556 |
seconds: l12 as u64, |
| 2557 |
nanoseconds: l13 as u32, |
| 2558 |
} |
| 2559 |
}; |
| 2560 |
Some(e) |
| 2561 |
} |
| 2562 |
_ => _rt::invalid_enum_discriminant(), |
| 2563 |
}, |
| 2564 |
status_change_timestamp: match l14 { |
| 2565 |
0 => None, |
| 2566 |
1 => { |
| 2567 |
let e = { |
| 2568 |
let l15 = *ptr2.add(88).cast::<i64>(); |
| 2569 |
let l16 = *ptr2.add(96).cast::<i32>(); |
| 2570 |
super::super::super::wasi::clocks::wall_clock::Datetime { |
| 2571 |
seconds: l15 as u64, |
| 2572 |
nanoseconds: l16 as u32, |
| 2573 |
} |
| 2574 |
}; |
| 2575 |
Some(e) |
| 2576 |
} |
| 2577 |
_ => _rt::invalid_enum_discriminant(), |
| 2578 |
}, |
| 2579 |
} |
| 2580 |
}; |
| 2581 |
Ok(e) |
| 2582 |
} |
| 2583 |
1 => { |
| 2584 |
let e = { |
| 2585 |
let l17 = i32::from(*ptr2.add(8).cast::<u8>()); |
| 2586 |
ErrorCode::_lift(l17 as u8) |
| 2587 |
}; |
| 2588 |
Err(e) |
| 2589 |
} |
| 2590 |
_ => _rt::invalid_enum_discriminant(), |
| 2591 |
}; |
| 2592 |
result18 |
| 2593 |
} |
| 2594 |
} |
| 2595 |
} |
| 2596 |
impl Descriptor { |
| 2597 |
#[allow(unused_unsafe, clippy::all)] |
| 2598 |
/// Adjust the timestamps of a file or directory. |
| 2599 |
/// |
| 2600 |
/// Note: This is similar to `utimensat` in POSIX. |
| 2601 |
/// |
| 2602 |
/// Note: This was called `path_filestat_set_times` in earlier versions of |
| 2603 |
/// WASI. |
| 2604 |
#[allow(async_fn_in_trait)] |
| 2605 |
pub fn set_times_at( |
| 2606 |
&self, |
| 2607 |
path_flags: PathFlags, |
| 2608 |
path: &str, |
| 2609 |
data_access_timestamp: NewTimestamp, |
| 2610 |
data_modification_timestamp: NewTimestamp, |
| 2611 |
) -> Result<(), ErrorCode> { |
| 2612 |
unsafe { |
| 2613 |
#[repr(align(1))] |
| 2614 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 2615 |
let mut ret_area = RetArea( |
| 2616 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 2617 |
); |
| 2618 |
let flags0 = path_flags; |
| 2619 |
let vec1 = path; |
| 2620 |
let ptr1 = vec1.as_ptr().cast::<u8>(); |
| 2621 |
let len1 = vec1.len(); |
| 2622 |
let (result3_0, result3_1, result3_2) = match data_access_timestamp { |
| 2623 |
NewTimestamp::NoChange => (0i32, 0i64, 0i32), |
| 2624 |
NewTimestamp::Now => (1i32, 0i64, 0i32), |
| 2625 |
NewTimestamp::Timestamp(e) => { |
| 2626 |
let super::super::super::wasi::clocks::wall_clock::Datetime { |
| 2627 |
seconds: seconds2, |
| 2628 |
nanoseconds: nanoseconds2, |
| 2629 |
} = e; |
| 2630 |
(2i32, _rt::as_i64(seconds2), _rt::as_i32(nanoseconds2)) |
| 2631 |
} |
| 2632 |
}; |
| 2633 |
let (result5_0, result5_1, result5_2) = match data_modification_timestamp { |
| 2634 |
NewTimestamp::NoChange => (0i32, 0i64, 0i32), |
| 2635 |
NewTimestamp::Now => (1i32, 0i64, 0i32), |
| 2636 |
NewTimestamp::Timestamp(e) => { |
| 2637 |
let super::super::super::wasi::clocks::wall_clock::Datetime { |
| 2638 |
seconds: seconds4, |
| 2639 |
nanoseconds: nanoseconds4, |
| 2640 |
} = e; |
| 2641 |
(2i32, _rt::as_i64(seconds4), _rt::as_i32(nanoseconds4)) |
| 2642 |
} |
| 2643 |
}; |
| 2644 |
let ptr6 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 2645 |
#[cfg(target_arch = "wasm32")] |
| 2646 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 2647 |
unsafe extern "C" { |
| 2648 |
#[link_name = "[method]descriptor.set-times-at"] |
| 2649 |
fn wit_import7( |
| 2650 |
_: i32, |
| 2651 |
_: i32, |
| 2652 |
_: *mut u8, |
| 2653 |
_: usize, |
| 2654 |
_: i32, |
| 2655 |
_: i64, |
| 2656 |
_: i32, |
| 2657 |
_: i32, |
| 2658 |
_: i64, |
| 2659 |
_: i32, |
| 2660 |
_: *mut u8, |
| 2661 |
); |
| 2662 |
} |
| 2663 |
#[cfg(not(target_arch = "wasm32"))] |
| 2664 |
unsafe extern "C" fn wit_import7( |
| 2665 |
_: i32, |
| 2666 |
_: i32, |
| 2667 |
_: *mut u8, |
| 2668 |
_: usize, |
| 2669 |
_: i32, |
| 2670 |
_: i64, |
| 2671 |
_: i32, |
| 2672 |
_: i32, |
| 2673 |
_: i64, |
| 2674 |
_: i32, |
| 2675 |
_: *mut u8, |
| 2676 |
) { |
| 2677 |
unreachable!() |
| 2678 |
} |
| 2679 |
wit_import7( |
| 2680 |
(self).handle() as i32, |
| 2681 |
(flags0.bits() >> 0) as i32, |
| 2682 |
ptr1.cast_mut(), |
| 2683 |
len1, |
| 2684 |
result3_0, |
| 2685 |
result3_1, |
| 2686 |
result3_2, |
| 2687 |
result5_0, |
| 2688 |
result5_1, |
| 2689 |
result5_2, |
| 2690 |
ptr6, |
| 2691 |
); |
| 2692 |
let l8 = i32::from(*ptr6.add(0).cast::<u8>()); |
| 2693 |
let result10 = match l8 { |
| 2694 |
0 => { |
| 2695 |
let e = (); |
| 2696 |
Ok(e) |
| 2697 |
} |
| 2698 |
1 => { |
| 2699 |
let e = { |
| 2700 |
let l9 = i32::from(*ptr6.add(1).cast::<u8>()); |
| 2701 |
ErrorCode::_lift(l9 as u8) |
| 2702 |
}; |
| 2703 |
Err(e) |
| 2704 |
} |
| 2705 |
_ => _rt::invalid_enum_discriminant(), |
| 2706 |
}; |
| 2707 |
result10 |
| 2708 |
} |
| 2709 |
} |
| 2710 |
} |
| 2711 |
impl Descriptor { |
| 2712 |
#[allow(unused_unsafe, clippy::all)] |
| 2713 |
/// Create a hard link. |
| 2714 |
/// |
| 2715 |
/// Fails with `error-code::no-entry` if the old path does not exist, |
| 2716 |
/// with `error-code::exist` if the new path already exists, and |
| 2717 |
/// `error-code::not-permitted` if the old path is not a file. |
| 2718 |
/// |
| 2719 |
/// Note: This is similar to `linkat` in POSIX. |
| 2720 |
#[allow(async_fn_in_trait)] |
| 2721 |
pub fn link_at( |
| 2722 |
&self, |
| 2723 |
old_path_flags: PathFlags, |
| 2724 |
old_path: &str, |
| 2725 |
new_descriptor: &Descriptor, |
| 2726 |
new_path: &str, |
| 2727 |
) -> Result<(), ErrorCode> { |
| 2728 |
unsafe { |
| 2729 |
#[repr(align(1))] |
| 2730 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 2731 |
let mut ret_area = RetArea( |
| 2732 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 2733 |
); |
| 2734 |
let flags0 = old_path_flags; |
| 2735 |
let vec1 = old_path; |
| 2736 |
let ptr1 = vec1.as_ptr().cast::<u8>(); |
| 2737 |
let len1 = vec1.len(); |
| 2738 |
let vec2 = new_path; |
| 2739 |
let ptr2 = vec2.as_ptr().cast::<u8>(); |
| 2740 |
let len2 = vec2.len(); |
| 2741 |
let ptr3 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 2742 |
#[cfg(target_arch = "wasm32")] |
| 2743 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 2744 |
unsafe extern "C" { |
| 2745 |
#[link_name = "[method]descriptor.link-at"] |
| 2746 |
fn wit_import4( |
| 2747 |
_: i32, |
| 2748 |
_: i32, |
| 2749 |
_: *mut u8, |
| 2750 |
_: usize, |
| 2751 |
_: i32, |
| 2752 |
_: *mut u8, |
| 2753 |
_: usize, |
| 2754 |
_: *mut u8, |
| 2755 |
); |
| 2756 |
} |
| 2757 |
#[cfg(not(target_arch = "wasm32"))] |
| 2758 |
unsafe extern "C" fn wit_import4( |
| 2759 |
_: i32, |
| 2760 |
_: i32, |
| 2761 |
_: *mut u8, |
| 2762 |
_: usize, |
| 2763 |
_: i32, |
| 2764 |
_: *mut u8, |
| 2765 |
_: usize, |
| 2766 |
_: *mut u8, |
| 2767 |
) { |
| 2768 |
unreachable!() |
| 2769 |
} |
| 2770 |
wit_import4( |
| 2771 |
(self).handle() as i32, |
| 2772 |
(flags0.bits() >> 0) as i32, |
| 2773 |
ptr1.cast_mut(), |
| 2774 |
len1, |
| 2775 |
(new_descriptor).handle() as i32, |
| 2776 |
ptr2.cast_mut(), |
| 2777 |
len2, |
| 2778 |
ptr3, |
| 2779 |
); |
| 2780 |
let l5 = i32::from(*ptr3.add(0).cast::<u8>()); |
| 2781 |
let result7 = match l5 { |
| 2782 |
0 => { |
| 2783 |
let e = (); |
| 2784 |
Ok(e) |
| 2785 |
} |
| 2786 |
1 => { |
| 2787 |
let e = { |
| 2788 |
let l6 = i32::from(*ptr3.add(1).cast::<u8>()); |
| 2789 |
ErrorCode::_lift(l6 as u8) |
| 2790 |
}; |
| 2791 |
Err(e) |
| 2792 |
} |
| 2793 |
_ => _rt::invalid_enum_discriminant(), |
| 2794 |
}; |
| 2795 |
result7 |
| 2796 |
} |
| 2797 |
} |
| 2798 |
} |
| 2799 |
impl Descriptor { |
| 2800 |
#[allow(unused_unsafe, clippy::all)] |
| 2801 |
/// Open a file or directory. |
| 2802 |
/// |
| 2803 |
/// If `flags` contains `descriptor-flags::mutate-directory`, and the base |
| 2804 |
/// descriptor doesn't have `descriptor-flags::mutate-directory` set, |
| 2805 |
/// `open-at` fails with `error-code::read-only`. |
| 2806 |
/// |
| 2807 |
/// If `flags` contains `write` or `mutate-directory`, or `open-flags` |
| 2808 |
/// contains `truncate` or `create`, and the base descriptor doesn't have |
| 2809 |
/// `descriptor-flags::mutate-directory` set, `open-at` fails with |
| 2810 |
/// `error-code::read-only`. |
| 2811 |
/// |
| 2812 |
/// Note: This is similar to `openat` in POSIX. |
| 2813 |
#[allow(async_fn_in_trait)] |
| 2814 |
pub fn open_at( |
| 2815 |
&self, |
| 2816 |
path_flags: PathFlags, |
| 2817 |
path: &str, |
| 2818 |
open_flags: OpenFlags, |
| 2819 |
flags: DescriptorFlags, |
| 2820 |
) -> Result<Descriptor, ErrorCode> { |
| 2821 |
unsafe { |
| 2822 |
#[repr(align(4))] |
| 2823 |
struct RetArea([::core::mem::MaybeUninit<u8>; 8]); |
| 2824 |
let mut ret_area = RetArea( |
| 2825 |
[::core::mem::MaybeUninit::uninit(); 8], |
| 2826 |
); |
| 2827 |
let flags0 = path_flags; |
| 2828 |
let vec1 = path; |
| 2829 |
let ptr1 = vec1.as_ptr().cast::<u8>(); |
| 2830 |
let len1 = vec1.len(); |
| 2831 |
let flags2 = open_flags; |
| 2832 |
let flags3 = flags; |
| 2833 |
let ptr4 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 2834 |
#[cfg(target_arch = "wasm32")] |
| 2835 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 2836 |
unsafe extern "C" { |
| 2837 |
#[link_name = "[method]descriptor.open-at"] |
| 2838 |
fn wit_import5( |
| 2839 |
_: i32, |
| 2840 |
_: i32, |
| 2841 |
_: *mut u8, |
| 2842 |
_: usize, |
| 2843 |
_: i32, |
| 2844 |
_: i32, |
| 2845 |
_: *mut u8, |
| 2846 |
); |
| 2847 |
} |
| 2848 |
#[cfg(not(target_arch = "wasm32"))] |
| 2849 |
unsafe extern "C" fn wit_import5( |
| 2850 |
_: i32, |
| 2851 |
_: i32, |
| 2852 |
_: *mut u8, |
| 2853 |
_: usize, |
| 2854 |
_: i32, |
| 2855 |
_: i32, |
| 2856 |
_: *mut u8, |
| 2857 |
) { |
| 2858 |
unreachable!() |
| 2859 |
} |
| 2860 |
wit_import5( |
| 2861 |
(self).handle() as i32, |
| 2862 |
(flags0.bits() >> 0) as i32, |
| 2863 |
ptr1.cast_mut(), |
| 2864 |
len1, |
| 2865 |
(flags2.bits() >> 0) as i32, |
| 2866 |
(flags3.bits() >> 0) as i32, |
| 2867 |
ptr4, |
| 2868 |
); |
| 2869 |
let l6 = i32::from(*ptr4.add(0).cast::<u8>()); |
| 2870 |
let result9 = match l6 { |
| 2871 |
0 => { |
| 2872 |
let e = { |
| 2873 |
let l7 = *ptr4.add(4).cast::<i32>(); |
| 2874 |
Descriptor::from_handle(l7 as u32) |
| 2875 |
}; |
| 2876 |
Ok(e) |
| 2877 |
} |
| 2878 |
1 => { |
| 2879 |
let e = { |
| 2880 |
let l8 = i32::from(*ptr4.add(4).cast::<u8>()); |
| 2881 |
ErrorCode::_lift(l8 as u8) |
| 2882 |
}; |
| 2883 |
Err(e) |
| 2884 |
} |
| 2885 |
_ => _rt::invalid_enum_discriminant(), |
| 2886 |
}; |
| 2887 |
result9 |
| 2888 |
} |
| 2889 |
} |
| 2890 |
} |
| 2891 |
impl Descriptor { |
| 2892 |
#[allow(unused_unsafe, clippy::all)] |
| 2893 |
/// Read the contents of a symbolic link. |
| 2894 |
/// |
| 2895 |
/// If the contents contain an absolute or rooted path in the underlying |
| 2896 |
/// filesystem, this function fails with `error-code::not-permitted`. |
| 2897 |
/// |
| 2898 |
/// Note: This is similar to `readlinkat` in POSIX. |
| 2899 |
#[allow(async_fn_in_trait)] |
| 2900 |
pub fn readlink_at(&self, path: &str) -> Result<_rt::String, ErrorCode> { |
| 2901 |
unsafe { |
| 2902 |
#[cfg_attr(target_pointer_width = "64", repr(align(8)))] |
| 2903 |
#[cfg_attr(target_pointer_width = "32", repr(align(4)))] |
| 2904 |
struct RetArea( |
| 2905 |
[::core::mem::MaybeUninit< |
| 2906 |
u8, |
| 2907 |
>; 3 * ::core::mem::size_of::<*const u8>()], |
| 2908 |
); |
| 2909 |
let mut ret_area = RetArea( |
| 2910 |
[::core::mem::MaybeUninit::uninit(); 3 |
| 2911 |
* ::core::mem::size_of::<*const u8>()], |
| 2912 |
); |
| 2913 |
let vec0 = path; |
| 2914 |
let ptr0 = vec0.as_ptr().cast::<u8>(); |
| 2915 |
let len0 = vec0.len(); |
| 2916 |
let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 2917 |
#[cfg(target_arch = "wasm32")] |
| 2918 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 2919 |
unsafe extern "C" { |
| 2920 |
#[link_name = "[method]descriptor.readlink-at"] |
| 2921 |
fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8); |
| 2922 |
} |
| 2923 |
#[cfg(not(target_arch = "wasm32"))] |
| 2924 |
unsafe extern "C" fn wit_import2( |
| 2925 |
_: i32, |
| 2926 |
_: *mut u8, |
| 2927 |
_: usize, |
| 2928 |
_: *mut u8, |
| 2929 |
) { |
| 2930 |
unreachable!() |
| 2931 |
} |
| 2932 |
wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1); |
| 2933 |
let l3 = i32::from(*ptr1.add(0).cast::<u8>()); |
| 2934 |
let result8 = match l3 { |
| 2935 |
0 => { |
| 2936 |
let e = { |
| 2937 |
let l4 = *ptr1 |
| 2938 |
.add(::core::mem::size_of::<*const u8>()) |
| 2939 |
.cast::<*mut u8>(); |
| 2940 |
let l5 = *ptr1 |
| 2941 |
.add(2 * ::core::mem::size_of::<*const u8>()) |
| 2942 |
.cast::<usize>(); |
| 2943 |
let len6 = l5; |
| 2944 |
let bytes6 = _rt::Vec::from_raw_parts( |
| 2945 |
l4.cast(), |
| 2946 |
len6, |
| 2947 |
len6, |
| 2948 |
); |
| 2949 |
_rt::string_lift(bytes6) |
| 2950 |
}; |
| 2951 |
Ok(e) |
| 2952 |
} |
| 2953 |
1 => { |
| 2954 |
let e = { |
| 2955 |
let l7 = i32::from( |
| 2956 |
*ptr1.add(::core::mem::size_of::<*const u8>()).cast::<u8>(), |
| 2957 |
); |
| 2958 |
ErrorCode::_lift(l7 as u8) |
| 2959 |
}; |
| 2960 |
Err(e) |
| 2961 |
} |
| 2962 |
_ => _rt::invalid_enum_discriminant(), |
| 2963 |
}; |
| 2964 |
result8 |
| 2965 |
} |
| 2966 |
} |
| 2967 |
} |
| 2968 |
impl Descriptor { |
| 2969 |
#[allow(unused_unsafe, clippy::all)] |
| 2970 |
/// Remove a directory. |
| 2971 |
/// |
| 2972 |
/// Return `error-code::not-empty` if the directory is not empty. |
| 2973 |
/// |
| 2974 |
/// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. |
| 2975 |
#[allow(async_fn_in_trait)] |
| 2976 |
pub fn remove_directory_at(&self, path: &str) -> Result<(), ErrorCode> { |
| 2977 |
unsafe { |
| 2978 |
#[repr(align(1))] |
| 2979 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 2980 |
let mut ret_area = RetArea( |
| 2981 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 2982 |
); |
| 2983 |
let vec0 = path; |
| 2984 |
let ptr0 = vec0.as_ptr().cast::<u8>(); |
| 2985 |
let len0 = vec0.len(); |
| 2986 |
let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 2987 |
#[cfg(target_arch = "wasm32")] |
| 2988 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 2989 |
unsafe extern "C" { |
| 2990 |
#[link_name = "[method]descriptor.remove-directory-at"] |
| 2991 |
fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8); |
| 2992 |
} |
| 2993 |
#[cfg(not(target_arch = "wasm32"))] |
| 2994 |
unsafe extern "C" fn wit_import2( |
| 2995 |
_: i32, |
| 2996 |
_: *mut u8, |
| 2997 |
_: usize, |
| 2998 |
_: *mut u8, |
| 2999 |
) { |
| 3000 |
unreachable!() |
| 3001 |
} |
| 3002 |
wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1); |
| 3003 |
let l3 = i32::from(*ptr1.add(0).cast::<u8>()); |
| 3004 |
let result5 = match l3 { |
| 3005 |
0 => { |
| 3006 |
let e = (); |
| 3007 |
Ok(e) |
| 3008 |
} |
| 3009 |
1 => { |
| 3010 |
let e = { |
| 3011 |
let l4 = i32::from(*ptr1.add(1).cast::<u8>()); |
| 3012 |
ErrorCode::_lift(l4 as u8) |
| 3013 |
}; |
| 3014 |
Err(e) |
| 3015 |
} |
| 3016 |
_ => _rt::invalid_enum_discriminant(), |
| 3017 |
}; |
| 3018 |
result5 |
| 3019 |
} |
| 3020 |
} |
| 3021 |
} |
| 3022 |
impl Descriptor { |
| 3023 |
#[allow(unused_unsafe, clippy::all)] |
| 3024 |
/// Rename a filesystem object. |
| 3025 |
/// |
| 3026 |
/// Note: This is similar to `renameat` in POSIX. |
| 3027 |
#[allow(async_fn_in_trait)] |
| 3028 |
pub fn rename_at( |
| 3029 |
&self, |
| 3030 |
old_path: &str, |
| 3031 |
new_descriptor: &Descriptor, |
| 3032 |
new_path: &str, |
| 3033 |
) -> Result<(), ErrorCode> { |
| 3034 |
unsafe { |
| 3035 |
#[repr(align(1))] |
| 3036 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 3037 |
let mut ret_area = RetArea( |
| 3038 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 3039 |
); |
| 3040 |
let vec0 = old_path; |
| 3041 |
let ptr0 = vec0.as_ptr().cast::<u8>(); |
| 3042 |
let len0 = vec0.len(); |
| 3043 |
let vec1 = new_path; |
| 3044 |
let ptr1 = vec1.as_ptr().cast::<u8>(); |
| 3045 |
let len1 = vec1.len(); |
| 3046 |
let ptr2 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 3047 |
#[cfg(target_arch = "wasm32")] |
| 3048 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 3049 |
unsafe extern "C" { |
| 3050 |
#[link_name = "[method]descriptor.rename-at"] |
| 3051 |
fn wit_import3( |
| 3052 |
_: i32, |
| 3053 |
_: *mut u8, |
| 3054 |
_: usize, |
| 3055 |
_: i32, |
| 3056 |
_: *mut u8, |
| 3057 |
_: usize, |
| 3058 |
_: *mut u8, |
| 3059 |
); |
| 3060 |
} |
| 3061 |
#[cfg(not(target_arch = "wasm32"))] |
| 3062 |
unsafe extern "C" fn wit_import3( |
| 3063 |
_: i32, |
| 3064 |
_: *mut u8, |
| 3065 |
_: usize, |
| 3066 |
_: i32, |
| 3067 |
_: *mut u8, |
| 3068 |
_: usize, |
| 3069 |
_: *mut u8, |
| 3070 |
) { |
| 3071 |
unreachable!() |
| 3072 |
} |
| 3073 |
wit_import3( |
| 3074 |
(self).handle() as i32, |
| 3075 |
ptr0.cast_mut(), |
| 3076 |
len0, |
| 3077 |
(new_descriptor).handle() as i32, |
| 3078 |
ptr1.cast_mut(), |
| 3079 |
len1, |
| 3080 |
ptr2, |
| 3081 |
); |
| 3082 |
let l4 = i32::from(*ptr2.add(0).cast::<u8>()); |
| 3083 |
let result6 = match l4 { |
| 3084 |
0 => { |
| 3085 |
let e = (); |
| 3086 |
Ok(e) |
| 3087 |
} |
| 3088 |
1 => { |
| 3089 |
let e = { |
| 3090 |
let l5 = i32::from(*ptr2.add(1).cast::<u8>()); |
| 3091 |
ErrorCode::_lift(l5 as u8) |
| 3092 |
}; |
| 3093 |
Err(e) |
| 3094 |
} |
| 3095 |
_ => _rt::invalid_enum_discriminant(), |
| 3096 |
}; |
| 3097 |
result6 |
| 3098 |
} |
| 3099 |
} |
| 3100 |
} |
| 3101 |
impl Descriptor { |
| 3102 |
#[allow(unused_unsafe, clippy::all)] |
| 3103 |
/// Create a symbolic link (also known as a "symlink"). |
| 3104 |
/// |
| 3105 |
/// If `old-path` starts with `/`, the function fails with |
| 3106 |
/// `error-code::not-permitted`. |
| 3107 |
/// |
| 3108 |
/// Note: This is similar to `symlinkat` in POSIX. |
| 3109 |
#[allow(async_fn_in_trait)] |
| 3110 |
pub fn symlink_at( |
| 3111 |
&self, |
| 3112 |
old_path: &str, |
| 3113 |
new_path: &str, |
| 3114 |
) -> Result<(), ErrorCode> { |
| 3115 |
unsafe { |
| 3116 |
#[repr(align(1))] |
| 3117 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 3118 |
let mut ret_area = RetArea( |
| 3119 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 3120 |
); |
| 3121 |
let vec0 = old_path; |
| 3122 |
let ptr0 = vec0.as_ptr().cast::<u8>(); |
| 3123 |
let len0 = vec0.len(); |
| 3124 |
let vec1 = new_path; |
| 3125 |
let ptr1 = vec1.as_ptr().cast::<u8>(); |
| 3126 |
let len1 = vec1.len(); |
| 3127 |
let ptr2 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 3128 |
#[cfg(target_arch = "wasm32")] |
| 3129 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 3130 |
unsafe extern "C" { |
| 3131 |
#[link_name = "[method]descriptor.symlink-at"] |
| 3132 |
fn wit_import3( |
| 3133 |
_: i32, |
| 3134 |
_: *mut u8, |
| 3135 |
_: usize, |
| 3136 |
_: *mut u8, |
| 3137 |
_: usize, |
| 3138 |
_: *mut u8, |
| 3139 |
); |
| 3140 |
} |
| 3141 |
#[cfg(not(target_arch = "wasm32"))] |
| 3142 |
unsafe extern "C" fn wit_import3( |
| 3143 |
_: i32, |
| 3144 |
_: *mut u8, |
| 3145 |
_: usize, |
| 3146 |
_: *mut u8, |
| 3147 |
_: usize, |
| 3148 |
_: *mut u8, |
| 3149 |
) { |
| 3150 |
unreachable!() |
| 3151 |
} |
| 3152 |
wit_import3( |
| 3153 |
(self).handle() as i32, |
| 3154 |
ptr0.cast_mut(), |
| 3155 |
len0, |
| 3156 |
ptr1.cast_mut(), |
| 3157 |
len1, |
| 3158 |
ptr2, |
| 3159 |
); |
| 3160 |
let l4 = i32::from(*ptr2.add(0).cast::<u8>()); |
| 3161 |
let result6 = match l4 { |
| 3162 |
0 => { |
| 3163 |
let e = (); |
| 3164 |
Ok(e) |
| 3165 |
} |
| 3166 |
1 => { |
| 3167 |
let e = { |
| 3168 |
let l5 = i32::from(*ptr2.add(1).cast::<u8>()); |
| 3169 |
ErrorCode::_lift(l5 as u8) |
| 3170 |
}; |
| 3171 |
Err(e) |
| 3172 |
} |
| 3173 |
_ => _rt::invalid_enum_discriminant(), |
| 3174 |
}; |
| 3175 |
result6 |
| 3176 |
} |
| 3177 |
} |
| 3178 |
} |
| 3179 |
impl Descriptor { |
| 3180 |
#[allow(unused_unsafe, clippy::all)] |
| 3181 |
/// Unlink a filesystem object that is not a directory. |
| 3182 |
/// |
| 3183 |
/// Return `error-code::is-directory` if the path refers to a directory. |
| 3184 |
/// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. |
| 3185 |
#[allow(async_fn_in_trait)] |
| 3186 |
pub fn unlink_file_at(&self, path: &str) -> Result<(), ErrorCode> { |
| 3187 |
unsafe { |
| 3188 |
#[repr(align(1))] |
| 3189 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 3190 |
let mut ret_area = RetArea( |
| 3191 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 3192 |
); |
| 3193 |
let vec0 = path; |
| 3194 |
let ptr0 = vec0.as_ptr().cast::<u8>(); |
| 3195 |
let len0 = vec0.len(); |
| 3196 |
let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 3197 |
#[cfg(target_arch = "wasm32")] |
| 3198 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 3199 |
unsafe extern "C" { |
| 3200 |
#[link_name = "[method]descriptor.unlink-file-at"] |
| 3201 |
fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8); |
| 3202 |
} |
| 3203 |
#[cfg(not(target_arch = "wasm32"))] |
| 3204 |
unsafe extern "C" fn wit_import2( |
| 3205 |
_: i32, |
| 3206 |
_: *mut u8, |
| 3207 |
_: usize, |
| 3208 |
_: *mut u8, |
| 3209 |
) { |
| 3210 |
unreachable!() |
| 3211 |
} |
| 3212 |
wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1); |
| 3213 |
let l3 = i32::from(*ptr1.add(0).cast::<u8>()); |
| 3214 |
let result5 = match l3 { |
| 3215 |
0 => { |
| 3216 |
let e = (); |
| 3217 |
Ok(e) |
| 3218 |
} |
| 3219 |
1 => { |
| 3220 |
let e = { |
| 3221 |
let l4 = i32::from(*ptr1.add(1).cast::<u8>()); |
| 3222 |
ErrorCode::_lift(l4 as u8) |
| 3223 |
}; |
| 3224 |
Err(e) |
| 3225 |
} |
| 3226 |
_ => _rt::invalid_enum_discriminant(), |
| 3227 |
}; |
| 3228 |
result5 |
| 3229 |
} |
| 3230 |
} |
| 3231 |
} |
| 3232 |
impl Descriptor { |
| 3233 |
#[allow(unused_unsafe, clippy::all)] |
| 3234 |
/// Test whether two descriptors refer to the same filesystem object. |
| 3235 |
/// |
| 3236 |
/// In POSIX, this corresponds to testing whether the two descriptors have the |
| 3237 |
/// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers. |
| 3238 |
/// wasi-filesystem does not expose device and inode numbers, so this function |
| 3239 |
/// may be used instead. |
| 3240 |
#[allow(async_fn_in_trait)] |
| 3241 |
pub fn is_same_object(&self, other: &Descriptor) -> bool { |
| 3242 |
unsafe { |
| 3243 |
#[cfg(target_arch = "wasm32")] |
| 3244 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 3245 |
unsafe extern "C" { |
| 3246 |
#[link_name = "[method]descriptor.is-same-object"] |
| 3247 |
fn wit_import0(_: i32, _: i32) -> i32; |
| 3248 |
} |
| 3249 |
#[cfg(not(target_arch = "wasm32"))] |
| 3250 |
unsafe extern "C" fn wit_import0(_: i32, _: i32) -> i32 { |
| 3251 |
unreachable!() |
| 3252 |
} |
| 3253 |
let ret = wit_import0( |
| 3254 |
(self).handle() as i32, |
| 3255 |
(other).handle() as i32, |
| 3256 |
); |
| 3257 |
_rt::bool_lift(ret as u8) |
| 3258 |
} |
| 3259 |
} |
| 3260 |
} |
| 3261 |
impl Descriptor { |
| 3262 |
#[allow(unused_unsafe, clippy::all)] |
| 3263 |
/// Return a hash of the metadata associated with a filesystem object referred |
| 3264 |
/// to by a descriptor. |
| 3265 |
/// |
| 3266 |
/// This returns a hash of the last-modification timestamp and file size, and |
| 3267 |
/// may also include the inode number, device number, birth timestamp, and |
| 3268 |
/// other metadata fields that may change when the file is modified or |
| 3269 |
/// replaced. It may also include a secret value chosen by the |
| 3270 |
/// implementation and not otherwise exposed. |
| 3271 |
/// |
| 3272 |
/// Implementations are encouraged to provide the following properties: |
| 3273 |
/// |
| 3274 |
/// - If the file is not modified or replaced, the computed hash value should |
| 3275 |
/// usually not change. |
| 3276 |
/// - If the object is modified or replaced, the computed hash value should |
| 3277 |
/// usually change. |
| 3278 |
/// - The inputs to the hash should not be easily computable from the |
| 3279 |
/// computed hash. |
| 3280 |
/// |
| 3281 |
/// However, none of these is required. |
| 3282 |
#[allow(async_fn_in_trait)] |
| 3283 |
pub fn metadata_hash(&self) -> Result<MetadataHashValue, ErrorCode> { |
| 3284 |
unsafe { |
| 3285 |
#[repr(align(8))] |
| 3286 |
struct RetArea([::core::mem::MaybeUninit<u8>; 24]); |
| 3287 |
let mut ret_area = RetArea( |
| 3288 |
[::core::mem::MaybeUninit::uninit(); 24], |
| 3289 |
); |
| 3290 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 3291 |
#[cfg(target_arch = "wasm32")] |
| 3292 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 3293 |
unsafe extern "C" { |
| 3294 |
#[link_name = "[method]descriptor.metadata-hash"] |
| 3295 |
fn wit_import1(_: i32, _: *mut u8); |
| 3296 |
} |
| 3297 |
#[cfg(not(target_arch = "wasm32"))] |
| 3298 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 3299 |
unreachable!() |
| 3300 |
} |
| 3301 |
wit_import1((self).handle() as i32, ptr0); |
| 3302 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 3303 |
let result6 = match l2 { |
| 3304 |
0 => { |
| 3305 |
let e = { |
| 3306 |
let l3 = *ptr0.add(8).cast::<i64>(); |
| 3307 |
let l4 = *ptr0.add(16).cast::<i64>(); |
| 3308 |
MetadataHashValue { |
| 3309 |
lower: l3 as u64, |
| 3310 |
upper: l4 as u64, |
| 3311 |
} |
| 3312 |
}; |
| 3313 |
Ok(e) |
| 3314 |
} |
| 3315 |
1 => { |
| 3316 |
let e = { |
| 3317 |
let l5 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 3318 |
ErrorCode::_lift(l5 as u8) |
| 3319 |
}; |
| 3320 |
Err(e) |
| 3321 |
} |
| 3322 |
_ => _rt::invalid_enum_discriminant(), |
| 3323 |
}; |
| 3324 |
result6 |
| 3325 |
} |
| 3326 |
} |
| 3327 |
} |
| 3328 |
impl Descriptor { |
| 3329 |
#[allow(unused_unsafe, clippy::all)] |
| 3330 |
/// Return a hash of the metadata associated with a filesystem object referred |
| 3331 |
/// to by a directory descriptor and a relative path. |
| 3332 |
/// |
| 3333 |
/// This performs the same hash computation as `metadata-hash`. |
| 3334 |
#[allow(async_fn_in_trait)] |
| 3335 |
pub fn metadata_hash_at( |
| 3336 |
&self, |
| 3337 |
path_flags: PathFlags, |
| 3338 |
path: &str, |
| 3339 |
) -> Result<MetadataHashValue, ErrorCode> { |
| 3340 |
unsafe { |
| 3341 |
#[repr(align(8))] |
| 3342 |
struct RetArea([::core::mem::MaybeUninit<u8>; 24]); |
| 3343 |
let mut ret_area = RetArea( |
| 3344 |
[::core::mem::MaybeUninit::uninit(); 24], |
| 3345 |
); |
| 3346 |
let flags0 = path_flags; |
| 3347 |
let vec1 = path; |
| 3348 |
let ptr1 = vec1.as_ptr().cast::<u8>(); |
| 3349 |
let len1 = vec1.len(); |
| 3350 |
let ptr2 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 3351 |
#[cfg(target_arch = "wasm32")] |
| 3352 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 3353 |
unsafe extern "C" { |
| 3354 |
#[link_name = "[method]descriptor.metadata-hash-at"] |
| 3355 |
fn wit_import3( |
| 3356 |
_: i32, |
| 3357 |
_: i32, |
| 3358 |
_: *mut u8, |
| 3359 |
_: usize, |
| 3360 |
_: *mut u8, |
| 3361 |
); |
| 3362 |
} |
| 3363 |
#[cfg(not(target_arch = "wasm32"))] |
| 3364 |
unsafe extern "C" fn wit_import3( |
| 3365 |
_: i32, |
| 3366 |
_: i32, |
| 3367 |
_: *mut u8, |
| 3368 |
_: usize, |
| 3369 |
_: *mut u8, |
| 3370 |
) { |
| 3371 |
unreachable!() |
| 3372 |
} |
| 3373 |
wit_import3( |
| 3374 |
(self).handle() as i32, |
| 3375 |
(flags0.bits() >> 0) as i32, |
| 3376 |
ptr1.cast_mut(), |
| 3377 |
len1, |
| 3378 |
ptr2, |
| 3379 |
); |
| 3380 |
let l4 = i32::from(*ptr2.add(0).cast::<u8>()); |
| 3381 |
let result8 = match l4 { |
| 3382 |
0 => { |
| 3383 |
let e = { |
| 3384 |
let l5 = *ptr2.add(8).cast::<i64>(); |
| 3385 |
let l6 = *ptr2.add(16).cast::<i64>(); |
| 3386 |
MetadataHashValue { |
| 3387 |
lower: l5 as u64, |
| 3388 |
upper: l6 as u64, |
| 3389 |
} |
| 3390 |
}; |
| 3391 |
Ok(e) |
| 3392 |
} |
| 3393 |
1 => { |
| 3394 |
let e = { |
| 3395 |
let l7 = i32::from(*ptr2.add(8).cast::<u8>()); |
| 3396 |
ErrorCode::_lift(l7 as u8) |
| 3397 |
}; |
| 3398 |
Err(e) |
| 3399 |
} |
| 3400 |
_ => _rt::invalid_enum_discriminant(), |
| 3401 |
}; |
| 3402 |
result8 |
| 3403 |
} |
| 3404 |
} |
| 3405 |
} |
| 3406 |
impl DirectoryEntryStream { |
| 3407 |
#[allow(unused_unsafe, clippy::all)] |
| 3408 |
/// Read a single directory entry from a `directory-entry-stream`. |
| 3409 |
#[allow(async_fn_in_trait)] |
| 3410 |
pub fn read_directory_entry( |
| 3411 |
&self, |
| 3412 |
) -> Result<Option<DirectoryEntry>, ErrorCode> { |
| 3413 |
unsafe { |
| 3414 |
#[cfg_attr(target_pointer_width = "64", repr(align(8)))] |
| 3415 |
#[cfg_attr(target_pointer_width = "32", repr(align(4)))] |
| 3416 |
struct RetArea( |
| 3417 |
[::core::mem::MaybeUninit< |
| 3418 |
u8, |
| 3419 |
>; 5 * ::core::mem::size_of::<*const u8>()], |
| 3420 |
); |
| 3421 |
let mut ret_area = RetArea( |
| 3422 |
[::core::mem::MaybeUninit::uninit(); 5 |
| 3423 |
* ::core::mem::size_of::<*const u8>()], |
| 3424 |
); |
| 3425 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 3426 |
#[cfg(target_arch = "wasm32")] |
| 3427 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 3428 |
unsafe extern "C" { |
| 3429 |
#[link_name = "[method]directory-entry-stream.read-directory-entry"] |
| 3430 |
fn wit_import1(_: i32, _: *mut u8); |
| 3431 |
} |
| 3432 |
#[cfg(not(target_arch = "wasm32"))] |
| 3433 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 3434 |
unreachable!() |
| 3435 |
} |
| 3436 |
wit_import1((self).handle() as i32, ptr0); |
| 3437 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 3438 |
let result9 = match l2 { |
| 3439 |
0 => { |
| 3440 |
let e = { |
| 3441 |
let l3 = i32::from( |
| 3442 |
*ptr0.add(::core::mem::size_of::<*const u8>()).cast::<u8>(), |
| 3443 |
); |
| 3444 |
match l3 { |
| 3445 |
0 => None, |
| 3446 |
1 => { |
| 3447 |
let e = { |
| 3448 |
let l4 = i32::from( |
| 3449 |
*ptr0 |
| 3450 |
.add(2 * ::core::mem::size_of::<*const u8>()) |
| 3451 |
.cast::<u8>(), |
| 3452 |
); |
| 3453 |
let l5 = *ptr0 |
| 3454 |
.add(3 * ::core::mem::size_of::<*const u8>()) |
| 3455 |
.cast::<*mut u8>(); |
| 3456 |
let l6 = *ptr0 |
| 3457 |
.add(4 * ::core::mem::size_of::<*const u8>()) |
| 3458 |
.cast::<usize>(); |
| 3459 |
let len7 = l6; |
| 3460 |
let bytes7 = _rt::Vec::from_raw_parts( |
| 3461 |
l5.cast(), |
| 3462 |
len7, |
| 3463 |
len7, |
| 3464 |
); |
| 3465 |
DirectoryEntry { |
| 3466 |
type_: DescriptorType::_lift(l4 as u8), |
| 3467 |
name: _rt::string_lift(bytes7), |
| 3468 |
} |
| 3469 |
}; |
| 3470 |
Some(e) |
| 3471 |
} |
| 3472 |
_ => _rt::invalid_enum_discriminant(), |
| 3473 |
} |
| 3474 |
}; |
| 3475 |
Ok(e) |
| 3476 |
} |
| 3477 |
1 => { |
| 3478 |
let e = { |
| 3479 |
let l8 = i32::from( |
| 3480 |
*ptr0.add(::core::mem::size_of::<*const u8>()).cast::<u8>(), |
| 3481 |
); |
| 3482 |
ErrorCode::_lift(l8 as u8) |
| 3483 |
}; |
| 3484 |
Err(e) |
| 3485 |
} |
| 3486 |
_ => _rt::invalid_enum_discriminant(), |
| 3487 |
}; |
| 3488 |
result9 |
| 3489 |
} |
| 3490 |
} |
| 3491 |
} |
| 3492 |
#[allow(unused_unsafe, clippy::all)] |
| 3493 |
/// Attempts to extract a filesystem-related `error-code` from the stream |
| 3494 |
/// `error` provided. |
| 3495 |
/// |
| 3496 |
/// Stream operations which return `stream-error::last-operation-failed` |
| 3497 |
/// have a payload with more information about the operation that failed. |
| 3498 |
/// This payload can be passed through to this function to see if there's |
| 3499 |
/// filesystem-related information about the error to return. |
| 3500 |
/// |
| 3501 |
/// Note that this function is fallible because not all stream-related |
| 3502 |
/// errors are filesystem-related errors. |
| 3503 |
#[allow(async_fn_in_trait)] |
| 3504 |
pub fn filesystem_error_code(err: &Error) -> Option<ErrorCode> { |
| 3505 |
unsafe { |
| 3506 |
#[repr(align(1))] |
| 3507 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 3508 |
let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 2]); |
| 3509 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 3510 |
#[cfg(target_arch = "wasm32")] |
| 3511 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 3512 |
unsafe extern "C" { |
| 3513 |
#[link_name = "filesystem-error-code"] |
| 3514 |
fn wit_import1(_: i32, _: *mut u8); |
| 3515 |
} |
| 3516 |
#[cfg(not(target_arch = "wasm32"))] |
| 3517 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 3518 |
unreachable!() |
| 3519 |
} |
| 3520 |
wit_import1((err).handle() as i32, ptr0); |
| 3521 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 3522 |
let result4 = match l2 { |
| 3523 |
0 => None, |
| 3524 |
1 => { |
| 3525 |
let e = { |
| 3526 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 3527 |
ErrorCode::_lift(l3 as u8) |
| 3528 |
}; |
| 3529 |
Some(e) |
| 3530 |
} |
| 3531 |
_ => _rt::invalid_enum_discriminant(), |
| 3532 |
}; |
| 3533 |
result4 |
| 3534 |
} |
| 3535 |
} |
| 3536 |
} |
| 3537 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 3538 |
pub mod preopens { |
| 3539 |
#[used] |
| 3540 |
#[doc(hidden)] |
| 3541 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 3542 |
use super::super::super::_rt; |
| 3543 |
pub type Descriptor = super::super::super::wasi::filesystem::types::Descriptor; |
| 3544 |
#[allow(unused_unsafe, clippy::all)] |
| 3545 |
/// Return the set of preopened directories, and their paths. |
| 3546 |
#[allow(async_fn_in_trait)] |
| 3547 |
pub fn get_directories() -> _rt::Vec<(Descriptor, _rt::String)> { |
| 3548 |
unsafe { |
| 3549 |
#[cfg_attr(target_pointer_width = "64", repr(align(8)))] |
| 3550 |
#[cfg_attr(target_pointer_width = "32", repr(align(4)))] |
| 3551 |
struct RetArea( |
| 3552 |
[::core::mem::MaybeUninit< |
| 3553 |
u8, |
| 3554 |
>; 2 * ::core::mem::size_of::<*const u8>()], |
| 3555 |
); |
| 3556 |
let mut ret_area = RetArea( |
| 3557 |
[::core::mem::MaybeUninit::uninit(); 2 |
| 3558 |
* ::core::mem::size_of::<*const u8>()], |
| 3559 |
); |
| 3560 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 3561 |
#[cfg(target_arch = "wasm32")] |
| 3562 |
#[link(wasm_import_module = "wasi:filesystem/[email protected]")] |
| 3563 |
unsafe extern "C" { |
| 3564 |
#[link_name = "get-directories"] |
| 3565 |
fn wit_import1(_: *mut u8); |
| 3566 |
} |
| 3567 |
#[cfg(not(target_arch = "wasm32"))] |
| 3568 |
unsafe extern "C" fn wit_import1(_: *mut u8) { |
| 3569 |
unreachable!() |
| 3570 |
} |
| 3571 |
wit_import1(ptr0); |
| 3572 |
let l2 = *ptr0.add(0).cast::<*mut u8>(); |
| 3573 |
let l3 = *ptr0 |
| 3574 |
.add(::core::mem::size_of::<*const u8>()) |
| 3575 |
.cast::<usize>(); |
| 3576 |
let base8 = l2; |
| 3577 |
let len8 = l3; |
| 3578 |
let mut result8 = _rt::Vec::with_capacity(len8); |
| 3579 |
for i in 0..len8 { |
| 3580 |
let base = base8 |
| 3581 |
.add(i * (3 * ::core::mem::size_of::<*const u8>())); |
| 3582 |
let e8 = { |
| 3583 |
let l4 = *base.add(0).cast::<i32>(); |
| 3584 |
let l5 = *base |
| 3585 |
.add(::core::mem::size_of::<*const u8>()) |
| 3586 |
.cast::<*mut u8>(); |
| 3587 |
let l6 = *base |
| 3588 |
.add(2 * ::core::mem::size_of::<*const u8>()) |
| 3589 |
.cast::<usize>(); |
| 3590 |
let len7 = l6; |
| 3591 |
let bytes7 = _rt::Vec::from_raw_parts(l5.cast(), len7, len7); |
| 3592 |
( |
| 3593 |
super::super::super::wasi::filesystem::types::Descriptor::from_handle( |
| 3594 |
l4 as u32, |
| 3595 |
), |
| 3596 |
_rt::string_lift(bytes7), |
| 3597 |
) |
| 3598 |
}; |
| 3599 |
result8.push(e8); |
| 3600 |
} |
| 3601 |
_rt::cabi_dealloc( |
| 3602 |
base8, |
| 3603 |
len8 * (3 * ::core::mem::size_of::<*const u8>()), |
| 3604 |
::core::mem::size_of::<*const u8>(), |
| 3605 |
); |
| 3606 |
let result9 = result8; |
| 3607 |
result9 |
| 3608 |
} |
| 3609 |
} |
| 3610 |
} |
| 3611 |
} |
| 3612 |
pub mod io { |
| 3613 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 3614 |
pub mod error { |
| 3615 |
#[used] |
| 3616 |
#[doc(hidden)] |
| 3617 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 3618 |
use super::super::super::_rt; |
| 3619 |
/// A resource which represents some error information. |
| 3620 |
/// |
| 3621 |
/// The only method provided by this resource is `to-debug-string`, |
| 3622 |
/// which provides some human-readable information about the error. |
| 3623 |
/// |
| 3624 |
/// In the `wasi:io` package, this resource is returned through the |
| 3625 |
/// `wasi:io/streams/stream-error` type. |
| 3626 |
/// |
| 3627 |
/// To provide more specific error information, other interfaces may |
| 3628 |
/// offer functions to "downcast" this error into more specific types. For example, |
| 3629 |
/// errors returned from streams derived from filesystem types can be described using |
| 3630 |
/// the filesystem's own error-code type. This is done using the function |
| 3631 |
/// `wasi:filesystem/types/filesystem-error-code`, which takes a `borrow<error>` |
| 3632 |
/// parameter and returns an `option<wasi:filesystem/types/error-code>`. |
| 3633 |
/// |
| 3634 |
/// The set of functions which can "downcast" an `error` into a more |
| 3635 |
/// concrete type is open. |
| 3636 |
#[derive(Debug)] |
| 3637 |
#[repr(transparent)] |
| 3638 |
pub struct Error { |
| 3639 |
handle: _rt::Resource<Error>, |
| 3640 |
} |
| 3641 |
impl Error { |
| 3642 |
#[doc(hidden)] |
| 3643 |
pub unsafe fn from_handle(handle: u32) -> Self { |
| 3644 |
Self { |
| 3645 |
handle: unsafe { _rt::Resource::from_handle(handle) }, |
| 3646 |
} |
| 3647 |
} |
| 3648 |
#[doc(hidden)] |
| 3649 |
pub fn take_handle(&self) -> u32 { |
| 3650 |
_rt::Resource::take_handle(&self.handle) |
| 3651 |
} |
| 3652 |
#[doc(hidden)] |
| 3653 |
pub fn handle(&self) -> u32 { |
| 3654 |
_rt::Resource::handle(&self.handle) |
| 3655 |
} |
| 3656 |
} |
| 3657 |
unsafe impl _rt::WasmResource for Error { |
| 3658 |
#[inline] |
| 3659 |
unsafe fn drop(_handle: u32) { |
| 3660 |
#[cfg(target_arch = "wasm32")] |
| 3661 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 3662 |
unsafe extern "C" { |
| 3663 |
#[link_name = "[resource-drop]error"] |
| 3664 |
fn drop(_: i32); |
| 3665 |
} |
| 3666 |
#[cfg(not(target_arch = "wasm32"))] |
| 3667 |
unsafe extern "C" fn drop(_: i32) { |
| 3668 |
unreachable!() |
| 3669 |
} |
| 3670 |
unsafe { |
| 3671 |
drop(_handle as i32); |
| 3672 |
} |
| 3673 |
} |
| 3674 |
} |
| 3675 |
impl Error { |
| 3676 |
#[allow(unused_unsafe, clippy::all)] |
| 3677 |
/// Returns a string that is suitable to assist humans in debugging |
| 3678 |
/// this error. |
| 3679 |
/// |
| 3680 |
/// WARNING: The returned string should not be consumed mechanically! |
| 3681 |
/// It may change across platforms, hosts, or other implementation |
| 3682 |
/// details. Parsing this string is a major platform-compatibility |
| 3683 |
/// hazard. |
| 3684 |
#[allow(async_fn_in_trait)] |
| 3685 |
pub fn to_debug_string(&self) -> _rt::String { |
| 3686 |
unsafe { |
| 3687 |
#[cfg_attr(target_pointer_width = "64", repr(align(8)))] |
| 3688 |
#[cfg_attr(target_pointer_width = "32", repr(align(4)))] |
| 3689 |
struct RetArea( |
| 3690 |
[::core::mem::MaybeUninit< |
| 3691 |
u8, |
| 3692 |
>; 2 * ::core::mem::size_of::<*const u8>()], |
| 3693 |
); |
| 3694 |
let mut ret_area = RetArea( |
| 3695 |
[::core::mem::MaybeUninit::uninit(); 2 |
| 3696 |
* ::core::mem::size_of::<*const u8>()], |
| 3697 |
); |
| 3698 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 3699 |
#[cfg(target_arch = "wasm32")] |
| 3700 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 3701 |
unsafe extern "C" { |
| 3702 |
#[link_name = "[method]error.to-debug-string"] |
| 3703 |
fn wit_import1(_: i32, _: *mut u8); |
| 3704 |
} |
| 3705 |
#[cfg(not(target_arch = "wasm32"))] |
| 3706 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 3707 |
unreachable!() |
| 3708 |
} |
| 3709 |
wit_import1((self).handle() as i32, ptr0); |
| 3710 |
let l2 = *ptr0.add(0).cast::<*mut u8>(); |
| 3711 |
let l3 = *ptr0 |
| 3712 |
.add(::core::mem::size_of::<*const u8>()) |
| 3713 |
.cast::<usize>(); |
| 3714 |
let len4 = l3; |
| 3715 |
let bytes4 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4); |
| 3716 |
let result5 = _rt::string_lift(bytes4); |
| 3717 |
result5 |
| 3718 |
} |
| 3719 |
} |
| 3720 |
} |
| 3721 |
} |
| 3722 |
/// A poll API intended to let users wait for I/O events on multiple handles |
| 3723 |
/// at once. |
| 3724 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 3725 |
pub mod poll { |
| 3726 |
#[used] |
| 3727 |
#[doc(hidden)] |
| 3728 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 3729 |
use super::super::super::_rt; |
| 3730 |
/// `pollable` represents a single I/O event which may be ready, or not. |
| 3731 |
#[derive(Debug)] |
| 3732 |
#[repr(transparent)] |
| 3733 |
pub struct Pollable { |
| 3734 |
handle: _rt::Resource<Pollable>, |
| 3735 |
} |
| 3736 |
impl Pollable { |
| 3737 |
#[doc(hidden)] |
| 3738 |
pub unsafe fn from_handle(handle: u32) -> Self { |
| 3739 |
Self { |
| 3740 |
handle: unsafe { _rt::Resource::from_handle(handle) }, |
| 3741 |
} |
| 3742 |
} |
| 3743 |
#[doc(hidden)] |
| 3744 |
pub fn take_handle(&self) -> u32 { |
| 3745 |
_rt::Resource::take_handle(&self.handle) |
| 3746 |
} |
| 3747 |
#[doc(hidden)] |
| 3748 |
pub fn handle(&self) -> u32 { |
| 3749 |
_rt::Resource::handle(&self.handle) |
| 3750 |
} |
| 3751 |
} |
| 3752 |
unsafe impl _rt::WasmResource for Pollable { |
| 3753 |
#[inline] |
| 3754 |
unsafe fn drop(_handle: u32) { |
| 3755 |
#[cfg(target_arch = "wasm32")] |
| 3756 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 3757 |
unsafe extern "C" { |
| 3758 |
#[link_name = "[resource-drop]pollable"] |
| 3759 |
fn drop(_: i32); |
| 3760 |
} |
| 3761 |
#[cfg(not(target_arch = "wasm32"))] |
| 3762 |
unsafe extern "C" fn drop(_: i32) { |
| 3763 |
unreachable!() |
| 3764 |
} |
| 3765 |
unsafe { |
| 3766 |
drop(_handle as i32); |
| 3767 |
} |
| 3768 |
} |
| 3769 |
} |
| 3770 |
impl Pollable { |
| 3771 |
#[allow(unused_unsafe, clippy::all)] |
| 3772 |
/// Return the readiness of a pollable. This function never blocks. |
| 3773 |
/// |
| 3774 |
/// Returns `true` when the pollable is ready, and `false` otherwise. |
| 3775 |
#[allow(async_fn_in_trait)] |
| 3776 |
pub fn ready(&self) -> bool { |
| 3777 |
unsafe { |
| 3778 |
#[cfg(target_arch = "wasm32")] |
| 3779 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 3780 |
unsafe extern "C" { |
| 3781 |
#[link_name = "[method]pollable.ready"] |
| 3782 |
fn wit_import0(_: i32) -> i32; |
| 3783 |
} |
| 3784 |
#[cfg(not(target_arch = "wasm32"))] |
| 3785 |
unsafe extern "C" fn wit_import0(_: i32) -> i32 { |
| 3786 |
unreachable!() |
| 3787 |
} |
| 3788 |
let ret = wit_import0((self).handle() as i32); |
| 3789 |
_rt::bool_lift(ret as u8) |
| 3790 |
} |
| 3791 |
} |
| 3792 |
} |
| 3793 |
impl Pollable { |
| 3794 |
#[allow(unused_unsafe, clippy::all)] |
| 3795 |
/// `block` returns immediately if the pollable is ready, and otherwise |
| 3796 |
/// blocks until ready. |
| 3797 |
/// |
| 3798 |
/// This function is equivalent to calling `poll.poll` on a list |
| 3799 |
/// containing only this pollable. |
| 3800 |
#[allow(async_fn_in_trait)] |
| 3801 |
pub fn block(&self) -> () { |
| 3802 |
unsafe { |
| 3803 |
#[cfg(target_arch = "wasm32")] |
| 3804 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 3805 |
unsafe extern "C" { |
| 3806 |
#[link_name = "[method]pollable.block"] |
| 3807 |
fn wit_import0(_: i32); |
| 3808 |
} |
| 3809 |
#[cfg(not(target_arch = "wasm32"))] |
| 3810 |
unsafe extern "C" fn wit_import0(_: i32) { |
| 3811 |
unreachable!() |
| 3812 |
} |
| 3813 |
wit_import0((self).handle() as i32); |
| 3814 |
} |
| 3815 |
} |
| 3816 |
} |
| 3817 |
#[allow(unused_unsafe, clippy::all)] |
| 3818 |
/// Poll for completion on a set of pollables. |
| 3819 |
/// |
| 3820 |
/// This function takes a list of pollables, which identify I/O sources of |
| 3821 |
/// interest, and waits until one or more of the events is ready for I/O. |
| 3822 |
/// |
| 3823 |
/// The result `list<u32>` contains one or more indices of handles in the |
| 3824 |
/// argument list that is ready for I/O. |
| 3825 |
/// |
| 3826 |
/// This function traps if either: |
| 3827 |
/// - the list is empty, or: |
| 3828 |
/// - the list contains more elements than can be indexed with a `u32` value. |
| 3829 |
/// |
| 3830 |
/// A timeout can be implemented by adding a pollable from the |
| 3831 |
/// wasi-clocks API to the list. |
| 3832 |
/// |
| 3833 |
/// This function does not return a `result`; polling in itself does not |
| 3834 |
/// do any I/O so it doesn't fail. If any of the I/O sources identified by |
| 3835 |
/// the pollables has an error, it is indicated by marking the source as |
| 3836 |
/// being ready for I/O. |
| 3837 |
#[allow(async_fn_in_trait)] |
| 3838 |
pub fn poll(in_: &[&Pollable]) -> _rt::Vec<u32> { |
| 3839 |
unsafe { |
| 3840 |
#[cfg_attr(target_pointer_width = "64", repr(align(8)))] |
| 3841 |
#[cfg_attr(target_pointer_width = "32", repr(align(4)))] |
| 3842 |
struct RetArea( |
| 3843 |
[::core::mem::MaybeUninit< |
| 3844 |
u8, |
| 3845 |
>; 2 * ::core::mem::size_of::<*const u8>()], |
| 3846 |
); |
| 3847 |
let mut ret_area = RetArea( |
| 3848 |
[::core::mem::MaybeUninit::uninit(); 2 |
| 3849 |
* ::core::mem::size_of::<*const u8>()], |
| 3850 |
); |
| 3851 |
let vec0 = in_; |
| 3852 |
let len0 = vec0.len(); |
| 3853 |
let layout0 = _rt::alloc::Layout::from_size_align(vec0.len() * 4, 4) |
| 3854 |
.unwrap(); |
| 3855 |
let (result0, _cleanup0) = wit_bindgen::rt::Cleanup::new(layout0); |
| 3856 |
for (i, e) in vec0.into_iter().enumerate() { |
| 3857 |
let base = result0.add(i * 4); |
| 3858 |
{ |
| 3859 |
*base.add(0).cast::<i32>() = (e).handle() as i32; |
| 3860 |
} |
| 3861 |
} |
| 3862 |
let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 3863 |
#[cfg(target_arch = "wasm32")] |
| 3864 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 3865 |
unsafe extern "C" { |
| 3866 |
#[link_name = "poll"] |
| 3867 |
fn wit_import2(_: *mut u8, _: usize, _: *mut u8); |
| 3868 |
} |
| 3869 |
#[cfg(not(target_arch = "wasm32"))] |
| 3870 |
unsafe extern "C" fn wit_import2(_: *mut u8, _: usize, _: *mut u8) { |
| 3871 |
unreachable!() |
| 3872 |
} |
| 3873 |
wit_import2(result0, len0, ptr1); |
| 3874 |
let l3 = *ptr1.add(0).cast::<*mut u8>(); |
| 3875 |
let l4 = *ptr1 |
| 3876 |
.add(::core::mem::size_of::<*const u8>()) |
| 3877 |
.cast::<usize>(); |
| 3878 |
let len5 = l4; |
| 3879 |
let result6 = _rt::Vec::from_raw_parts(l3.cast(), len5, len5); |
| 3880 |
result6 |
| 3881 |
} |
| 3882 |
} |
| 3883 |
} |
| 3884 |
/// WASI I/O is an I/O abstraction API which is currently focused on providing |
| 3885 |
/// stream types. |
| 3886 |
/// |
| 3887 |
/// In the future, the component model is expected to add built-in stream types; |
| 3888 |
/// when it does, they are expected to subsume this API. |
| 3889 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 3890 |
pub mod streams { |
| 3891 |
#[used] |
| 3892 |
#[doc(hidden)] |
| 3893 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 3894 |
use super::super::super::_rt; |
| 3895 |
pub type Error = super::super::super::wasi::io::error::Error; |
| 3896 |
pub type Pollable = super::super::super::wasi::io::poll::Pollable; |
| 3897 |
/// An error for input-stream and output-stream operations. |
| 3898 |
pub enum StreamError { |
| 3899 |
/// The last operation (a write or flush) failed before completion. |
| 3900 |
/// |
| 3901 |
/// More information is available in the `error` payload. |
| 3902 |
/// |
| 3903 |
/// After this, the stream will be closed. All future operations return |
| 3904 |
/// `stream-error::closed`. |
| 3905 |
LastOperationFailed(Error), |
| 3906 |
/// The stream is closed: no more input will be accepted by the |
| 3907 |
/// stream. A closed output-stream will return this error on all |
| 3908 |
/// future operations. |
| 3909 |
Closed, |
| 3910 |
} |
| 3911 |
impl ::core::fmt::Debug for StreamError { |
| 3912 |
fn fmt( |
| 3913 |
&self, |
| 3914 |
f: &mut ::core::fmt::Formatter<'_>, |
| 3915 |
) -> ::core::fmt::Result { |
| 3916 |
match self { |
| 3917 |
StreamError::LastOperationFailed(e) => { |
| 3918 |
f.debug_tuple("StreamError::LastOperationFailed") |
| 3919 |
.field(e) |
| 3920 |
.finish() |
| 3921 |
} |
| 3922 |
StreamError::Closed => { |
| 3923 |
f.debug_tuple("StreamError::Closed").finish() |
| 3924 |
} |
| 3925 |
} |
| 3926 |
} |
| 3927 |
} |
| 3928 |
impl ::core::fmt::Display for StreamError { |
| 3929 |
fn fmt( |
| 3930 |
&self, |
| 3931 |
f: &mut ::core::fmt::Formatter<'_>, |
| 3932 |
) -> ::core::fmt::Result { |
| 3933 |
write!(f, "{:?}", self) |
| 3934 |
} |
| 3935 |
} |
| 3936 |
#[cfg(feature = "std")] |
| 3937 |
impl std::error::Error for StreamError {} |
| 3938 |
/// An input bytestream. |
| 3939 |
/// |
| 3940 |
/// `input-stream`s are *non-blocking* to the extent practical on underlying |
| 3941 |
/// platforms. I/O operations always return promptly; if fewer bytes are |
| 3942 |
/// promptly available than requested, they return the number of bytes promptly |
| 3943 |
/// available, which could even be zero. To wait for data to be available, |
| 3944 |
/// use the `subscribe` function to obtain a `pollable` which can be polled |
| 3945 |
/// for using `wasi:io/poll`. |
| 3946 |
#[derive(Debug)] |
| 3947 |
#[repr(transparent)] |
| 3948 |
pub struct InputStream { |
| 3949 |
handle: _rt::Resource<InputStream>, |
| 3950 |
} |
| 3951 |
impl InputStream { |
| 3952 |
#[doc(hidden)] |
| 3953 |
pub unsafe fn from_handle(handle: u32) -> Self { |
| 3954 |
Self { |
| 3955 |
handle: unsafe { _rt::Resource::from_handle(handle) }, |
| 3956 |
} |
| 3957 |
} |
| 3958 |
#[doc(hidden)] |
| 3959 |
pub fn take_handle(&self) -> u32 { |
| 3960 |
_rt::Resource::take_handle(&self.handle) |
| 3961 |
} |
| 3962 |
#[doc(hidden)] |
| 3963 |
pub fn handle(&self) -> u32 { |
| 3964 |
_rt::Resource::handle(&self.handle) |
| 3965 |
} |
| 3966 |
} |
| 3967 |
unsafe impl _rt::WasmResource for InputStream { |
| 3968 |
#[inline] |
| 3969 |
unsafe fn drop(_handle: u32) { |
| 3970 |
#[cfg(target_arch = "wasm32")] |
| 3971 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 3972 |
unsafe extern "C" { |
| 3973 |
#[link_name = "[resource-drop]input-stream"] |
| 3974 |
fn drop(_: i32); |
| 3975 |
} |
| 3976 |
#[cfg(not(target_arch = "wasm32"))] |
| 3977 |
unsafe extern "C" fn drop(_: i32) { |
| 3978 |
unreachable!() |
| 3979 |
} |
| 3980 |
unsafe { |
| 3981 |
drop(_handle as i32); |
| 3982 |
} |
| 3983 |
} |
| 3984 |
} |
| 3985 |
/// An output bytestream. |
| 3986 |
/// |
| 3987 |
/// `output-stream`s are *non-blocking* to the extent practical on |
| 3988 |
/// underlying platforms. Except where specified otherwise, I/O operations also |
| 3989 |
/// always return promptly, after the number of bytes that can be written |
| 3990 |
/// promptly, which could even be zero. To wait for the stream to be ready to |
| 3991 |
/// accept data, the `subscribe` function to obtain a `pollable` which can be |
| 3992 |
/// polled for using `wasi:io/poll`. |
| 3993 |
/// |
| 3994 |
/// Dropping an `output-stream` while there's still an active write in |
| 3995 |
/// progress may result in the data being lost. Before dropping the stream, |
| 3996 |
/// be sure to fully flush your writes. |
| 3997 |
#[derive(Debug)] |
| 3998 |
#[repr(transparent)] |
| 3999 |
pub struct OutputStream { |
| 4000 |
handle: _rt::Resource<OutputStream>, |
| 4001 |
} |
| 4002 |
impl OutputStream { |
| 4003 |
#[doc(hidden)] |
| 4004 |
pub unsafe fn from_handle(handle: u32) -> Self { |
| 4005 |
Self { |
| 4006 |
handle: unsafe { _rt::Resource::from_handle(handle) }, |
| 4007 |
} |
| 4008 |
} |
| 4009 |
#[doc(hidden)] |
| 4010 |
pub fn take_handle(&self) -> u32 { |
| 4011 |
_rt::Resource::take_handle(&self.handle) |
| 4012 |
} |
| 4013 |
#[doc(hidden)] |
| 4014 |
pub fn handle(&self) -> u32 { |
| 4015 |
_rt::Resource::handle(&self.handle) |
| 4016 |
} |
| 4017 |
} |
| 4018 |
unsafe impl _rt::WasmResource for OutputStream { |
| 4019 |
#[inline] |
| 4020 |
unsafe fn drop(_handle: u32) { |
| 4021 |
#[cfg(target_arch = "wasm32")] |
| 4022 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 4023 |
unsafe extern "C" { |
| 4024 |
#[link_name = "[resource-drop]output-stream"] |
| 4025 |
fn drop(_: i32); |
| 4026 |
} |
| 4027 |
#[cfg(not(target_arch = "wasm32"))] |
| 4028 |
unsafe extern "C" fn drop(_: i32) { |
| 4029 |
unreachable!() |
| 4030 |
} |
| 4031 |
unsafe { |
| 4032 |
drop(_handle as i32); |
| 4033 |
} |
| 4034 |
} |
| 4035 |
} |
| 4036 |
impl InputStream { |
| 4037 |
#[allow(unused_unsafe, clippy::all)] |
| 4038 |
/// Perform a non-blocking read from the stream. |
| 4039 |
/// |
| 4040 |
/// When the source of a `read` is binary data, the bytes from the source |
| 4041 |
/// are returned verbatim. When the source of a `read` is known to the |
| 4042 |
/// implementation to be text, bytes containing the UTF-8 encoding of the |
| 4043 |
/// text are returned. |
| 4044 |
/// |
| 4045 |
/// This function returns a list of bytes containing the read data, |
| 4046 |
/// when successful. The returned list will contain up to `len` bytes; |
| 4047 |
/// it may return fewer than requested, but not more. The list is |
| 4048 |
/// empty when no bytes are available for reading at this time. The |
| 4049 |
/// pollable given by `subscribe` will be ready when more bytes are |
| 4050 |
/// available. |
| 4051 |
/// |
| 4052 |
/// This function fails with a `stream-error` when the operation |
| 4053 |
/// encounters an error, giving `last-operation-failed`, or when the |
| 4054 |
/// stream is closed, giving `closed`. |
| 4055 |
/// |
| 4056 |
/// When the caller gives a `len` of 0, it represents a request to |
| 4057 |
/// read 0 bytes. If the stream is still open, this call should |
| 4058 |
/// succeed and return an empty list, or otherwise fail with `closed`. |
| 4059 |
/// |
| 4060 |
/// The `len` parameter is a `u64`, which could represent a list of u8 which |
| 4061 |
/// is not possible to allocate in wasm32, or not desirable to allocate as |
| 4062 |
/// as a return value by the callee. The callee may return a list of bytes |
| 4063 |
/// less than `len` in size while more bytes are available for reading. |
| 4064 |
#[allow(async_fn_in_trait)] |
| 4065 |
pub fn read(&self, len: u64) -> Result<_rt::Vec<u8>, StreamError> { |
| 4066 |
unsafe { |
| 4067 |
#[cfg_attr(target_pointer_width = "64", repr(align(8)))] |
| 4068 |
#[cfg_attr(target_pointer_width = "32", repr(align(4)))] |
| 4069 |
struct RetArea( |
| 4070 |
[::core::mem::MaybeUninit< |
| 4071 |
u8, |
| 4072 |
>; 3 * ::core::mem::size_of::<*const u8>()], |
| 4073 |
); |
| 4074 |
let mut ret_area = RetArea( |
| 4075 |
[::core::mem::MaybeUninit::uninit(); 3 |
| 4076 |
* ::core::mem::size_of::<*const u8>()], |
| 4077 |
); |
| 4078 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 4079 |
#[cfg(target_arch = "wasm32")] |
| 4080 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 4081 |
unsafe extern "C" { |
| 4082 |
#[link_name = "[method]input-stream.read"] |
| 4083 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 4084 |
} |
| 4085 |
#[cfg(not(target_arch = "wasm32"))] |
| 4086 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 4087 |
unreachable!() |
| 4088 |
} |
| 4089 |
wit_import1((self).handle() as i32, _rt::as_i64(&len), ptr0); |
| 4090 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 4091 |
let result9 = match l2 { |
| 4092 |
0 => { |
| 4093 |
let e = { |
| 4094 |
let l3 = *ptr0 |
| 4095 |
.add(::core::mem::size_of::<*const u8>()) |
| 4096 |
.cast::<*mut u8>(); |
| 4097 |
let l4 = *ptr0 |
| 4098 |
.add(2 * ::core::mem::size_of::<*const u8>()) |
| 4099 |
.cast::<usize>(); |
| 4100 |
let len5 = l4; |
| 4101 |
_rt::Vec::from_raw_parts(l3.cast(), len5, len5) |
| 4102 |
}; |
| 4103 |
Ok(e) |
| 4104 |
} |
| 4105 |
1 => { |
| 4106 |
let e = { |
| 4107 |
let l6 = i32::from( |
| 4108 |
*ptr0.add(::core::mem::size_of::<*const u8>()).cast::<u8>(), |
| 4109 |
); |
| 4110 |
let v8 = match l6 { |
| 4111 |
0 => { |
| 4112 |
let e8 = { |
| 4113 |
let l7 = *ptr0 |
| 4114 |
.add(4 + 1 * ::core::mem::size_of::<*const u8>()) |
| 4115 |
.cast::<i32>(); |
| 4116 |
super::super::super::wasi::io::error::Error::from_handle( |
| 4117 |
l7 as u32, |
| 4118 |
) |
| 4119 |
}; |
| 4120 |
StreamError::LastOperationFailed(e8) |
| 4121 |
} |
| 4122 |
n => { |
| 4123 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 4124 |
StreamError::Closed |
| 4125 |
} |
| 4126 |
}; |
| 4127 |
v8 |
| 4128 |
}; |
| 4129 |
Err(e) |
| 4130 |
} |
| 4131 |
_ => _rt::invalid_enum_discriminant(), |
| 4132 |
}; |
| 4133 |
result9 |
| 4134 |
} |
| 4135 |
} |
| 4136 |
} |
| 4137 |
impl InputStream { |
| 4138 |
#[allow(unused_unsafe, clippy::all)] |
| 4139 |
/// Read bytes from a stream, after blocking until at least one byte can |
| 4140 |
/// be read. Except for blocking, behavior is identical to `read`. |
| 4141 |
#[allow(async_fn_in_trait)] |
| 4142 |
pub fn blocking_read( |
| 4143 |
&self, |
| 4144 |
len: u64, |
| 4145 |
) -> Result<_rt::Vec<u8>, StreamError> { |
| 4146 |
unsafe { |
| 4147 |
#[cfg_attr(target_pointer_width = "64", repr(align(8)))] |
| 4148 |
#[cfg_attr(target_pointer_width = "32", repr(align(4)))] |
| 4149 |
struct RetArea( |
| 4150 |
[::core::mem::MaybeUninit< |
| 4151 |
u8, |
| 4152 |
>; 3 * ::core::mem::size_of::<*const u8>()], |
| 4153 |
); |
| 4154 |
let mut ret_area = RetArea( |
| 4155 |
[::core::mem::MaybeUninit::uninit(); 3 |
| 4156 |
* ::core::mem::size_of::<*const u8>()], |
| 4157 |
); |
| 4158 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 4159 |
#[cfg(target_arch = "wasm32")] |
| 4160 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 4161 |
unsafe extern "C" { |
| 4162 |
#[link_name = "[method]input-stream.blocking-read"] |
| 4163 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 4164 |
} |
| 4165 |
#[cfg(not(target_arch = "wasm32"))] |
| 4166 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 4167 |
unreachable!() |
| 4168 |
} |
| 4169 |
wit_import1((self).handle() as i32, _rt::as_i64(&len), ptr0); |
| 4170 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 4171 |
let result9 = match l2 { |
| 4172 |
0 => { |
| 4173 |
let e = { |
| 4174 |
let l3 = *ptr0 |
| 4175 |
.add(::core::mem::size_of::<*const u8>()) |
| 4176 |
.cast::<*mut u8>(); |
| 4177 |
let l4 = *ptr0 |
| 4178 |
.add(2 * ::core::mem::size_of::<*const u8>()) |
| 4179 |
.cast::<usize>(); |
| 4180 |
let len5 = l4; |
| 4181 |
_rt::Vec::from_raw_parts(l3.cast(), len5, len5) |
| 4182 |
}; |
| 4183 |
Ok(e) |
| 4184 |
} |
| 4185 |
1 => { |
| 4186 |
let e = { |
| 4187 |
let l6 = i32::from( |
| 4188 |
*ptr0.add(::core::mem::size_of::<*const u8>()).cast::<u8>(), |
| 4189 |
); |
| 4190 |
let v8 = match l6 { |
| 4191 |
0 => { |
| 4192 |
let e8 = { |
| 4193 |
let l7 = *ptr0 |
| 4194 |
.add(4 + 1 * ::core::mem::size_of::<*const u8>()) |
| 4195 |
.cast::<i32>(); |
| 4196 |
super::super::super::wasi::io::error::Error::from_handle( |
| 4197 |
l7 as u32, |
| 4198 |
) |
| 4199 |
}; |
| 4200 |
StreamError::LastOperationFailed(e8) |
| 4201 |
} |
| 4202 |
n => { |
| 4203 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 4204 |
StreamError::Closed |
| 4205 |
} |
| 4206 |
}; |
| 4207 |
v8 |
| 4208 |
}; |
| 4209 |
Err(e) |
| 4210 |
} |
| 4211 |
_ => _rt::invalid_enum_discriminant(), |
| 4212 |
}; |
| 4213 |
result9 |
| 4214 |
} |
| 4215 |
} |
| 4216 |
} |
| 4217 |
impl InputStream { |
| 4218 |
#[allow(unused_unsafe, clippy::all)] |
| 4219 |
/// Skip bytes from a stream. Returns number of bytes skipped. |
| 4220 |
/// |
| 4221 |
/// Behaves identical to `read`, except instead of returning a list |
| 4222 |
/// of bytes, returns the number of bytes consumed from the stream. |
| 4223 |
#[allow(async_fn_in_trait)] |
| 4224 |
pub fn skip(&self, len: u64) -> Result<u64, StreamError> { |
| 4225 |
unsafe { |
| 4226 |
#[repr(align(8))] |
| 4227 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 4228 |
let mut ret_area = RetArea( |
| 4229 |
[::core::mem::MaybeUninit::uninit(); 16], |
| 4230 |
); |
| 4231 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 4232 |
#[cfg(target_arch = "wasm32")] |
| 4233 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 4234 |
unsafe extern "C" { |
| 4235 |
#[link_name = "[method]input-stream.skip"] |
| 4236 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 4237 |
} |
| 4238 |
#[cfg(not(target_arch = "wasm32"))] |
| 4239 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 4240 |
unreachable!() |
| 4241 |
} |
| 4242 |
wit_import1((self).handle() as i32, _rt::as_i64(&len), ptr0); |
| 4243 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 4244 |
let result7 = match l2 { |
| 4245 |
0 => { |
| 4246 |
let e = { |
| 4247 |
let l3 = *ptr0.add(8).cast::<i64>(); |
| 4248 |
l3 as u64 |
| 4249 |
}; |
| 4250 |
Ok(e) |
| 4251 |
} |
| 4252 |
1 => { |
| 4253 |
let e = { |
| 4254 |
let l4 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 4255 |
let v6 = match l4 { |
| 4256 |
0 => { |
| 4257 |
let e6 = { |
| 4258 |
let l5 = *ptr0.add(12).cast::<i32>(); |
| 4259 |
super::super::super::wasi::io::error::Error::from_handle( |
| 4260 |
l5 as u32, |
| 4261 |
) |
| 4262 |
}; |
| 4263 |
StreamError::LastOperationFailed(e6) |
| 4264 |
} |
| 4265 |
n => { |
| 4266 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 4267 |
StreamError::Closed |
| 4268 |
} |
| 4269 |
}; |
| 4270 |
v6 |
| 4271 |
}; |
| 4272 |
Err(e) |
| 4273 |
} |
| 4274 |
_ => _rt::invalid_enum_discriminant(), |
| 4275 |
}; |
| 4276 |
result7 |
| 4277 |
} |
| 4278 |
} |
| 4279 |
} |
| 4280 |
impl InputStream { |
| 4281 |
#[allow(unused_unsafe, clippy::all)] |
| 4282 |
/// Skip bytes from a stream, after blocking until at least one byte |
| 4283 |
/// can be skipped. Except for blocking behavior, identical to `skip`. |
| 4284 |
#[allow(async_fn_in_trait)] |
| 4285 |
pub fn blocking_skip(&self, len: u64) -> Result<u64, StreamError> { |
| 4286 |
unsafe { |
| 4287 |
#[repr(align(8))] |
| 4288 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 4289 |
let mut ret_area = RetArea( |
| 4290 |
[::core::mem::MaybeUninit::uninit(); 16], |
| 4291 |
); |
| 4292 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 4293 |
#[cfg(target_arch = "wasm32")] |
| 4294 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 4295 |
unsafe extern "C" { |
| 4296 |
#[link_name = "[method]input-stream.blocking-skip"] |
| 4297 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 4298 |
} |
| 4299 |
#[cfg(not(target_arch = "wasm32"))] |
| 4300 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 4301 |
unreachable!() |
| 4302 |
} |
| 4303 |
wit_import1((self).handle() as i32, _rt::as_i64(&len), ptr0); |
| 4304 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 4305 |
let result7 = match l2 { |
| 4306 |
0 => { |
| 4307 |
let e = { |
| 4308 |
let l3 = *ptr0.add(8).cast::<i64>(); |
| 4309 |
l3 as u64 |
| 4310 |
}; |
| 4311 |
Ok(e) |
| 4312 |
} |
| 4313 |
1 => { |
| 4314 |
let e = { |
| 4315 |
let l4 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 4316 |
let v6 = match l4 { |
| 4317 |
0 => { |
| 4318 |
let e6 = { |
| 4319 |
let l5 = *ptr0.add(12).cast::<i32>(); |
| 4320 |
super::super::super::wasi::io::error::Error::from_handle( |
| 4321 |
l5 as u32, |
| 4322 |
) |
| 4323 |
}; |
| 4324 |
StreamError::LastOperationFailed(e6) |
| 4325 |
} |
| 4326 |
n => { |
| 4327 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 4328 |
StreamError::Closed |
| 4329 |
} |
| 4330 |
}; |
| 4331 |
v6 |
| 4332 |
}; |
| 4333 |
Err(e) |
| 4334 |
} |
| 4335 |
_ => _rt::invalid_enum_discriminant(), |
| 4336 |
}; |
| 4337 |
result7 |
| 4338 |
} |
| 4339 |
} |
| 4340 |
} |
| 4341 |
impl InputStream { |
| 4342 |
#[allow(unused_unsafe, clippy::all)] |
| 4343 |
/// Create a `pollable` which will resolve once either the specified stream |
| 4344 |
/// has bytes available to read or the other end of the stream has been |
| 4345 |
/// closed. |
| 4346 |
/// The created `pollable` is a child resource of the `input-stream`. |
| 4347 |
/// Implementations may trap if the `input-stream` is dropped before |
| 4348 |
/// all derived `pollable`s created with this function are dropped. |
| 4349 |
#[allow(async_fn_in_trait)] |
| 4350 |
pub fn subscribe(&self) -> Pollable { |
| 4351 |
unsafe { |
| 4352 |
#[cfg(target_arch = "wasm32")] |
| 4353 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 4354 |
unsafe extern "C" { |
| 4355 |
#[link_name = "[method]input-stream.subscribe"] |
| 4356 |
fn wit_import0(_: i32) -> i32; |
| 4357 |
} |
| 4358 |
#[cfg(not(target_arch = "wasm32"))] |
| 4359 |
unsafe extern "C" fn wit_import0(_: i32) -> i32 { |
| 4360 |
unreachable!() |
| 4361 |
} |
| 4362 |
let ret = wit_import0((self).handle() as i32); |
| 4363 |
super::super::super::wasi::io::poll::Pollable::from_handle( |
| 4364 |
ret as u32, |
| 4365 |
) |
| 4366 |
} |
| 4367 |
} |
| 4368 |
} |
| 4369 |
impl OutputStream { |
| 4370 |
#[allow(unused_unsafe, clippy::all)] |
| 4371 |
/// Check readiness for writing. This function never blocks. |
| 4372 |
/// |
| 4373 |
/// Returns the number of bytes permitted for the next call to `write`, |
| 4374 |
/// or an error. Calling `write` with more bytes than this function has |
| 4375 |
/// permitted will trap. |
| 4376 |
/// |
| 4377 |
/// When this function returns 0 bytes, the `subscribe` pollable will |
| 4378 |
/// become ready when this function will report at least 1 byte, or an |
| 4379 |
/// error. |
| 4380 |
#[allow(async_fn_in_trait)] |
| 4381 |
pub fn check_write(&self) -> Result<u64, StreamError> { |
| 4382 |
unsafe { |
| 4383 |
#[repr(align(8))] |
| 4384 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 4385 |
let mut ret_area = RetArea( |
| 4386 |
[::core::mem::MaybeUninit::uninit(); 16], |
| 4387 |
); |
| 4388 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 4389 |
#[cfg(target_arch = "wasm32")] |
| 4390 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 4391 |
unsafe extern "C" { |
| 4392 |
#[link_name = "[method]output-stream.check-write"] |
| 4393 |
fn wit_import1(_: i32, _: *mut u8); |
| 4394 |
} |
| 4395 |
#[cfg(not(target_arch = "wasm32"))] |
| 4396 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 4397 |
unreachable!() |
| 4398 |
} |
| 4399 |
wit_import1((self).handle() as i32, ptr0); |
| 4400 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 4401 |
let result7 = match l2 { |
| 4402 |
0 => { |
| 4403 |
let e = { |
| 4404 |
let l3 = *ptr0.add(8).cast::<i64>(); |
| 4405 |
l3 as u64 |
| 4406 |
}; |
| 4407 |
Ok(e) |
| 4408 |
} |
| 4409 |
1 => { |
| 4410 |
let e = { |
| 4411 |
let l4 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 4412 |
let v6 = match l4 { |
| 4413 |
0 => { |
| 4414 |
let e6 = { |
| 4415 |
let l5 = *ptr0.add(12).cast::<i32>(); |
| 4416 |
super::super::super::wasi::io::error::Error::from_handle( |
| 4417 |
l5 as u32, |
| 4418 |
) |
| 4419 |
}; |
| 4420 |
StreamError::LastOperationFailed(e6) |
| 4421 |
} |
| 4422 |
n => { |
| 4423 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 4424 |
StreamError::Closed |
| 4425 |
} |
| 4426 |
}; |
| 4427 |
v6 |
| 4428 |
}; |
| 4429 |
Err(e) |
| 4430 |
} |
| 4431 |
_ => _rt::invalid_enum_discriminant(), |
| 4432 |
}; |
| 4433 |
result7 |
| 4434 |
} |
| 4435 |
} |
| 4436 |
} |
| 4437 |
impl OutputStream { |
| 4438 |
#[allow(unused_unsafe, clippy::all)] |
| 4439 |
/// Perform a write. This function never blocks. |
| 4440 |
/// |
| 4441 |
/// When the destination of a `write` is binary data, the bytes from |
| 4442 |
/// `contents` are written verbatim. When the destination of a `write` is |
| 4443 |
/// known to the implementation to be text, the bytes of `contents` are |
| 4444 |
/// transcoded from UTF-8 into the encoding of the destination and then |
| 4445 |
/// written. |
| 4446 |
/// |
| 4447 |
/// Precondition: check-write gave permit of Ok(n) and contents has a |
| 4448 |
/// length of less than or equal to n. Otherwise, this function will trap. |
| 4449 |
/// |
| 4450 |
/// returns Err(closed) without writing if the stream has closed since |
| 4451 |
/// the last call to check-write provided a permit. |
| 4452 |
#[allow(async_fn_in_trait)] |
| 4453 |
pub fn write(&self, contents: &[u8]) -> Result<(), StreamError> { |
| 4454 |
unsafe { |
| 4455 |
#[repr(align(4))] |
| 4456 |
struct RetArea([::core::mem::MaybeUninit<u8>; 12]); |
| 4457 |
let mut ret_area = RetArea( |
| 4458 |
[::core::mem::MaybeUninit::uninit(); 12], |
| 4459 |
); |
| 4460 |
let vec0 = contents; |
| 4461 |
let ptr0 = vec0.as_ptr().cast::<u8>(); |
| 4462 |
let len0 = vec0.len(); |
| 4463 |
let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 4464 |
#[cfg(target_arch = "wasm32")] |
| 4465 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 4466 |
unsafe extern "C" { |
| 4467 |
#[link_name = "[method]output-stream.write"] |
| 4468 |
fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8); |
| 4469 |
} |
| 4470 |
#[cfg(not(target_arch = "wasm32"))] |
| 4471 |
unsafe extern "C" fn wit_import2( |
| 4472 |
_: i32, |
| 4473 |
_: *mut u8, |
| 4474 |
_: usize, |
| 4475 |
_: *mut u8, |
| 4476 |
) { |
| 4477 |
unreachable!() |
| 4478 |
} |
| 4479 |
wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1); |
| 4480 |
let l3 = i32::from(*ptr1.add(0).cast::<u8>()); |
| 4481 |
let result7 = match l3 { |
| 4482 |
0 => { |
| 4483 |
let e = (); |
| 4484 |
Ok(e) |
| 4485 |
} |
| 4486 |
1 => { |
| 4487 |
let e = { |
| 4488 |
let l4 = i32::from(*ptr1.add(4).cast::<u8>()); |
| 4489 |
let v6 = match l4 { |
| 4490 |
0 => { |
| 4491 |
let e6 = { |
| 4492 |
let l5 = *ptr1.add(8).cast::<i32>(); |
| 4493 |
super::super::super::wasi::io::error::Error::from_handle( |
| 4494 |
l5 as u32, |
| 4495 |
) |
| 4496 |
}; |
| 4497 |
StreamError::LastOperationFailed(e6) |
| 4498 |
} |
| 4499 |
n => { |
| 4500 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 4501 |
StreamError::Closed |
| 4502 |
} |
| 4503 |
}; |
| 4504 |
v6 |
| 4505 |
}; |
| 4506 |
Err(e) |
| 4507 |
} |
| 4508 |
_ => _rt::invalid_enum_discriminant(), |
| 4509 |
}; |
| 4510 |
result7 |
| 4511 |
} |
| 4512 |
} |
| 4513 |
} |
| 4514 |
impl OutputStream { |
| 4515 |
#[allow(unused_unsafe, clippy::all)] |
| 4516 |
/// Perform a write of up to 4096 bytes, and then flush the stream. Block |
| 4517 |
/// until all of these operations are complete, or an error occurs. |
| 4518 |
/// |
| 4519 |
/// This is a convenience wrapper around the use of `check-write`, |
| 4520 |
/// `subscribe`, `write`, and `flush`, and is implemented with the |
| 4521 |
/// following pseudo-code: |
| 4522 |
/// |
| 4523 |
/// ```text |
| 4524 |
/// let pollable = this.subscribe(); |
| 4525 |
/// while !contents.is_empty() { |
| 4526 |
/// // Wait for the stream to become writable |
| 4527 |
/// pollable.block(); |
| 4528 |
/// let Ok(n) = this.check-write(); // eliding error handling |
| 4529 |
/// let len = min(n, contents.len()); |
| 4530 |
/// let (chunk, rest) = contents.split_at(len); |
| 4531 |
/// this.write(chunk ); // eliding error handling |
| 4532 |
/// contents = rest; |
| 4533 |
/// } |
| 4534 |
/// this.flush(); |
| 4535 |
/// // Wait for completion of `flush` |
| 4536 |
/// pollable.block(); |
| 4537 |
/// // Check for any errors that arose during `flush` |
| 4538 |
/// let _ = this.check-write(); // eliding error handling |
| 4539 |
/// ``` |
| 4540 |
#[allow(async_fn_in_trait)] |
| 4541 |
pub fn blocking_write_and_flush( |
| 4542 |
&self, |
| 4543 |
contents: &[u8], |
| 4544 |
) -> Result<(), StreamError> { |
| 4545 |
unsafe { |
| 4546 |
#[repr(align(4))] |
| 4547 |
struct RetArea([::core::mem::MaybeUninit<u8>; 12]); |
| 4548 |
let mut ret_area = RetArea( |
| 4549 |
[::core::mem::MaybeUninit::uninit(); 12], |
| 4550 |
); |
| 4551 |
let vec0 = contents; |
| 4552 |
let ptr0 = vec0.as_ptr().cast::<u8>(); |
| 4553 |
let len0 = vec0.len(); |
| 4554 |
let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 4555 |
#[cfg(target_arch = "wasm32")] |
| 4556 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 4557 |
unsafe extern "C" { |
| 4558 |
#[link_name = "[method]output-stream.blocking-write-and-flush"] |
| 4559 |
fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8); |
| 4560 |
} |
| 4561 |
#[cfg(not(target_arch = "wasm32"))] |
| 4562 |
unsafe extern "C" fn wit_import2( |
| 4563 |
_: i32, |
| 4564 |
_: *mut u8, |
| 4565 |
_: usize, |
| 4566 |
_: *mut u8, |
| 4567 |
) { |
| 4568 |
unreachable!() |
| 4569 |
} |
| 4570 |
wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1); |
| 4571 |
let l3 = i32::from(*ptr1.add(0).cast::<u8>()); |
| 4572 |
let result7 = match l3 { |
| 4573 |
0 => { |
| 4574 |
let e = (); |
| 4575 |
Ok(e) |
| 4576 |
} |
| 4577 |
1 => { |
| 4578 |
let e = { |
| 4579 |
let l4 = i32::from(*ptr1.add(4).cast::<u8>()); |
| 4580 |
let v6 = match l4 { |
| 4581 |
0 => { |
| 4582 |
let e6 = { |
| 4583 |
let l5 = *ptr1.add(8).cast::<i32>(); |
| 4584 |
super::super::super::wasi::io::error::Error::from_handle( |
| 4585 |
l5 as u32, |
| 4586 |
) |
| 4587 |
}; |
| 4588 |
StreamError::LastOperationFailed(e6) |
| 4589 |
} |
| 4590 |
n => { |
| 4591 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 4592 |
StreamError::Closed |
| 4593 |
} |
| 4594 |
}; |
| 4595 |
v6 |
| 4596 |
}; |
| 4597 |
Err(e) |
| 4598 |
} |
| 4599 |
_ => _rt::invalid_enum_discriminant(), |
| 4600 |
}; |
| 4601 |
result7 |
| 4602 |
} |
| 4603 |
} |
| 4604 |
} |
| 4605 |
impl OutputStream { |
| 4606 |
#[allow(unused_unsafe, clippy::all)] |
| 4607 |
/// Request to flush buffered output. This function never blocks. |
| 4608 |
/// |
| 4609 |
/// This tells the output-stream that the caller intends any buffered |
| 4610 |
/// output to be flushed. the output which is expected to be flushed |
| 4611 |
/// is all that has been passed to `write` prior to this call. |
| 4612 |
/// |
| 4613 |
/// Upon calling this function, the `output-stream` will not accept any |
| 4614 |
/// writes (`check-write` will return `ok(0)`) until the flush has |
| 4615 |
/// completed. The `subscribe` pollable will become ready when the |
| 4616 |
/// flush has completed and the stream can accept more writes. |
| 4617 |
#[allow(async_fn_in_trait)] |
| 4618 |
pub fn flush(&self) -> Result<(), StreamError> { |
| 4619 |
unsafe { |
| 4620 |
#[repr(align(4))] |
| 4621 |
struct RetArea([::core::mem::MaybeUninit<u8>; 12]); |
| 4622 |
let mut ret_area = RetArea( |
| 4623 |
[::core::mem::MaybeUninit::uninit(); 12], |
| 4624 |
); |
| 4625 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 4626 |
#[cfg(target_arch = "wasm32")] |
| 4627 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 4628 |
unsafe extern "C" { |
| 4629 |
#[link_name = "[method]output-stream.flush"] |
| 4630 |
fn wit_import1(_: i32, _: *mut u8); |
| 4631 |
} |
| 4632 |
#[cfg(not(target_arch = "wasm32"))] |
| 4633 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 4634 |
unreachable!() |
| 4635 |
} |
| 4636 |
wit_import1((self).handle() as i32, ptr0); |
| 4637 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 4638 |
let result6 = match l2 { |
| 4639 |
0 => { |
| 4640 |
let e = (); |
| 4641 |
Ok(e) |
| 4642 |
} |
| 4643 |
1 => { |
| 4644 |
let e = { |
| 4645 |
let l3 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 4646 |
let v5 = match l3 { |
| 4647 |
0 => { |
| 4648 |
let e5 = { |
| 4649 |
let l4 = *ptr0.add(8).cast::<i32>(); |
| 4650 |
super::super::super::wasi::io::error::Error::from_handle( |
| 4651 |
l4 as u32, |
| 4652 |
) |
| 4653 |
}; |
| 4654 |
StreamError::LastOperationFailed(e5) |
| 4655 |
} |
| 4656 |
n => { |
| 4657 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 4658 |
StreamError::Closed |
| 4659 |
} |
| 4660 |
}; |
| 4661 |
v5 |
| 4662 |
}; |
| 4663 |
Err(e) |
| 4664 |
} |
| 4665 |
_ => _rt::invalid_enum_discriminant(), |
| 4666 |
}; |
| 4667 |
result6 |
| 4668 |
} |
| 4669 |
} |
| 4670 |
} |
| 4671 |
impl OutputStream { |
| 4672 |
#[allow(unused_unsafe, clippy::all)] |
| 4673 |
/// Request to flush buffered output, and block until flush completes |
| 4674 |
/// and stream is ready for writing again. |
| 4675 |
#[allow(async_fn_in_trait)] |
| 4676 |
pub fn blocking_flush(&self) -> Result<(), StreamError> { |
| 4677 |
unsafe { |
| 4678 |
#[repr(align(4))] |
| 4679 |
struct RetArea([::core::mem::MaybeUninit<u8>; 12]); |
| 4680 |
let mut ret_area = RetArea( |
| 4681 |
[::core::mem::MaybeUninit::uninit(); 12], |
| 4682 |
); |
| 4683 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 4684 |
#[cfg(target_arch = "wasm32")] |
| 4685 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 4686 |
unsafe extern "C" { |
| 4687 |
#[link_name = "[method]output-stream.blocking-flush"] |
| 4688 |
fn wit_import1(_: i32, _: *mut u8); |
| 4689 |
} |
| 4690 |
#[cfg(not(target_arch = "wasm32"))] |
| 4691 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 4692 |
unreachable!() |
| 4693 |
} |
| 4694 |
wit_import1((self).handle() as i32, ptr0); |
| 4695 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 4696 |
let result6 = match l2 { |
| 4697 |
0 => { |
| 4698 |
let e = (); |
| 4699 |
Ok(e) |
| 4700 |
} |
| 4701 |
1 => { |
| 4702 |
let e = { |
| 4703 |
let l3 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 4704 |
let v5 = match l3 { |
| 4705 |
0 => { |
| 4706 |
let e5 = { |
| 4707 |
let l4 = *ptr0.add(8).cast::<i32>(); |
| 4708 |
super::super::super::wasi::io::error::Error::from_handle( |
| 4709 |
l4 as u32, |
| 4710 |
) |
| 4711 |
}; |
| 4712 |
StreamError::LastOperationFailed(e5) |
| 4713 |
} |
| 4714 |
n => { |
| 4715 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 4716 |
StreamError::Closed |
| 4717 |
} |
| 4718 |
}; |
| 4719 |
v5 |
| 4720 |
}; |
| 4721 |
Err(e) |
| 4722 |
} |
| 4723 |
_ => _rt::invalid_enum_discriminant(), |
| 4724 |
}; |
| 4725 |
result6 |
| 4726 |
} |
| 4727 |
} |
| 4728 |
} |
| 4729 |
impl OutputStream { |
| 4730 |
#[allow(unused_unsafe, clippy::all)] |
| 4731 |
/// Create a `pollable` which will resolve once the output-stream |
| 4732 |
/// is ready for more writing, or an error has occurred. When this |
| 4733 |
/// pollable is ready, `check-write` will return `ok(n)` with n>0, or an |
| 4734 |
/// error. |
| 4735 |
/// |
| 4736 |
/// If the stream is closed, this pollable is always ready immediately. |
| 4737 |
/// |
| 4738 |
/// The created `pollable` is a child resource of the `output-stream`. |
| 4739 |
/// Implementations may trap if the `output-stream` is dropped before |
| 4740 |
/// all derived `pollable`s created with this function are dropped. |
| 4741 |
#[allow(async_fn_in_trait)] |
| 4742 |
pub fn subscribe(&self) -> Pollable { |
| 4743 |
unsafe { |
| 4744 |
#[cfg(target_arch = "wasm32")] |
| 4745 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 4746 |
unsafe extern "C" { |
| 4747 |
#[link_name = "[method]output-stream.subscribe"] |
| 4748 |
fn wit_import0(_: i32) -> i32; |
| 4749 |
} |
| 4750 |
#[cfg(not(target_arch = "wasm32"))] |
| 4751 |
unsafe extern "C" fn wit_import0(_: i32) -> i32 { |
| 4752 |
unreachable!() |
| 4753 |
} |
| 4754 |
let ret = wit_import0((self).handle() as i32); |
| 4755 |
super::super::super::wasi::io::poll::Pollable::from_handle( |
| 4756 |
ret as u32, |
| 4757 |
) |
| 4758 |
} |
| 4759 |
} |
| 4760 |
} |
| 4761 |
impl OutputStream { |
| 4762 |
#[allow(unused_unsafe, clippy::all)] |
| 4763 |
/// Write zeroes to a stream. |
| 4764 |
/// |
| 4765 |
/// This should be used precisely like `write` with the exact same |
| 4766 |
/// preconditions (must use check-write first), but instead of |
| 4767 |
/// passing a list of bytes, you simply pass the number of zero-bytes |
| 4768 |
/// that should be written. |
| 4769 |
#[allow(async_fn_in_trait)] |
| 4770 |
pub fn write_zeroes(&self, len: u64) -> Result<(), StreamError> { |
| 4771 |
unsafe { |
| 4772 |
#[repr(align(4))] |
| 4773 |
struct RetArea([::core::mem::MaybeUninit<u8>; 12]); |
| 4774 |
let mut ret_area = RetArea( |
| 4775 |
[::core::mem::MaybeUninit::uninit(); 12], |
| 4776 |
); |
| 4777 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 4778 |
#[cfg(target_arch = "wasm32")] |
| 4779 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 4780 |
unsafe extern "C" { |
| 4781 |
#[link_name = "[method]output-stream.write-zeroes"] |
| 4782 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 4783 |
} |
| 4784 |
#[cfg(not(target_arch = "wasm32"))] |
| 4785 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 4786 |
unreachable!() |
| 4787 |
} |
| 4788 |
wit_import1((self).handle() as i32, _rt::as_i64(&len), ptr0); |
| 4789 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 4790 |
let result6 = match l2 { |
| 4791 |
0 => { |
| 4792 |
let e = (); |
| 4793 |
Ok(e) |
| 4794 |
} |
| 4795 |
1 => { |
| 4796 |
let e = { |
| 4797 |
let l3 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 4798 |
let v5 = match l3 { |
| 4799 |
0 => { |
| 4800 |
let e5 = { |
| 4801 |
let l4 = *ptr0.add(8).cast::<i32>(); |
| 4802 |
super::super::super::wasi::io::error::Error::from_handle( |
| 4803 |
l4 as u32, |
| 4804 |
) |
| 4805 |
}; |
| 4806 |
StreamError::LastOperationFailed(e5) |
| 4807 |
} |
| 4808 |
n => { |
| 4809 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 4810 |
StreamError::Closed |
| 4811 |
} |
| 4812 |
}; |
| 4813 |
v5 |
| 4814 |
}; |
| 4815 |
Err(e) |
| 4816 |
} |
| 4817 |
_ => _rt::invalid_enum_discriminant(), |
| 4818 |
}; |
| 4819 |
result6 |
| 4820 |
} |
| 4821 |
} |
| 4822 |
} |
| 4823 |
impl OutputStream { |
| 4824 |
#[allow(unused_unsafe, clippy::all)] |
| 4825 |
/// Perform a write of up to 4096 zeroes, and then flush the stream. |
| 4826 |
/// Block until all of these operations are complete, or an error |
| 4827 |
/// occurs. |
| 4828 |
/// |
| 4829 |
/// This is a convenience wrapper around the use of `check-write`, |
| 4830 |
/// `subscribe`, `write-zeroes`, and `flush`, and is implemented with |
| 4831 |
/// the following pseudo-code: |
| 4832 |
/// |
| 4833 |
/// ```text |
| 4834 |
/// let pollable = this.subscribe(); |
| 4835 |
/// while num_zeroes != 0 { |
| 4836 |
/// // Wait for the stream to become writable |
| 4837 |
/// pollable.block(); |
| 4838 |
/// let Ok(n) = this.check-write(); // eliding error handling |
| 4839 |
/// let len = min(n, num_zeroes); |
| 4840 |
/// this.write-zeroes(len); // eliding error handling |
| 4841 |
/// num_zeroes -= len; |
| 4842 |
/// } |
| 4843 |
/// this.flush(); |
| 4844 |
/// // Wait for completion of `flush` |
| 4845 |
/// pollable.block(); |
| 4846 |
/// // Check for any errors that arose during `flush` |
| 4847 |
/// let _ = this.check-write(); // eliding error handling |
| 4848 |
/// ``` |
| 4849 |
#[allow(async_fn_in_trait)] |
| 4850 |
pub fn blocking_write_zeroes_and_flush( |
| 4851 |
&self, |
| 4852 |
len: u64, |
| 4853 |
) -> Result<(), StreamError> { |
| 4854 |
unsafe { |
| 4855 |
#[repr(align(4))] |
| 4856 |
struct RetArea([::core::mem::MaybeUninit<u8>; 12]); |
| 4857 |
let mut ret_area = RetArea( |
| 4858 |
[::core::mem::MaybeUninit::uninit(); 12], |
| 4859 |
); |
| 4860 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 4861 |
#[cfg(target_arch = "wasm32")] |
| 4862 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 4863 |
unsafe extern "C" { |
| 4864 |
#[link_name = "[method]output-stream.blocking-write-zeroes-and-flush"] |
| 4865 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 4866 |
} |
| 4867 |
#[cfg(not(target_arch = "wasm32"))] |
| 4868 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 4869 |
unreachable!() |
| 4870 |
} |
| 4871 |
wit_import1((self).handle() as i32, _rt::as_i64(&len), ptr0); |
| 4872 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 4873 |
let result6 = match l2 { |
| 4874 |
0 => { |
| 4875 |
let e = (); |
| 4876 |
Ok(e) |
| 4877 |
} |
| 4878 |
1 => { |
| 4879 |
let e = { |
| 4880 |
let l3 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 4881 |
let v5 = match l3 { |
| 4882 |
0 => { |
| 4883 |
let e5 = { |
| 4884 |
let l4 = *ptr0.add(8).cast::<i32>(); |
| 4885 |
super::super::super::wasi::io::error::Error::from_handle( |
| 4886 |
l4 as u32, |
| 4887 |
) |
| 4888 |
}; |
| 4889 |
StreamError::LastOperationFailed(e5) |
| 4890 |
} |
| 4891 |
n => { |
| 4892 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 4893 |
StreamError::Closed |
| 4894 |
} |
| 4895 |
}; |
| 4896 |
v5 |
| 4897 |
}; |
| 4898 |
Err(e) |
| 4899 |
} |
| 4900 |
_ => _rt::invalid_enum_discriminant(), |
| 4901 |
}; |
| 4902 |
result6 |
| 4903 |
} |
| 4904 |
} |
| 4905 |
} |
| 4906 |
impl OutputStream { |
| 4907 |
#[allow(unused_unsafe, clippy::all)] |
| 4908 |
/// Read from one stream and write to another. |
| 4909 |
/// |
| 4910 |
/// The behavior of splice is equivalent to: |
| 4911 |
/// 1. calling `check-write` on the `output-stream` |
| 4912 |
/// 2. calling `read` on the `input-stream` with the smaller of the |
| 4913 |
/// `check-write` permitted length and the `len` provided to `splice` |
| 4914 |
/// 3. calling `write` on the `output-stream` with that read data. |
| 4915 |
/// |
| 4916 |
/// Any error reported by the call to `check-write`, `read`, or |
| 4917 |
/// `write` ends the splice and reports that error. |
| 4918 |
/// |
| 4919 |
/// This function returns the number of bytes transferred; it may be less |
| 4920 |
/// than `len`. |
| 4921 |
#[allow(async_fn_in_trait)] |
| 4922 |
pub fn splice( |
| 4923 |
&self, |
| 4924 |
src: &InputStream, |
| 4925 |
len: u64, |
| 4926 |
) -> Result<u64, StreamError> { |
| 4927 |
unsafe { |
| 4928 |
#[repr(align(8))] |
| 4929 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 4930 |
let mut ret_area = RetArea( |
| 4931 |
[::core::mem::MaybeUninit::uninit(); 16], |
| 4932 |
); |
| 4933 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 4934 |
#[cfg(target_arch = "wasm32")] |
| 4935 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 4936 |
unsafe extern "C" { |
| 4937 |
#[link_name = "[method]output-stream.splice"] |
| 4938 |
fn wit_import1(_: i32, _: i32, _: i64, _: *mut u8); |
| 4939 |
} |
| 4940 |
#[cfg(not(target_arch = "wasm32"))] |
| 4941 |
unsafe extern "C" fn wit_import1( |
| 4942 |
_: i32, |
| 4943 |
_: i32, |
| 4944 |
_: i64, |
| 4945 |
_: *mut u8, |
| 4946 |
) { |
| 4947 |
unreachable!() |
| 4948 |
} |
| 4949 |
wit_import1( |
| 4950 |
(self).handle() as i32, |
| 4951 |
(src).handle() as i32, |
| 4952 |
_rt::as_i64(&len), |
| 4953 |
ptr0, |
| 4954 |
); |
| 4955 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 4956 |
let result7 = match l2 { |
| 4957 |
0 => { |
| 4958 |
let e = { |
| 4959 |
let l3 = *ptr0.add(8).cast::<i64>(); |
| 4960 |
l3 as u64 |
| 4961 |
}; |
| 4962 |
Ok(e) |
| 4963 |
} |
| 4964 |
1 => { |
| 4965 |
let e = { |
| 4966 |
let l4 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 4967 |
let v6 = match l4 { |
| 4968 |
0 => { |
| 4969 |
let e6 = { |
| 4970 |
let l5 = *ptr0.add(12).cast::<i32>(); |
| 4971 |
super::super::super::wasi::io::error::Error::from_handle( |
| 4972 |
l5 as u32, |
| 4973 |
) |
| 4974 |
}; |
| 4975 |
StreamError::LastOperationFailed(e6) |
| 4976 |
} |
| 4977 |
n => { |
| 4978 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 4979 |
StreamError::Closed |
| 4980 |
} |
| 4981 |
}; |
| 4982 |
v6 |
| 4983 |
}; |
| 4984 |
Err(e) |
| 4985 |
} |
| 4986 |
_ => _rt::invalid_enum_discriminant(), |
| 4987 |
}; |
| 4988 |
result7 |
| 4989 |
} |
| 4990 |
} |
| 4991 |
} |
| 4992 |
impl OutputStream { |
| 4993 |
#[allow(unused_unsafe, clippy::all)] |
| 4994 |
/// Read from one stream and write to another, with blocking. |
| 4995 |
/// |
| 4996 |
/// This is similar to `splice`, except that it blocks until the |
| 4997 |
/// `output-stream` is ready for writing, and the `input-stream` |
| 4998 |
/// is ready for reading, before performing the `splice`. |
| 4999 |
#[allow(async_fn_in_trait)] |
| 5000 |
pub fn blocking_splice( |
| 5001 |
&self, |
| 5002 |
src: &InputStream, |
| 5003 |
len: u64, |
| 5004 |
) -> Result<u64, StreamError> { |
| 5005 |
unsafe { |
| 5006 |
#[repr(align(8))] |
| 5007 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 5008 |
let mut ret_area = RetArea( |
| 5009 |
[::core::mem::MaybeUninit::uninit(); 16], |
| 5010 |
); |
| 5011 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 5012 |
#[cfg(target_arch = "wasm32")] |
| 5013 |
#[link(wasm_import_module = "wasi:io/[email protected]")] |
| 5014 |
unsafe extern "C" { |
| 5015 |
#[link_name = "[method]output-stream.blocking-splice"] |
| 5016 |
fn wit_import1(_: i32, _: i32, _: i64, _: *mut u8); |
| 5017 |
} |
| 5018 |
#[cfg(not(target_arch = "wasm32"))] |
| 5019 |
unsafe extern "C" fn wit_import1( |
| 5020 |
_: i32, |
| 5021 |
_: i32, |
| 5022 |
_: i64, |
| 5023 |
_: *mut u8, |
| 5024 |
) { |
| 5025 |
unreachable!() |
| 5026 |
} |
| 5027 |
wit_import1( |
| 5028 |
(self).handle() as i32, |
| 5029 |
(src).handle() as i32, |
| 5030 |
_rt::as_i64(&len), |
| 5031 |
ptr0, |
| 5032 |
); |
| 5033 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 5034 |
let result7 = match l2 { |
| 5035 |
0 => { |
| 5036 |
let e = { |
| 5037 |
let l3 = *ptr0.add(8).cast::<i64>(); |
| 5038 |
l3 as u64 |
| 5039 |
}; |
| 5040 |
Ok(e) |
| 5041 |
} |
| 5042 |
1 => { |
| 5043 |
let e = { |
| 5044 |
let l4 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 5045 |
let v6 = match l4 { |
| 5046 |
0 => { |
| 5047 |
let e6 = { |
| 5048 |
let l5 = *ptr0.add(12).cast::<i32>(); |
| 5049 |
super::super::super::wasi::io::error::Error::from_handle( |
| 5050 |
l5 as u32, |
| 5051 |
) |
| 5052 |
}; |
| 5053 |
StreamError::LastOperationFailed(e6) |
| 5054 |
} |
| 5055 |
n => { |
| 5056 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 5057 |
StreamError::Closed |
| 5058 |
} |
| 5059 |
}; |
| 5060 |
v6 |
| 5061 |
}; |
| 5062 |
Err(e) |
| 5063 |
} |
| 5064 |
_ => _rt::invalid_enum_discriminant(), |
| 5065 |
}; |
| 5066 |
result7 |
| 5067 |
} |
| 5068 |
} |
| 5069 |
} |
| 5070 |
} |
| 5071 |
} |
| 5072 |
pub mod random { |
| 5073 |
/// WASI Random is a random data API. |
| 5074 |
/// |
| 5075 |
/// It is intended to be portable at least between Unix-family platforms and |
| 5076 |
/// Windows. |
| 5077 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 5078 |
pub mod random { |
| 5079 |
#[used] |
| 5080 |
#[doc(hidden)] |
| 5081 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 5082 |
use super::super::super::_rt; |
| 5083 |
#[allow(unused_unsafe, clippy::all)] |
| 5084 |
/// Return `len` cryptographically-secure random or pseudo-random bytes. |
| 5085 |
/// |
| 5086 |
/// This function must produce data at least as cryptographically secure and |
| 5087 |
/// fast as an adequately seeded cryptographically-secure pseudo-random |
| 5088 |
/// number generator (CSPRNG). It must not block, from the perspective of |
| 5089 |
/// the calling program, under any circumstances, including on the first |
| 5090 |
/// request and on requests for numbers of bytes. The returned data must |
| 5091 |
/// always be unpredictable. |
| 5092 |
/// |
| 5093 |
/// This function must always return fresh data. Deterministic environments |
| 5094 |
/// must omit this function, rather than implementing it with deterministic |
| 5095 |
/// data. |
| 5096 |
#[allow(async_fn_in_trait)] |
| 5097 |
pub fn get_random_bytes(len: u64) -> _rt::Vec<u8> { |
| 5098 |
unsafe { |
| 5099 |
#[cfg_attr(target_pointer_width = "64", repr(align(8)))] |
| 5100 |
#[cfg_attr(target_pointer_width = "32", repr(align(4)))] |
| 5101 |
struct RetArea( |
| 5102 |
[::core::mem::MaybeUninit< |
| 5103 |
u8, |
| 5104 |
>; 2 * ::core::mem::size_of::<*const u8>()], |
| 5105 |
); |
| 5106 |
let mut ret_area = RetArea( |
| 5107 |
[::core::mem::MaybeUninit::uninit(); 2 |
| 5108 |
* ::core::mem::size_of::<*const u8>()], |
| 5109 |
); |
| 5110 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 5111 |
#[cfg(target_arch = "wasm32")] |
| 5112 |
#[link(wasm_import_module = "wasi:random/[email protected]")] |
| 5113 |
unsafe extern "C" { |
| 5114 |
#[link_name = "get-random-bytes"] |
| 5115 |
fn wit_import1(_: i64, _: *mut u8); |
| 5116 |
} |
| 5117 |
#[cfg(not(target_arch = "wasm32"))] |
| 5118 |
unsafe extern "C" fn wit_import1(_: i64, _: *mut u8) { |
| 5119 |
unreachable!() |
| 5120 |
} |
| 5121 |
wit_import1(_rt::as_i64(&len), ptr0); |
| 5122 |
let l2 = *ptr0.add(0).cast::<*mut u8>(); |
| 5123 |
let l3 = *ptr0 |
| 5124 |
.add(::core::mem::size_of::<*const u8>()) |
| 5125 |
.cast::<usize>(); |
| 5126 |
let len4 = l3; |
| 5127 |
let result5 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4); |
| 5128 |
result5 |
| 5129 |
} |
| 5130 |
} |
| 5131 |
#[allow(unused_unsafe, clippy::all)] |
| 5132 |
/// Return a cryptographically-secure random or pseudo-random `u64` value. |
| 5133 |
/// |
| 5134 |
/// This function returns the same type of data as `get-random-bytes`, |
| 5135 |
/// represented as a `u64`. |
| 5136 |
#[allow(async_fn_in_trait)] |
| 5137 |
pub fn get_random_u64() -> u64 { |
| 5138 |
unsafe { |
| 5139 |
#[cfg(target_arch = "wasm32")] |
| 5140 |
#[link(wasm_import_module = "wasi:random/[email protected]")] |
| 5141 |
unsafe extern "C" { |
| 5142 |
#[link_name = "get-random-u64"] |
| 5143 |
fn wit_import0() -> i64; |
| 5144 |
} |
| 5145 |
#[cfg(not(target_arch = "wasm32"))] |
| 5146 |
unsafe extern "C" fn wit_import0() -> i64 { |
| 5147 |
unreachable!() |
| 5148 |
} |
| 5149 |
let ret = wit_import0(); |
| 5150 |
ret as u64 |
| 5151 |
} |
| 5152 |
} |
| 5153 |
} |
| 5154 |
/// The insecure interface for insecure pseudo-random numbers. |
| 5155 |
/// |
| 5156 |
/// It is intended to be portable at least between Unix-family platforms and |
| 5157 |
/// Windows. |
| 5158 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 5159 |
pub mod insecure { |
| 5160 |
#[used] |
| 5161 |
#[doc(hidden)] |
| 5162 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 5163 |
use super::super::super::_rt; |
| 5164 |
#[allow(unused_unsafe, clippy::all)] |
| 5165 |
/// Return `len` insecure pseudo-random bytes. |
| 5166 |
/// |
| 5167 |
/// This function is not cryptographically secure. Do not use it for |
| 5168 |
/// anything related to security. |
| 5169 |
/// |
| 5170 |
/// There are no requirements on the values of the returned bytes, however |
| 5171 |
/// implementations are encouraged to return evenly distributed values with |
| 5172 |
/// a long period. |
| 5173 |
#[allow(async_fn_in_trait)] |
| 5174 |
pub fn get_insecure_random_bytes(len: u64) -> _rt::Vec<u8> { |
| 5175 |
unsafe { |
| 5176 |
#[cfg_attr(target_pointer_width = "64", repr(align(8)))] |
| 5177 |
#[cfg_attr(target_pointer_width = "32", repr(align(4)))] |
| 5178 |
struct RetArea( |
| 5179 |
[::core::mem::MaybeUninit< |
| 5180 |
u8, |
| 5181 |
>; 2 * ::core::mem::size_of::<*const u8>()], |
| 5182 |
); |
| 5183 |
let mut ret_area = RetArea( |
| 5184 |
[::core::mem::MaybeUninit::uninit(); 2 |
| 5185 |
* ::core::mem::size_of::<*const u8>()], |
| 5186 |
); |
| 5187 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 5188 |
#[cfg(target_arch = "wasm32")] |
| 5189 |
#[link(wasm_import_module = "wasi:random/[email protected]")] |
| 5190 |
unsafe extern "C" { |
| 5191 |
#[link_name = "get-insecure-random-bytes"] |
| 5192 |
fn wit_import1(_: i64, _: *mut u8); |
| 5193 |
} |
| 5194 |
#[cfg(not(target_arch = "wasm32"))] |
| 5195 |
unsafe extern "C" fn wit_import1(_: i64, _: *mut u8) { |
| 5196 |
unreachable!() |
| 5197 |
} |
| 5198 |
wit_import1(_rt::as_i64(&len), ptr0); |
| 5199 |
let l2 = *ptr0.add(0).cast::<*mut u8>(); |
| 5200 |
let l3 = *ptr0 |
| 5201 |
.add(::core::mem::size_of::<*const u8>()) |
| 5202 |
.cast::<usize>(); |
| 5203 |
let len4 = l3; |
| 5204 |
let result5 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4); |
| 5205 |
result5 |
| 5206 |
} |
| 5207 |
} |
| 5208 |
#[allow(unused_unsafe, clippy::all)] |
| 5209 |
/// Return an insecure pseudo-random `u64` value. |
| 5210 |
/// |
| 5211 |
/// This function returns the same type of pseudo-random data as |
| 5212 |
/// `get-insecure-random-bytes`, represented as a `u64`. |
| 5213 |
#[allow(async_fn_in_trait)] |
| 5214 |
pub fn get_insecure_random_u64() -> u64 { |
| 5215 |
unsafe { |
| 5216 |
#[cfg(target_arch = "wasm32")] |
| 5217 |
#[link(wasm_import_module = "wasi:random/[email protected]")] |
| 5218 |
unsafe extern "C" { |
| 5219 |
#[link_name = "get-insecure-random-u64"] |
| 5220 |
fn wit_import0() -> i64; |
| 5221 |
} |
| 5222 |
#[cfg(not(target_arch = "wasm32"))] |
| 5223 |
unsafe extern "C" fn wit_import0() -> i64 { |
| 5224 |
unreachable!() |
| 5225 |
} |
| 5226 |
let ret = wit_import0(); |
| 5227 |
ret as u64 |
| 5228 |
} |
| 5229 |
} |
| 5230 |
} |
| 5231 |
/// The insecure-seed interface for seeding hash-map DoS resistance. |
| 5232 |
/// |
| 5233 |
/// It is intended to be portable at least between Unix-family platforms and |
| 5234 |
/// Windows. |
| 5235 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 5236 |
pub mod insecure_seed { |
| 5237 |
#[used] |
| 5238 |
#[doc(hidden)] |
| 5239 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 5240 |
#[allow(unused_unsafe, clippy::all)] |
| 5241 |
/// Return a 128-bit value that may contain a pseudo-random value. |
| 5242 |
/// |
| 5243 |
/// The returned value is not required to be computed from a CSPRNG, and may |
| 5244 |
/// even be entirely deterministic. Host implementations are encouraged to |
| 5245 |
/// provide pseudo-random values to any program exposed to |
| 5246 |
/// attacker-controlled content, to enable DoS protection built into many |
| 5247 |
/// languages' hash-map implementations. |
| 5248 |
/// |
| 5249 |
/// This function is intended to only be called once, by a source language |
| 5250 |
/// to initialize Denial Of Service (DoS) protection in its hash-map |
| 5251 |
/// implementation. |
| 5252 |
/// |
| 5253 |
/// # Expected future evolution |
| 5254 |
/// |
| 5255 |
/// This will likely be changed to a value import, to prevent it from being |
| 5256 |
/// called multiple times and potentially used for purposes other than DoS |
| 5257 |
/// protection. |
| 5258 |
#[allow(async_fn_in_trait)] |
| 5259 |
pub fn insecure_seed() -> (u64, u64) { |
| 5260 |
unsafe { |
| 5261 |
#[repr(align(8))] |
| 5262 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 5263 |
let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); |
| 5264 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 5265 |
#[cfg(target_arch = "wasm32")] |
| 5266 |
#[link(wasm_import_module = "wasi:random/[email protected]")] |
| 5267 |
unsafe extern "C" { |
| 5268 |
#[link_name = "insecure-seed"] |
| 5269 |
fn wit_import1(_: *mut u8); |
| 5270 |
} |
| 5271 |
#[cfg(not(target_arch = "wasm32"))] |
| 5272 |
unsafe extern "C" fn wit_import1(_: *mut u8) { |
| 5273 |
unreachable!() |
| 5274 |
} |
| 5275 |
wit_import1(ptr0); |
| 5276 |
let l2 = *ptr0.add(0).cast::<i64>(); |
| 5277 |
let l3 = *ptr0.add(8).cast::<i64>(); |
| 5278 |
let result4 = (l2 as u64, l3 as u64); |
| 5279 |
result4 |
| 5280 |
} |
| 5281 |
} |
| 5282 |
} |
| 5283 |
} |
| 5284 |
pub mod sockets { |
| 5285 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 5286 |
pub mod network { |
| 5287 |
#[used] |
| 5288 |
#[doc(hidden)] |
| 5289 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 5290 |
use super::super::super::_rt; |
| 5291 |
/// An opaque resource that represents access to (a subset of) the network. |
| 5292 |
/// This enables context-based security for networking. |
| 5293 |
/// There is no need for this to map 1:1 to a physical network interface. |
| 5294 |
#[derive(Debug)] |
| 5295 |
#[repr(transparent)] |
| 5296 |
pub struct Network { |
| 5297 |
handle: _rt::Resource<Network>, |
| 5298 |
} |
| 5299 |
impl Network { |
| 5300 |
#[doc(hidden)] |
| 5301 |
pub unsafe fn from_handle(handle: u32) -> Self { |
| 5302 |
Self { |
| 5303 |
handle: unsafe { _rt::Resource::from_handle(handle) }, |
| 5304 |
} |
| 5305 |
} |
| 5306 |
#[doc(hidden)] |
| 5307 |
pub fn take_handle(&self) -> u32 { |
| 5308 |
_rt::Resource::take_handle(&self.handle) |
| 5309 |
} |
| 5310 |
#[doc(hidden)] |
| 5311 |
pub fn handle(&self) -> u32 { |
| 5312 |
_rt::Resource::handle(&self.handle) |
| 5313 |
} |
| 5314 |
} |
| 5315 |
unsafe impl _rt::WasmResource for Network { |
| 5316 |
#[inline] |
| 5317 |
unsafe fn drop(_handle: u32) { |
| 5318 |
#[cfg(target_arch = "wasm32")] |
| 5319 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 5320 |
unsafe extern "C" { |
| 5321 |
#[link_name = "[resource-drop]network"] |
| 5322 |
fn drop(_: i32); |
| 5323 |
} |
| 5324 |
#[cfg(not(target_arch = "wasm32"))] |
| 5325 |
unsafe extern "C" fn drop(_: i32) { |
| 5326 |
unreachable!() |
| 5327 |
} |
| 5328 |
unsafe { |
| 5329 |
drop(_handle as i32); |
| 5330 |
} |
| 5331 |
} |
| 5332 |
} |
| 5333 |
/// Error codes. |
| 5334 |
/// |
| 5335 |
/// In theory, every API can return any error code. |
| 5336 |
/// In practice, API's typically only return the errors documented per API |
| 5337 |
/// combined with a couple of errors that are always possible: |
| 5338 |
/// - `unknown` |
| 5339 |
/// - `access-denied` |
| 5340 |
/// - `not-supported` |
| 5341 |
/// - `out-of-memory` |
| 5342 |
/// - `concurrency-conflict` |
| 5343 |
/// |
| 5344 |
/// See each individual API for what the POSIX equivalents are. They sometimes differ per API. |
| 5345 |
#[repr(u8)] |
| 5346 |
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)] |
| 5347 |
pub enum ErrorCode { |
| 5348 |
/// Unknown error |
| 5349 |
Unknown, |
| 5350 |
/// Access denied. |
| 5351 |
/// |
| 5352 |
/// POSIX equivalent: EACCES, EPERM |
| 5353 |
AccessDenied, |
| 5354 |
/// The operation is not supported. |
| 5355 |
/// |
| 5356 |
/// POSIX equivalent: EOPNOTSUPP |
| 5357 |
NotSupported, |
| 5358 |
/// One of the arguments is invalid. |
| 5359 |
/// |
| 5360 |
/// POSIX equivalent: EINVAL |
| 5361 |
InvalidArgument, |
| 5362 |
/// Not enough memory to complete the operation. |
| 5363 |
/// |
| 5364 |
/// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY |
| 5365 |
OutOfMemory, |
| 5366 |
/// The operation timed out before it could finish completely. |
| 5367 |
Timeout, |
| 5368 |
/// This operation is incompatible with another asynchronous operation that is already in progress. |
| 5369 |
/// |
| 5370 |
/// POSIX equivalent: EALREADY |
| 5371 |
ConcurrencyConflict, |
| 5372 |
/// Trying to finish an asynchronous operation that: |
| 5373 |
/// - has not been started yet, or: |
| 5374 |
/// - was already finished by a previous `finish-*` call. |
| 5375 |
/// |
| 5376 |
/// Note: this is scheduled to be removed when `future`s are natively supported. |
| 5377 |
NotInProgress, |
| 5378 |
/// The operation has been aborted because it could not be completed immediately. |
| 5379 |
/// |
| 5380 |
/// Note: this is scheduled to be removed when `future`s are natively supported. |
| 5381 |
WouldBlock, |
| 5382 |
/// The operation is not valid in the socket's current state. |
| 5383 |
InvalidState, |
| 5384 |
/// A new socket resource could not be created because of a system limit. |
| 5385 |
NewSocketLimit, |
| 5386 |
/// A bind operation failed because the provided address is not an address that the `network` can bind to. |
| 5387 |
AddressNotBindable, |
| 5388 |
/// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available. |
| 5389 |
AddressInUse, |
| 5390 |
/// The remote address is not reachable |
| 5391 |
RemoteUnreachable, |
| 5392 |
/// The TCP connection was forcefully rejected |
| 5393 |
ConnectionRefused, |
| 5394 |
/// The TCP connection was reset. |
| 5395 |
ConnectionReset, |
| 5396 |
/// A TCP connection was aborted. |
| 5397 |
ConnectionAborted, |
| 5398 |
/// The size of a datagram sent to a UDP socket exceeded the maximum |
| 5399 |
/// supported size. |
| 5400 |
DatagramTooLarge, |
| 5401 |
/// Name does not exist or has no suitable associated IP addresses. |
| 5402 |
NameUnresolvable, |
| 5403 |
/// A temporary failure in name resolution occurred. |
| 5404 |
TemporaryResolverFailure, |
| 5405 |
/// A permanent failure in name resolution occurred. |
| 5406 |
PermanentResolverFailure, |
| 5407 |
} |
| 5408 |
impl ErrorCode { |
| 5409 |
pub fn name(&self) -> &'static str { |
| 5410 |
match self { |
| 5411 |
ErrorCode::Unknown => "unknown", |
| 5412 |
ErrorCode::AccessDenied => "access-denied", |
| 5413 |
ErrorCode::NotSupported => "not-supported", |
| 5414 |
ErrorCode::InvalidArgument => "invalid-argument", |
| 5415 |
ErrorCode::OutOfMemory => "out-of-memory", |
| 5416 |
ErrorCode::Timeout => "timeout", |
| 5417 |
ErrorCode::ConcurrencyConflict => "concurrency-conflict", |
| 5418 |
ErrorCode::NotInProgress => "not-in-progress", |
| 5419 |
ErrorCode::WouldBlock => "would-block", |
| 5420 |
ErrorCode::InvalidState => "invalid-state", |
| 5421 |
ErrorCode::NewSocketLimit => "new-socket-limit", |
| 5422 |
ErrorCode::AddressNotBindable => "address-not-bindable", |
| 5423 |
ErrorCode::AddressInUse => "address-in-use", |
| 5424 |
ErrorCode::RemoteUnreachable => "remote-unreachable", |
| 5425 |
ErrorCode::ConnectionRefused => "connection-refused", |
| 5426 |
ErrorCode::ConnectionReset => "connection-reset", |
| 5427 |
ErrorCode::ConnectionAborted => "connection-aborted", |
| 5428 |
ErrorCode::DatagramTooLarge => "datagram-too-large", |
| 5429 |
ErrorCode::NameUnresolvable => "name-unresolvable", |
| 5430 |
ErrorCode::TemporaryResolverFailure => { |
| 5431 |
"temporary-resolver-failure" |
| 5432 |
} |
| 5433 |
ErrorCode::PermanentResolverFailure => { |
| 5434 |
"permanent-resolver-failure" |
| 5435 |
} |
| 5436 |
} |
| 5437 |
} |
| 5438 |
pub fn message(&self) -> &'static str { |
| 5439 |
match self { |
| 5440 |
ErrorCode::Unknown => "Unknown error", |
| 5441 |
ErrorCode::AccessDenied => { |
| 5442 |
"Access denied. |
| 5443 |
|
| 5444 |
POSIX equivalent: EACCES, EPERM" |
| 5445 |
} |
| 5446 |
ErrorCode::NotSupported => { |
| 5447 |
"The operation is not supported. |
| 5448 |
|
| 5449 |
POSIX equivalent: EOPNOTSUPP" |
| 5450 |
} |
| 5451 |
ErrorCode::InvalidArgument => { |
| 5452 |
"One of the arguments is invalid. |
| 5453 |
|
| 5454 |
POSIX equivalent: EINVAL" |
| 5455 |
} |
| 5456 |
ErrorCode::OutOfMemory => { |
| 5457 |
"Not enough memory to complete the operation. |
| 5458 |
|
| 5459 |
POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY" |
| 5460 |
} |
| 5461 |
ErrorCode::Timeout => { |
| 5462 |
"The operation timed out before it could finish completely." |
| 5463 |
} |
| 5464 |
ErrorCode::ConcurrencyConflict => { |
| 5465 |
"This operation is incompatible with another asynchronous operation that is already in progress. |
| 5466 |
|
| 5467 |
POSIX equivalent: EALREADY" |
| 5468 |
} |
| 5469 |
ErrorCode::NotInProgress => { |
| 5470 |
"Trying to finish an asynchronous operation that: |
| 5471 |
- has not been started yet, or: |
| 5472 |
- was already finished by a previous `finish-*` call. |
| 5473 |
|
| 5474 |
Note: this is scheduled to be removed when `future`s are natively supported." |
| 5475 |
} |
| 5476 |
ErrorCode::WouldBlock => { |
| 5477 |
"The operation has been aborted because it could not be completed immediately. |
| 5478 |
|
| 5479 |
Note: this is scheduled to be removed when `future`s are natively supported." |
| 5480 |
} |
| 5481 |
ErrorCode::InvalidState => { |
| 5482 |
"The operation is not valid in the socket's current state." |
| 5483 |
} |
| 5484 |
ErrorCode::NewSocketLimit => { |
| 5485 |
"A new socket resource could not be created because of a system limit." |
| 5486 |
} |
| 5487 |
ErrorCode::AddressNotBindable => { |
| 5488 |
"A bind operation failed because the provided address is not an address that the `network` can bind to." |
| 5489 |
} |
| 5490 |
ErrorCode::AddressInUse => { |
| 5491 |
"A bind operation failed because the provided address is already in use or because there are no ephemeral ports available." |
| 5492 |
} |
| 5493 |
ErrorCode::RemoteUnreachable => { |
| 5494 |
"The remote address is not reachable" |
| 5495 |
} |
| 5496 |
ErrorCode::ConnectionRefused => { |
| 5497 |
"The TCP connection was forcefully rejected" |
| 5498 |
} |
| 5499 |
ErrorCode::ConnectionReset => "The TCP connection was reset.", |
| 5500 |
ErrorCode::ConnectionAborted => "A TCP connection was aborted.", |
| 5501 |
ErrorCode::DatagramTooLarge => { |
| 5502 |
"The size of a datagram sent to a UDP socket exceeded the maximum |
| 5503 |
supported size." |
| 5504 |
} |
| 5505 |
ErrorCode::NameUnresolvable => { |
| 5506 |
"Name does not exist or has no suitable associated IP addresses." |
| 5507 |
} |
| 5508 |
ErrorCode::TemporaryResolverFailure => { |
| 5509 |
"A temporary failure in name resolution occurred." |
| 5510 |
} |
| 5511 |
ErrorCode::PermanentResolverFailure => { |
| 5512 |
"A permanent failure in name resolution occurred." |
| 5513 |
} |
| 5514 |
} |
| 5515 |
} |
| 5516 |
} |
| 5517 |
impl ::core::fmt::Debug for ErrorCode { |
| 5518 |
fn fmt( |
| 5519 |
&self, |
| 5520 |
f: &mut ::core::fmt::Formatter<'_>, |
| 5521 |
) -> ::core::fmt::Result { |
| 5522 |
f.debug_struct("ErrorCode") |
| 5523 |
.field("code", &(*self as i32)) |
| 5524 |
.field("name", &self.name()) |
| 5525 |
.field("message", &self.message()) |
| 5526 |
.finish() |
| 5527 |
} |
| 5528 |
} |
| 5529 |
impl ::core::fmt::Display for ErrorCode { |
| 5530 |
fn fmt( |
| 5531 |
&self, |
| 5532 |
f: &mut ::core::fmt::Formatter<'_>, |
| 5533 |
) -> ::core::fmt::Result { |
| 5534 |
write!(f, "{} (error {})", self.name(), * self as i32) |
| 5535 |
} |
| 5536 |
} |
| 5537 |
#[cfg(feature = "std")] |
| 5538 |
impl std::error::Error for ErrorCode {} |
| 5539 |
impl ErrorCode { |
| 5540 |
#[doc(hidden)] |
| 5541 |
pub unsafe fn _lift(val: u8) -> ErrorCode { |
| 5542 |
if !cfg!(debug_assertions) { |
| 5543 |
return unsafe { ::core::mem::transmute(val) }; |
| 5544 |
} |
| 5545 |
match val { |
| 5546 |
0 => ErrorCode::Unknown, |
| 5547 |
1 => ErrorCode::AccessDenied, |
| 5548 |
2 => ErrorCode::NotSupported, |
| 5549 |
3 => ErrorCode::InvalidArgument, |
| 5550 |
4 => ErrorCode::OutOfMemory, |
| 5551 |
5 => ErrorCode::Timeout, |
| 5552 |
6 => ErrorCode::ConcurrencyConflict, |
| 5553 |
7 => ErrorCode::NotInProgress, |
| 5554 |
8 => ErrorCode::WouldBlock, |
| 5555 |
9 => ErrorCode::InvalidState, |
| 5556 |
10 => ErrorCode::NewSocketLimit, |
| 5557 |
11 => ErrorCode::AddressNotBindable, |
| 5558 |
12 => ErrorCode::AddressInUse, |
| 5559 |
13 => ErrorCode::RemoteUnreachable, |
| 5560 |
14 => ErrorCode::ConnectionRefused, |
| 5561 |
15 => ErrorCode::ConnectionReset, |
| 5562 |
16 => ErrorCode::ConnectionAborted, |
| 5563 |
17 => ErrorCode::DatagramTooLarge, |
| 5564 |
18 => ErrorCode::NameUnresolvable, |
| 5565 |
19 => ErrorCode::TemporaryResolverFailure, |
| 5566 |
20 => ErrorCode::PermanentResolverFailure, |
| 5567 |
_ => panic!("invalid enum discriminant"), |
| 5568 |
} |
| 5569 |
} |
| 5570 |
} |
| 5571 |
#[repr(u8)] |
| 5572 |
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)] |
| 5573 |
pub enum IpAddressFamily { |
| 5574 |
/// Similar to `AF_INET` in POSIX. |
| 5575 |
Ipv4, |
| 5576 |
/// Similar to `AF_INET6` in POSIX. |
| 5577 |
Ipv6, |
| 5578 |
} |
| 5579 |
impl ::core::fmt::Debug for IpAddressFamily { |
| 5580 |
fn fmt( |
| 5581 |
&self, |
| 5582 |
f: &mut ::core::fmt::Formatter<'_>, |
| 5583 |
) -> ::core::fmt::Result { |
| 5584 |
match self { |
| 5585 |
IpAddressFamily::Ipv4 => { |
| 5586 |
f.debug_tuple("IpAddressFamily::Ipv4").finish() |
| 5587 |
} |
| 5588 |
IpAddressFamily::Ipv6 => { |
| 5589 |
f.debug_tuple("IpAddressFamily::Ipv6").finish() |
| 5590 |
} |
| 5591 |
} |
| 5592 |
} |
| 5593 |
} |
| 5594 |
impl IpAddressFamily { |
| 5595 |
#[doc(hidden)] |
| 5596 |
pub unsafe fn _lift(val: u8) -> IpAddressFamily { |
| 5597 |
if !cfg!(debug_assertions) { |
| 5598 |
return unsafe { ::core::mem::transmute(val) }; |
| 5599 |
} |
| 5600 |
match val { |
| 5601 |
0 => IpAddressFamily::Ipv4, |
| 5602 |
1 => IpAddressFamily::Ipv6, |
| 5603 |
_ => panic!("invalid enum discriminant"), |
| 5604 |
} |
| 5605 |
} |
| 5606 |
} |
| 5607 |
pub type Ipv4Address = (u8, u8, u8, u8); |
| 5608 |
pub type Ipv6Address = (u16, u16, u16, u16, u16, u16, u16, u16); |
| 5609 |
#[derive(Clone, Copy)] |
| 5610 |
pub enum IpAddress { |
| 5611 |
Ipv4(Ipv4Address), |
| 5612 |
Ipv6(Ipv6Address), |
| 5613 |
} |
| 5614 |
impl ::core::fmt::Debug for IpAddress { |
| 5615 |
fn fmt( |
| 5616 |
&self, |
| 5617 |
f: &mut ::core::fmt::Formatter<'_>, |
| 5618 |
) -> ::core::fmt::Result { |
| 5619 |
match self { |
| 5620 |
IpAddress::Ipv4(e) => { |
| 5621 |
f.debug_tuple("IpAddress::Ipv4").field(e).finish() |
| 5622 |
} |
| 5623 |
IpAddress::Ipv6(e) => { |
| 5624 |
f.debug_tuple("IpAddress::Ipv6").field(e).finish() |
| 5625 |
} |
| 5626 |
} |
| 5627 |
} |
| 5628 |
} |
| 5629 |
#[repr(C)] |
| 5630 |
#[derive(Clone, Copy)] |
| 5631 |
pub struct Ipv4SocketAddress { |
| 5632 |
/// sin_port |
| 5633 |
pub port: u16, |
| 5634 |
/// sin_addr |
| 5635 |
pub address: Ipv4Address, |
| 5636 |
} |
| 5637 |
impl ::core::fmt::Debug for Ipv4SocketAddress { |
| 5638 |
fn fmt( |
| 5639 |
&self, |
| 5640 |
f: &mut ::core::fmt::Formatter<'_>, |
| 5641 |
) -> ::core::fmt::Result { |
| 5642 |
f.debug_struct("Ipv4SocketAddress") |
| 5643 |
.field("port", &self.port) |
| 5644 |
.field("address", &self.address) |
| 5645 |
.finish() |
| 5646 |
} |
| 5647 |
} |
| 5648 |
#[repr(C)] |
| 5649 |
#[derive(Clone, Copy)] |
| 5650 |
pub struct Ipv6SocketAddress { |
| 5651 |
/// sin6_port |
| 5652 |
pub port: u16, |
| 5653 |
/// sin6_flowinfo |
| 5654 |
pub flow_info: u32, |
| 5655 |
/// sin6_addr |
| 5656 |
pub address: Ipv6Address, |
| 5657 |
/// sin6_scope_id |
| 5658 |
pub scope_id: u32, |
| 5659 |
} |
| 5660 |
impl ::core::fmt::Debug for Ipv6SocketAddress { |
| 5661 |
fn fmt( |
| 5662 |
&self, |
| 5663 |
f: &mut ::core::fmt::Formatter<'_>, |
| 5664 |
) -> ::core::fmt::Result { |
| 5665 |
f.debug_struct("Ipv6SocketAddress") |
| 5666 |
.field("port", &self.port) |
| 5667 |
.field("flow-info", &self.flow_info) |
| 5668 |
.field("address", &self.address) |
| 5669 |
.field("scope-id", &self.scope_id) |
| 5670 |
.finish() |
| 5671 |
} |
| 5672 |
} |
| 5673 |
#[derive(Clone, Copy)] |
| 5674 |
pub enum IpSocketAddress { |
| 5675 |
Ipv4(Ipv4SocketAddress), |
| 5676 |
Ipv6(Ipv6SocketAddress), |
| 5677 |
} |
| 5678 |
impl ::core::fmt::Debug for IpSocketAddress { |
| 5679 |
fn fmt( |
| 5680 |
&self, |
| 5681 |
f: &mut ::core::fmt::Formatter<'_>, |
| 5682 |
) -> ::core::fmt::Result { |
| 5683 |
match self { |
| 5684 |
IpSocketAddress::Ipv4(e) => { |
| 5685 |
f.debug_tuple("IpSocketAddress::Ipv4").field(e).finish() |
| 5686 |
} |
| 5687 |
IpSocketAddress::Ipv6(e) => { |
| 5688 |
f.debug_tuple("IpSocketAddress::Ipv6").field(e).finish() |
| 5689 |
} |
| 5690 |
} |
| 5691 |
} |
| 5692 |
} |
| 5693 |
} |
| 5694 |
/// This interface provides a value-export of the default network handle.. |
| 5695 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 5696 |
pub mod instance_network { |
| 5697 |
#[used] |
| 5698 |
#[doc(hidden)] |
| 5699 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 5700 |
pub type Network = super::super::super::wasi::sockets::network::Network; |
| 5701 |
#[allow(unused_unsafe, clippy::all)] |
| 5702 |
/// Get a handle to the default network. |
| 5703 |
#[allow(async_fn_in_trait)] |
| 5704 |
pub fn instance_network() -> Network { |
| 5705 |
unsafe { |
| 5706 |
#[cfg(target_arch = "wasm32")] |
| 5707 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 5708 |
unsafe extern "C" { |
| 5709 |
#[link_name = "instance-network"] |
| 5710 |
fn wit_import0() -> i32; |
| 5711 |
} |
| 5712 |
#[cfg(not(target_arch = "wasm32"))] |
| 5713 |
unsafe extern "C" fn wit_import0() -> i32 { |
| 5714 |
unreachable!() |
| 5715 |
} |
| 5716 |
let ret = wit_import0(); |
| 5717 |
super::super::super::wasi::sockets::network::Network::from_handle( |
| 5718 |
ret as u32, |
| 5719 |
) |
| 5720 |
} |
| 5721 |
} |
| 5722 |
} |
| 5723 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 5724 |
pub mod udp { |
| 5725 |
#[used] |
| 5726 |
#[doc(hidden)] |
| 5727 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 5728 |
use super::super::super::_rt; |
| 5729 |
pub type Pollable = super::super::super::wasi::io::poll::Pollable; |
| 5730 |
pub type Network = super::super::super::wasi::sockets::network::Network; |
| 5731 |
pub type ErrorCode = super::super::super::wasi::sockets::network::ErrorCode; |
| 5732 |
pub type IpSocketAddress = super::super::super::wasi::sockets::network::IpSocketAddress; |
| 5733 |
pub type IpAddressFamily = super::super::super::wasi::sockets::network::IpAddressFamily; |
| 5734 |
/// A received datagram. |
| 5735 |
#[derive(Clone)] |
| 5736 |
pub struct IncomingDatagram { |
| 5737 |
/// The payload. |
| 5738 |
/// |
| 5739 |
/// Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. |
| 5740 |
pub data: _rt::Vec<u8>, |
| 5741 |
/// The source address. |
| 5742 |
/// |
| 5743 |
/// This field is guaranteed to match the remote address the stream was initialized with, if any. |
| 5744 |
/// |
| 5745 |
/// Equivalent to the `src_addr` out parameter of `recvfrom`. |
| 5746 |
pub remote_address: IpSocketAddress, |
| 5747 |
} |
| 5748 |
impl ::core::fmt::Debug for IncomingDatagram { |
| 5749 |
fn fmt( |
| 5750 |
&self, |
| 5751 |
f: &mut ::core::fmt::Formatter<'_>, |
| 5752 |
) -> ::core::fmt::Result { |
| 5753 |
f.debug_struct("IncomingDatagram") |
| 5754 |
.field("data", &self.data) |
| 5755 |
.field("remote-address", &self.remote_address) |
| 5756 |
.finish() |
| 5757 |
} |
| 5758 |
} |
| 5759 |
/// A datagram to be sent out. |
| 5760 |
#[derive(Clone)] |
| 5761 |
pub struct OutgoingDatagram { |
| 5762 |
/// The payload. |
| 5763 |
pub data: _rt::Vec<u8>, |
| 5764 |
/// The destination address. |
| 5765 |
/// |
| 5766 |
/// The requirements on this field depend on how the stream was initialized: |
| 5767 |
/// - with a remote address: this field must be None or match the stream's remote address exactly. |
| 5768 |
/// - without a remote address: this field is required. |
| 5769 |
/// |
| 5770 |
/// If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise it is equivalent to `sendto`. |
| 5771 |
pub remote_address: Option<IpSocketAddress>, |
| 5772 |
} |
| 5773 |
impl ::core::fmt::Debug for OutgoingDatagram { |
| 5774 |
fn fmt( |
| 5775 |
&self, |
| 5776 |
f: &mut ::core::fmt::Formatter<'_>, |
| 5777 |
) -> ::core::fmt::Result { |
| 5778 |
f.debug_struct("OutgoingDatagram") |
| 5779 |
.field("data", &self.data) |
| 5780 |
.field("remote-address", &self.remote_address) |
| 5781 |
.finish() |
| 5782 |
} |
| 5783 |
} |
| 5784 |
/// A UDP socket handle. |
| 5785 |
#[derive(Debug)] |
| 5786 |
#[repr(transparent)] |
| 5787 |
pub struct UdpSocket { |
| 5788 |
handle: _rt::Resource<UdpSocket>, |
| 5789 |
} |
| 5790 |
impl UdpSocket { |
| 5791 |
#[doc(hidden)] |
| 5792 |
pub unsafe fn from_handle(handle: u32) -> Self { |
| 5793 |
Self { |
| 5794 |
handle: unsafe { _rt::Resource::from_handle(handle) }, |
| 5795 |
} |
| 5796 |
} |
| 5797 |
#[doc(hidden)] |
| 5798 |
pub fn take_handle(&self) -> u32 { |
| 5799 |
_rt::Resource::take_handle(&self.handle) |
| 5800 |
} |
| 5801 |
#[doc(hidden)] |
| 5802 |
pub fn handle(&self) -> u32 { |
| 5803 |
_rt::Resource::handle(&self.handle) |
| 5804 |
} |
| 5805 |
} |
| 5806 |
unsafe impl _rt::WasmResource for UdpSocket { |
| 5807 |
#[inline] |
| 5808 |
unsafe fn drop(_handle: u32) { |
| 5809 |
#[cfg(target_arch = "wasm32")] |
| 5810 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 5811 |
unsafe extern "C" { |
| 5812 |
#[link_name = "[resource-drop]udp-socket"] |
| 5813 |
fn drop(_: i32); |
| 5814 |
} |
| 5815 |
#[cfg(not(target_arch = "wasm32"))] |
| 5816 |
unsafe extern "C" fn drop(_: i32) { |
| 5817 |
unreachable!() |
| 5818 |
} |
| 5819 |
unsafe { |
| 5820 |
drop(_handle as i32); |
| 5821 |
} |
| 5822 |
} |
| 5823 |
} |
| 5824 |
#[derive(Debug)] |
| 5825 |
#[repr(transparent)] |
| 5826 |
pub struct IncomingDatagramStream { |
| 5827 |
handle: _rt::Resource<IncomingDatagramStream>, |
| 5828 |
} |
| 5829 |
impl IncomingDatagramStream { |
| 5830 |
#[doc(hidden)] |
| 5831 |
pub unsafe fn from_handle(handle: u32) -> Self { |
| 5832 |
Self { |
| 5833 |
handle: unsafe { _rt::Resource::from_handle(handle) }, |
| 5834 |
} |
| 5835 |
} |
| 5836 |
#[doc(hidden)] |
| 5837 |
pub fn take_handle(&self) -> u32 { |
| 5838 |
_rt::Resource::take_handle(&self.handle) |
| 5839 |
} |
| 5840 |
#[doc(hidden)] |
| 5841 |
pub fn handle(&self) -> u32 { |
| 5842 |
_rt::Resource::handle(&self.handle) |
| 5843 |
} |
| 5844 |
} |
| 5845 |
unsafe impl _rt::WasmResource for IncomingDatagramStream { |
| 5846 |
#[inline] |
| 5847 |
unsafe fn drop(_handle: u32) { |
| 5848 |
#[cfg(target_arch = "wasm32")] |
| 5849 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 5850 |
unsafe extern "C" { |
| 5851 |
#[link_name = "[resource-drop]incoming-datagram-stream"] |
| 5852 |
fn drop(_: i32); |
| 5853 |
} |
| 5854 |
#[cfg(not(target_arch = "wasm32"))] |
| 5855 |
unsafe extern "C" fn drop(_: i32) { |
| 5856 |
unreachable!() |
| 5857 |
} |
| 5858 |
unsafe { |
| 5859 |
drop(_handle as i32); |
| 5860 |
} |
| 5861 |
} |
| 5862 |
} |
| 5863 |
#[derive(Debug)] |
| 5864 |
#[repr(transparent)] |
| 5865 |
pub struct OutgoingDatagramStream { |
| 5866 |
handle: _rt::Resource<OutgoingDatagramStream>, |
| 5867 |
} |
| 5868 |
impl OutgoingDatagramStream { |
| 5869 |
#[doc(hidden)] |
| 5870 |
pub unsafe fn from_handle(handle: u32) -> Self { |
| 5871 |
Self { |
| 5872 |
handle: unsafe { _rt::Resource::from_handle(handle) }, |
| 5873 |
} |
| 5874 |
} |
| 5875 |
#[doc(hidden)] |
| 5876 |
pub fn take_handle(&self) -> u32 { |
| 5877 |
_rt::Resource::take_handle(&self.handle) |
| 5878 |
} |
| 5879 |
#[doc(hidden)] |
| 5880 |
pub fn handle(&self) -> u32 { |
| 5881 |
_rt::Resource::handle(&self.handle) |
| 5882 |
} |
| 5883 |
} |
| 5884 |
unsafe impl _rt::WasmResource for OutgoingDatagramStream { |
| 5885 |
#[inline] |
| 5886 |
unsafe fn drop(_handle: u32) { |
| 5887 |
#[cfg(target_arch = "wasm32")] |
| 5888 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 5889 |
unsafe extern "C" { |
| 5890 |
#[link_name = "[resource-drop]outgoing-datagram-stream"] |
| 5891 |
fn drop(_: i32); |
| 5892 |
} |
| 5893 |
#[cfg(not(target_arch = "wasm32"))] |
| 5894 |
unsafe extern "C" fn drop(_: i32) { |
| 5895 |
unreachable!() |
| 5896 |
} |
| 5897 |
unsafe { |
| 5898 |
drop(_handle as i32); |
| 5899 |
} |
| 5900 |
} |
| 5901 |
} |
| 5902 |
impl UdpSocket { |
| 5903 |
#[allow(unused_unsafe, clippy::all)] |
| 5904 |
/// Bind the socket to a specific network on the provided IP address and port. |
| 5905 |
/// |
| 5906 |
/// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which |
| 5907 |
/// network interface(s) to bind to. |
| 5908 |
/// If the port is zero, the socket will be bound to a random free port. |
| 5909 |
/// |
| 5910 |
/// # Typical errors |
| 5911 |
/// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) |
| 5912 |
/// - `invalid-state`: The socket is already bound. (EINVAL) |
| 5913 |
/// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) |
| 5914 |
/// - `address-in-use`: Address is already in use. (EADDRINUSE) |
| 5915 |
/// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) |
| 5916 |
/// - `not-in-progress`: A `bind` operation is not in progress. |
| 5917 |
/// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) |
| 5918 |
/// |
| 5919 |
/// # Implementors note |
| 5920 |
/// Unlike in POSIX, in WASI the bind operation is async. This enables |
| 5921 |
/// interactive WASI hosts to inject permission prompts. Runtimes that |
| 5922 |
/// don't want to make use of this ability can simply call the native |
| 5923 |
/// `bind` as part of either `start-bind` or `finish-bind`. |
| 5924 |
/// |
| 5925 |
/// # References |
| 5926 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html> |
| 5927 |
/// - <https://man7.org/linux/man-pages/man2/bind.2.html> |
| 5928 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-bind> |
| 5929 |
/// - <https://man.freebsd.org/cgi/man.cgi?query=bind&sektion=2&format=html> |
| 5930 |
#[allow(async_fn_in_trait)] |
| 5931 |
pub fn start_bind( |
| 5932 |
&self, |
| 5933 |
network: &Network, |
| 5934 |
local_address: IpSocketAddress, |
| 5935 |
) -> Result<(), ErrorCode> { |
| 5936 |
unsafe { |
| 5937 |
#[repr(align(1))] |
| 5938 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 5939 |
let mut ret_area = RetArea( |
| 5940 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 5941 |
); |
| 5942 |
use super::super::super::wasi::sockets::network::IpSocketAddress as V4; |
| 5943 |
let ( |
| 5944 |
result5_0, |
| 5945 |
result5_1, |
| 5946 |
result5_2, |
| 5947 |
result5_3, |
| 5948 |
result5_4, |
| 5949 |
result5_5, |
| 5950 |
result5_6, |
| 5951 |
result5_7, |
| 5952 |
result5_8, |
| 5953 |
result5_9, |
| 5954 |
result5_10, |
| 5955 |
result5_11, |
| 5956 |
) = match local_address { |
| 5957 |
V4::Ipv4(e) => { |
| 5958 |
let super::super::super::wasi::sockets::network::Ipv4SocketAddress { |
| 5959 |
port: port0, |
| 5960 |
address: address0, |
| 5961 |
} = e; |
| 5962 |
let (t1_0, t1_1, t1_2, t1_3) = address0; |
| 5963 |
( |
| 5964 |
0i32, |
| 5965 |
_rt::as_i32(port0), |
| 5966 |
_rt::as_i32(t1_0), |
| 5967 |
_rt::as_i32(t1_1), |
| 5968 |
_rt::as_i32(t1_2), |
| 5969 |
_rt::as_i32(t1_3), |
| 5970 |
0i32, |
| 5971 |
0i32, |
| 5972 |
0i32, |
| 5973 |
0i32, |
| 5974 |
0i32, |
| 5975 |
0i32, |
| 5976 |
) |
| 5977 |
} |
| 5978 |
V4::Ipv6(e) => { |
| 5979 |
let super::super::super::wasi::sockets::network::Ipv6SocketAddress { |
| 5980 |
port: port2, |
| 5981 |
flow_info: flow_info2, |
| 5982 |
address: address2, |
| 5983 |
scope_id: scope_id2, |
| 5984 |
} = e; |
| 5985 |
let (t3_0, t3_1, t3_2, t3_3, t3_4, t3_5, t3_6, t3_7) = address2; |
| 5986 |
( |
| 5987 |
1i32, |
| 5988 |
_rt::as_i32(port2), |
| 5989 |
_rt::as_i32(flow_info2), |
| 5990 |
_rt::as_i32(t3_0), |
| 5991 |
_rt::as_i32(t3_1), |
| 5992 |
_rt::as_i32(t3_2), |
| 5993 |
_rt::as_i32(t3_3), |
| 5994 |
_rt::as_i32(t3_4), |
| 5995 |
_rt::as_i32(t3_5), |
| 5996 |
_rt::as_i32(t3_6), |
| 5997 |
_rt::as_i32(t3_7), |
| 5998 |
_rt::as_i32(scope_id2), |
| 5999 |
) |
| 6000 |
} |
| 6001 |
}; |
| 6002 |
let ptr6 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 6003 |
#[cfg(target_arch = "wasm32")] |
| 6004 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 6005 |
unsafe extern "C" { |
| 6006 |
#[link_name = "[method]udp-socket.start-bind"] |
| 6007 |
fn wit_import7( |
| 6008 |
_: i32, |
| 6009 |
_: i32, |
| 6010 |
_: i32, |
| 6011 |
_: i32, |
| 6012 |
_: i32, |
| 6013 |
_: i32, |
| 6014 |
_: i32, |
| 6015 |
_: i32, |
| 6016 |
_: i32, |
| 6017 |
_: i32, |
| 6018 |
_: i32, |
| 6019 |
_: i32, |
| 6020 |
_: i32, |
| 6021 |
_: i32, |
| 6022 |
_: *mut u8, |
| 6023 |
); |
| 6024 |
} |
| 6025 |
#[cfg(not(target_arch = "wasm32"))] |
| 6026 |
unsafe extern "C" fn wit_import7( |
| 6027 |
_: i32, |
| 6028 |
_: i32, |
| 6029 |
_: i32, |
| 6030 |
_: i32, |
| 6031 |
_: i32, |
| 6032 |
_: i32, |
| 6033 |
_: i32, |
| 6034 |
_: i32, |
| 6035 |
_: i32, |
| 6036 |
_: i32, |
| 6037 |
_: i32, |
| 6038 |
_: i32, |
| 6039 |
_: i32, |
| 6040 |
_: i32, |
| 6041 |
_: *mut u8, |
| 6042 |
) { |
| 6043 |
unreachable!() |
| 6044 |
} |
| 6045 |
wit_import7( |
| 6046 |
(self).handle() as i32, |
| 6047 |
(network).handle() as i32, |
| 6048 |
result5_0, |
| 6049 |
result5_1, |
| 6050 |
result5_2, |
| 6051 |
result5_3, |
| 6052 |
result5_4, |
| 6053 |
result5_5, |
| 6054 |
result5_6, |
| 6055 |
result5_7, |
| 6056 |
result5_8, |
| 6057 |
result5_9, |
| 6058 |
result5_10, |
| 6059 |
result5_11, |
| 6060 |
ptr6, |
| 6061 |
); |
| 6062 |
let l8 = i32::from(*ptr6.add(0).cast::<u8>()); |
| 6063 |
let result10 = match l8 { |
| 6064 |
0 => { |
| 6065 |
let e = (); |
| 6066 |
Ok(e) |
| 6067 |
} |
| 6068 |
1 => { |
| 6069 |
let e = { |
| 6070 |
let l9 = i32::from(*ptr6.add(1).cast::<u8>()); |
| 6071 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 6072 |
l9 as u8, |
| 6073 |
) |
| 6074 |
}; |
| 6075 |
Err(e) |
| 6076 |
} |
| 6077 |
_ => _rt::invalid_enum_discriminant(), |
| 6078 |
}; |
| 6079 |
result10 |
| 6080 |
} |
| 6081 |
} |
| 6082 |
} |
| 6083 |
impl UdpSocket { |
| 6084 |
#[allow(unused_unsafe, clippy::all)] |
| 6085 |
#[allow(async_fn_in_trait)] |
| 6086 |
pub fn finish_bind(&self) -> Result<(), ErrorCode> { |
| 6087 |
unsafe { |
| 6088 |
#[repr(align(1))] |
| 6089 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 6090 |
let mut ret_area = RetArea( |
| 6091 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 6092 |
); |
| 6093 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 6094 |
#[cfg(target_arch = "wasm32")] |
| 6095 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 6096 |
unsafe extern "C" { |
| 6097 |
#[link_name = "[method]udp-socket.finish-bind"] |
| 6098 |
fn wit_import1(_: i32, _: *mut u8); |
| 6099 |
} |
| 6100 |
#[cfg(not(target_arch = "wasm32"))] |
| 6101 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 6102 |
unreachable!() |
| 6103 |
} |
| 6104 |
wit_import1((self).handle() as i32, ptr0); |
| 6105 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 6106 |
let result4 = match l2 { |
| 6107 |
0 => { |
| 6108 |
let e = (); |
| 6109 |
Ok(e) |
| 6110 |
} |
| 6111 |
1 => { |
| 6112 |
let e = { |
| 6113 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 6114 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 6115 |
l3 as u8, |
| 6116 |
) |
| 6117 |
}; |
| 6118 |
Err(e) |
| 6119 |
} |
| 6120 |
_ => _rt::invalid_enum_discriminant(), |
| 6121 |
}; |
| 6122 |
result4 |
| 6123 |
} |
| 6124 |
} |
| 6125 |
} |
| 6126 |
impl UdpSocket { |
| 6127 |
#[allow(unused_unsafe, clippy::all)] |
| 6128 |
/// Set up inbound & outbound communication channels, optionally to a specific peer. |
| 6129 |
/// |
| 6130 |
/// This function only changes the local socket configuration and does not generate any network traffic. |
| 6131 |
/// On success, the `remote-address` of the socket is updated. The `local-address` may be updated as well, |
| 6132 |
/// based on the best network path to `remote-address`. |
| 6133 |
/// |
| 6134 |
/// When a `remote-address` is provided, the returned streams are limited to communicating with that specific peer: |
| 6135 |
/// - `send` can only be used to send to this destination. |
| 6136 |
/// - `receive` will only return datagrams sent from the provided `remote-address`. |
| 6137 |
/// |
| 6138 |
/// This method may be called multiple times on the same socket to change its association, but |
| 6139 |
/// only the most recently returned pair of streams will be operational. Implementations may trap if |
| 6140 |
/// the streams returned by a previous invocation haven't been dropped yet before calling `stream` again. |
| 6141 |
/// |
| 6142 |
/// The POSIX equivalent in pseudo-code is: |
| 6143 |
/// ```text |
| 6144 |
/// if (was previously connected) { |
| 6145 |
/// connect(s, AF_UNSPEC) |
| 6146 |
/// } |
| 6147 |
/// if (remote_address is Some) { |
| 6148 |
/// connect(s, remote_address) |
| 6149 |
/// } |
| 6150 |
/// ``` |
| 6151 |
/// |
| 6152 |
/// Unlike in POSIX, the socket must already be explicitly bound. |
| 6153 |
/// |
| 6154 |
/// # Typical errors |
| 6155 |
/// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) |
| 6156 |
/// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) |
| 6157 |
/// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) |
| 6158 |
/// - `invalid-state`: The socket is not bound. |
| 6159 |
/// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) |
| 6160 |
/// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) |
| 6161 |
/// - `connection-refused`: The connection was refused. (ECONNREFUSED) |
| 6162 |
/// |
| 6163 |
/// # References |
| 6164 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html> |
| 6165 |
/// - <https://man7.org/linux/man-pages/man2/connect.2.html> |
| 6166 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect> |
| 6167 |
/// - <https://man.freebsd.org/cgi/man.cgi?connect> |
| 6168 |
#[allow(async_fn_in_trait)] |
| 6169 |
pub fn stream( |
| 6170 |
&self, |
| 6171 |
remote_address: Option<IpSocketAddress>, |
| 6172 |
) -> Result< |
| 6173 |
(IncomingDatagramStream, OutgoingDatagramStream), |
| 6174 |
ErrorCode, |
| 6175 |
> { |
| 6176 |
unsafe { |
| 6177 |
#[repr(align(4))] |
| 6178 |
struct RetArea([::core::mem::MaybeUninit<u8>; 12]); |
| 6179 |
let mut ret_area = RetArea( |
| 6180 |
[::core::mem::MaybeUninit::uninit(); 12], |
| 6181 |
); |
| 6182 |
let ( |
| 6183 |
result6_0, |
| 6184 |
result6_1, |
| 6185 |
result6_2, |
| 6186 |
result6_3, |
| 6187 |
result6_4, |
| 6188 |
result6_5, |
| 6189 |
result6_6, |
| 6190 |
result6_7, |
| 6191 |
result6_8, |
| 6192 |
result6_9, |
| 6193 |
result6_10, |
| 6194 |
result6_11, |
| 6195 |
result6_12, |
| 6196 |
) = match remote_address { |
| 6197 |
Some(e) => { |
| 6198 |
use super::super::super::wasi::sockets::network::IpSocketAddress as V4; |
| 6199 |
let ( |
| 6200 |
result5_0, |
| 6201 |
result5_1, |
| 6202 |
result5_2, |
| 6203 |
result5_3, |
| 6204 |
result5_4, |
| 6205 |
result5_5, |
| 6206 |
result5_6, |
| 6207 |
result5_7, |
| 6208 |
result5_8, |
| 6209 |
result5_9, |
| 6210 |
result5_10, |
| 6211 |
result5_11, |
| 6212 |
) = match e { |
| 6213 |
V4::Ipv4(e) => { |
| 6214 |
let super::super::super::wasi::sockets::network::Ipv4SocketAddress { |
| 6215 |
port: port0, |
| 6216 |
address: address0, |
| 6217 |
} = e; |
| 6218 |
let (t1_0, t1_1, t1_2, t1_3) = address0; |
| 6219 |
( |
| 6220 |
0i32, |
| 6221 |
_rt::as_i32(port0), |
| 6222 |
_rt::as_i32(t1_0), |
| 6223 |
_rt::as_i32(t1_1), |
| 6224 |
_rt::as_i32(t1_2), |
| 6225 |
_rt::as_i32(t1_3), |
| 6226 |
0i32, |
| 6227 |
0i32, |
| 6228 |
0i32, |
| 6229 |
0i32, |
| 6230 |
0i32, |
| 6231 |
0i32, |
| 6232 |
) |
| 6233 |
} |
| 6234 |
V4::Ipv6(e) => { |
| 6235 |
let super::super::super::wasi::sockets::network::Ipv6SocketAddress { |
| 6236 |
port: port2, |
| 6237 |
flow_info: flow_info2, |
| 6238 |
address: address2, |
| 6239 |
scope_id: scope_id2, |
| 6240 |
} = e; |
| 6241 |
let (t3_0, t3_1, t3_2, t3_3, t3_4, t3_5, t3_6, t3_7) = address2; |
| 6242 |
( |
| 6243 |
1i32, |
| 6244 |
_rt::as_i32(port2), |
| 6245 |
_rt::as_i32(flow_info2), |
| 6246 |
_rt::as_i32(t3_0), |
| 6247 |
_rt::as_i32(t3_1), |
| 6248 |
_rt::as_i32(t3_2), |
| 6249 |
_rt::as_i32(t3_3), |
| 6250 |
_rt::as_i32(t3_4), |
| 6251 |
_rt::as_i32(t3_5), |
| 6252 |
_rt::as_i32(t3_6), |
| 6253 |
_rt::as_i32(t3_7), |
| 6254 |
_rt::as_i32(scope_id2), |
| 6255 |
) |
| 6256 |
} |
| 6257 |
}; |
| 6258 |
( |
| 6259 |
1i32, |
| 6260 |
result5_0, |
| 6261 |
result5_1, |
| 6262 |
result5_2, |
| 6263 |
result5_3, |
| 6264 |
result5_4, |
| 6265 |
result5_5, |
| 6266 |
result5_6, |
| 6267 |
result5_7, |
| 6268 |
result5_8, |
| 6269 |
result5_9, |
| 6270 |
result5_10, |
| 6271 |
result5_11, |
| 6272 |
) |
| 6273 |
} |
| 6274 |
None => { |
| 6275 |
( |
| 6276 |
0i32, |
| 6277 |
0i32, |
| 6278 |
0i32, |
| 6279 |
0i32, |
| 6280 |
0i32, |
| 6281 |
0i32, |
| 6282 |
0i32, |
| 6283 |
0i32, |
| 6284 |
0i32, |
| 6285 |
0i32, |
| 6286 |
0i32, |
| 6287 |
0i32, |
| 6288 |
0i32, |
| 6289 |
) |
| 6290 |
} |
| 6291 |
}; |
| 6292 |
let ptr7 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 6293 |
#[cfg(target_arch = "wasm32")] |
| 6294 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 6295 |
unsafe extern "C" { |
| 6296 |
#[link_name = "[method]udp-socket.stream"] |
| 6297 |
fn wit_import8( |
| 6298 |
_: i32, |
| 6299 |
_: i32, |
| 6300 |
_: i32, |
| 6301 |
_: i32, |
| 6302 |
_: i32, |
| 6303 |
_: i32, |
| 6304 |
_: i32, |
| 6305 |
_: i32, |
| 6306 |
_: i32, |
| 6307 |
_: i32, |
| 6308 |
_: i32, |
| 6309 |
_: i32, |
| 6310 |
_: i32, |
| 6311 |
_: i32, |
| 6312 |
_: *mut u8, |
| 6313 |
); |
| 6314 |
} |
| 6315 |
#[cfg(not(target_arch = "wasm32"))] |
| 6316 |
unsafe extern "C" fn wit_import8( |
| 6317 |
_: i32, |
| 6318 |
_: i32, |
| 6319 |
_: i32, |
| 6320 |
_: i32, |
| 6321 |
_: i32, |
| 6322 |
_: i32, |
| 6323 |
_: i32, |
| 6324 |
_: i32, |
| 6325 |
_: i32, |
| 6326 |
_: i32, |
| 6327 |
_: i32, |
| 6328 |
_: i32, |
| 6329 |
_: i32, |
| 6330 |
_: i32, |
| 6331 |
_: *mut u8, |
| 6332 |
) { |
| 6333 |
unreachable!() |
| 6334 |
} |
| 6335 |
wit_import8( |
| 6336 |
(self).handle() as i32, |
| 6337 |
result6_0, |
| 6338 |
result6_1, |
| 6339 |
result6_2, |
| 6340 |
result6_3, |
| 6341 |
result6_4, |
| 6342 |
result6_5, |
| 6343 |
result6_6, |
| 6344 |
result6_7, |
| 6345 |
result6_8, |
| 6346 |
result6_9, |
| 6347 |
result6_10, |
| 6348 |
result6_11, |
| 6349 |
result6_12, |
| 6350 |
ptr7, |
| 6351 |
); |
| 6352 |
let l9 = i32::from(*ptr7.add(0).cast::<u8>()); |
| 6353 |
let result13 = match l9 { |
| 6354 |
0 => { |
| 6355 |
let e = { |
| 6356 |
let l10 = *ptr7.add(4).cast::<i32>(); |
| 6357 |
let l11 = *ptr7.add(8).cast::<i32>(); |
| 6358 |
( |
| 6359 |
IncomingDatagramStream::from_handle(l10 as u32), |
| 6360 |
OutgoingDatagramStream::from_handle(l11 as u32), |
| 6361 |
) |
| 6362 |
}; |
| 6363 |
Ok(e) |
| 6364 |
} |
| 6365 |
1 => { |
| 6366 |
let e = { |
| 6367 |
let l12 = i32::from(*ptr7.add(4).cast::<u8>()); |
| 6368 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 6369 |
l12 as u8, |
| 6370 |
) |
| 6371 |
}; |
| 6372 |
Err(e) |
| 6373 |
} |
| 6374 |
_ => _rt::invalid_enum_discriminant(), |
| 6375 |
}; |
| 6376 |
result13 |
| 6377 |
} |
| 6378 |
} |
| 6379 |
} |
| 6380 |
impl UdpSocket { |
| 6381 |
#[allow(unused_unsafe, clippy::all)] |
| 6382 |
/// Get the current bound address. |
| 6383 |
/// |
| 6384 |
/// POSIX mentions: |
| 6385 |
/// > If the socket has not been bound to a local name, the value |
| 6386 |
/// > stored in the object pointed to by `address` is unspecified. |
| 6387 |
/// |
| 6388 |
/// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. |
| 6389 |
/// |
| 6390 |
/// # Typical errors |
| 6391 |
/// - `invalid-state`: The socket is not bound to any local address. |
| 6392 |
/// |
| 6393 |
/// # References |
| 6394 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html> |
| 6395 |
/// - <https://man7.org/linux/man-pages/man2/getsockname.2.html> |
| 6396 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getsockname> |
| 6397 |
/// - <https://man.freebsd.org/cgi/man.cgi?getsockname> |
| 6398 |
#[allow(async_fn_in_trait)] |
| 6399 |
pub fn local_address(&self) -> Result<IpSocketAddress, ErrorCode> { |
| 6400 |
unsafe { |
| 6401 |
#[repr(align(4))] |
| 6402 |
struct RetArea([::core::mem::MaybeUninit<u8>; 36]); |
| 6403 |
let mut ret_area = RetArea( |
| 6404 |
[::core::mem::MaybeUninit::uninit(); 36], |
| 6405 |
); |
| 6406 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 6407 |
#[cfg(target_arch = "wasm32")] |
| 6408 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 6409 |
unsafe extern "C" { |
| 6410 |
#[link_name = "[method]udp-socket.local-address"] |
| 6411 |
fn wit_import1(_: i32, _: *mut u8); |
| 6412 |
} |
| 6413 |
#[cfg(not(target_arch = "wasm32"))] |
| 6414 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 6415 |
unreachable!() |
| 6416 |
} |
| 6417 |
wit_import1((self).handle() as i32, ptr0); |
| 6418 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 6419 |
let result22 = match l2 { |
| 6420 |
0 => { |
| 6421 |
let e = { |
| 6422 |
let l3 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 6423 |
use super::super::super::wasi::sockets::network::IpSocketAddress as V20; |
| 6424 |
let v20 = match l3 { |
| 6425 |
0 => { |
| 6426 |
let e20 = { |
| 6427 |
let l4 = i32::from(*ptr0.add(8).cast::<u16>()); |
| 6428 |
let l5 = i32::from(*ptr0.add(10).cast::<u8>()); |
| 6429 |
let l6 = i32::from(*ptr0.add(11).cast::<u8>()); |
| 6430 |
let l7 = i32::from(*ptr0.add(12).cast::<u8>()); |
| 6431 |
let l8 = i32::from(*ptr0.add(13).cast::<u8>()); |
| 6432 |
super::super::super::wasi::sockets::network::Ipv4SocketAddress { |
| 6433 |
port: l4 as u16, |
| 6434 |
address: (l5 as u8, l6 as u8, l7 as u8, l8 as u8), |
| 6435 |
} |
| 6436 |
}; |
| 6437 |
V20::Ipv4(e20) |
| 6438 |
} |
| 6439 |
n => { |
| 6440 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 6441 |
let e20 = { |
| 6442 |
let l9 = i32::from(*ptr0.add(8).cast::<u16>()); |
| 6443 |
let l10 = *ptr0.add(12).cast::<i32>(); |
| 6444 |
let l11 = i32::from(*ptr0.add(16).cast::<u16>()); |
| 6445 |
let l12 = i32::from(*ptr0.add(18).cast::<u16>()); |
| 6446 |
let l13 = i32::from(*ptr0.add(20).cast::<u16>()); |
| 6447 |
let l14 = i32::from(*ptr0.add(22).cast::<u16>()); |
| 6448 |
let l15 = i32::from(*ptr0.add(24).cast::<u16>()); |
| 6449 |
let l16 = i32::from(*ptr0.add(26).cast::<u16>()); |
| 6450 |
let l17 = i32::from(*ptr0.add(28).cast::<u16>()); |
| 6451 |
let l18 = i32::from(*ptr0.add(30).cast::<u16>()); |
| 6452 |
let l19 = *ptr0.add(32).cast::<i32>(); |
| 6453 |
super::super::super::wasi::sockets::network::Ipv6SocketAddress { |
| 6454 |
port: l9 as u16, |
| 6455 |
flow_info: l10 as u32, |
| 6456 |
address: ( |
| 6457 |
l11 as u16, |
| 6458 |
l12 as u16, |
| 6459 |
l13 as u16, |
| 6460 |
l14 as u16, |
| 6461 |
l15 as u16, |
| 6462 |
l16 as u16, |
| 6463 |
l17 as u16, |
| 6464 |
l18 as u16, |
| 6465 |
), |
| 6466 |
scope_id: l19 as u32, |
| 6467 |
} |
| 6468 |
}; |
| 6469 |
V20::Ipv6(e20) |
| 6470 |
} |
| 6471 |
}; |
| 6472 |
v20 |
| 6473 |
}; |
| 6474 |
Ok(e) |
| 6475 |
} |
| 6476 |
1 => { |
| 6477 |
let e = { |
| 6478 |
let l21 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 6479 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 6480 |
l21 as u8, |
| 6481 |
) |
| 6482 |
}; |
| 6483 |
Err(e) |
| 6484 |
} |
| 6485 |
_ => _rt::invalid_enum_discriminant(), |
| 6486 |
}; |
| 6487 |
result22 |
| 6488 |
} |
| 6489 |
} |
| 6490 |
} |
| 6491 |
impl UdpSocket { |
| 6492 |
#[allow(unused_unsafe, clippy::all)] |
| 6493 |
/// Get the address the socket is currently streaming to. |
| 6494 |
/// |
| 6495 |
/// # Typical errors |
| 6496 |
/// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN) |
| 6497 |
/// |
| 6498 |
/// # References |
| 6499 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html> |
| 6500 |
/// - <https://man7.org/linux/man-pages/man2/getpeername.2.html> |
| 6501 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getpeername> |
| 6502 |
/// - <https://man.freebsd.org/cgi/man.cgi?query=getpeername&sektion=2&n=1> |
| 6503 |
#[allow(async_fn_in_trait)] |
| 6504 |
pub fn remote_address(&self) -> Result<IpSocketAddress, ErrorCode> { |
| 6505 |
unsafe { |
| 6506 |
#[repr(align(4))] |
| 6507 |
struct RetArea([::core::mem::MaybeUninit<u8>; 36]); |
| 6508 |
let mut ret_area = RetArea( |
| 6509 |
[::core::mem::MaybeUninit::uninit(); 36], |
| 6510 |
); |
| 6511 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 6512 |
#[cfg(target_arch = "wasm32")] |
| 6513 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 6514 |
unsafe extern "C" { |
| 6515 |
#[link_name = "[method]udp-socket.remote-address"] |
| 6516 |
fn wit_import1(_: i32, _: *mut u8); |
| 6517 |
} |
| 6518 |
#[cfg(not(target_arch = "wasm32"))] |
| 6519 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 6520 |
unreachable!() |
| 6521 |
} |
| 6522 |
wit_import1((self).handle() as i32, ptr0); |
| 6523 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 6524 |
let result22 = match l2 { |
| 6525 |
0 => { |
| 6526 |
let e = { |
| 6527 |
let l3 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 6528 |
use super::super::super::wasi::sockets::network::IpSocketAddress as V20; |
| 6529 |
let v20 = match l3 { |
| 6530 |
0 => { |
| 6531 |
let e20 = { |
| 6532 |
let l4 = i32::from(*ptr0.add(8).cast::<u16>()); |
| 6533 |
let l5 = i32::from(*ptr0.add(10).cast::<u8>()); |
| 6534 |
let l6 = i32::from(*ptr0.add(11).cast::<u8>()); |
| 6535 |
let l7 = i32::from(*ptr0.add(12).cast::<u8>()); |
| 6536 |
let l8 = i32::from(*ptr0.add(13).cast::<u8>()); |
| 6537 |
super::super::super::wasi::sockets::network::Ipv4SocketAddress { |
| 6538 |
port: l4 as u16, |
| 6539 |
address: (l5 as u8, l6 as u8, l7 as u8, l8 as u8), |
| 6540 |
} |
| 6541 |
}; |
| 6542 |
V20::Ipv4(e20) |
| 6543 |
} |
| 6544 |
n => { |
| 6545 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 6546 |
let e20 = { |
| 6547 |
let l9 = i32::from(*ptr0.add(8).cast::<u16>()); |
| 6548 |
let l10 = *ptr0.add(12).cast::<i32>(); |
| 6549 |
let l11 = i32::from(*ptr0.add(16).cast::<u16>()); |
| 6550 |
let l12 = i32::from(*ptr0.add(18).cast::<u16>()); |
| 6551 |
let l13 = i32::from(*ptr0.add(20).cast::<u16>()); |
| 6552 |
let l14 = i32::from(*ptr0.add(22).cast::<u16>()); |
| 6553 |
let l15 = i32::from(*ptr0.add(24).cast::<u16>()); |
| 6554 |
let l16 = i32::from(*ptr0.add(26).cast::<u16>()); |
| 6555 |
let l17 = i32::from(*ptr0.add(28).cast::<u16>()); |
| 6556 |
let l18 = i32::from(*ptr0.add(30).cast::<u16>()); |
| 6557 |
let l19 = *ptr0.add(32).cast::<i32>(); |
| 6558 |
super::super::super::wasi::sockets::network::Ipv6SocketAddress { |
| 6559 |
port: l9 as u16, |
| 6560 |
flow_info: l10 as u32, |
| 6561 |
address: ( |
| 6562 |
l11 as u16, |
| 6563 |
l12 as u16, |
| 6564 |
l13 as u16, |
| 6565 |
l14 as u16, |
| 6566 |
l15 as u16, |
| 6567 |
l16 as u16, |
| 6568 |
l17 as u16, |
| 6569 |
l18 as u16, |
| 6570 |
), |
| 6571 |
scope_id: l19 as u32, |
| 6572 |
} |
| 6573 |
}; |
| 6574 |
V20::Ipv6(e20) |
| 6575 |
} |
| 6576 |
}; |
| 6577 |
v20 |
| 6578 |
}; |
| 6579 |
Ok(e) |
| 6580 |
} |
| 6581 |
1 => { |
| 6582 |
let e = { |
| 6583 |
let l21 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 6584 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 6585 |
l21 as u8, |
| 6586 |
) |
| 6587 |
}; |
| 6588 |
Err(e) |
| 6589 |
} |
| 6590 |
_ => _rt::invalid_enum_discriminant(), |
| 6591 |
}; |
| 6592 |
result22 |
| 6593 |
} |
| 6594 |
} |
| 6595 |
} |
| 6596 |
impl UdpSocket { |
| 6597 |
#[allow(unused_unsafe, clippy::all)] |
| 6598 |
/// Whether this is a IPv4 or IPv6 socket. |
| 6599 |
/// |
| 6600 |
/// Equivalent to the SO_DOMAIN socket option. |
| 6601 |
#[allow(async_fn_in_trait)] |
| 6602 |
pub fn address_family(&self) -> IpAddressFamily { |
| 6603 |
unsafe { |
| 6604 |
#[cfg(target_arch = "wasm32")] |
| 6605 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 6606 |
unsafe extern "C" { |
| 6607 |
#[link_name = "[method]udp-socket.address-family"] |
| 6608 |
fn wit_import0(_: i32) -> i32; |
| 6609 |
} |
| 6610 |
#[cfg(not(target_arch = "wasm32"))] |
| 6611 |
unsafe extern "C" fn wit_import0(_: i32) -> i32 { |
| 6612 |
unreachable!() |
| 6613 |
} |
| 6614 |
let ret = wit_import0((self).handle() as i32); |
| 6615 |
super::super::super::wasi::sockets::network::IpAddressFamily::_lift( |
| 6616 |
ret as u8, |
| 6617 |
) |
| 6618 |
} |
| 6619 |
} |
| 6620 |
} |
| 6621 |
impl UdpSocket { |
| 6622 |
#[allow(unused_unsafe, clippy::all)] |
| 6623 |
/// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. |
| 6624 |
/// |
| 6625 |
/// If the provided value is 0, an `invalid-argument` error is returned. |
| 6626 |
/// |
| 6627 |
/// # Typical errors |
| 6628 |
/// - `invalid-argument`: (set) The TTL value must be 1 or higher. |
| 6629 |
#[allow(async_fn_in_trait)] |
| 6630 |
pub fn unicast_hop_limit(&self) -> Result<u8, ErrorCode> { |
| 6631 |
unsafe { |
| 6632 |
#[repr(align(1))] |
| 6633 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 6634 |
let mut ret_area = RetArea( |
| 6635 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 6636 |
); |
| 6637 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 6638 |
#[cfg(target_arch = "wasm32")] |
| 6639 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 6640 |
unsafe extern "C" { |
| 6641 |
#[link_name = "[method]udp-socket.unicast-hop-limit"] |
| 6642 |
fn wit_import1(_: i32, _: *mut u8); |
| 6643 |
} |
| 6644 |
#[cfg(not(target_arch = "wasm32"))] |
| 6645 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 6646 |
unreachable!() |
| 6647 |
} |
| 6648 |
wit_import1((self).handle() as i32, ptr0); |
| 6649 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 6650 |
let result5 = match l2 { |
| 6651 |
0 => { |
| 6652 |
let e = { |
| 6653 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 6654 |
l3 as u8 |
| 6655 |
}; |
| 6656 |
Ok(e) |
| 6657 |
} |
| 6658 |
1 => { |
| 6659 |
let e = { |
| 6660 |
let l4 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 6661 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 6662 |
l4 as u8, |
| 6663 |
) |
| 6664 |
}; |
| 6665 |
Err(e) |
| 6666 |
} |
| 6667 |
_ => _rt::invalid_enum_discriminant(), |
| 6668 |
}; |
| 6669 |
result5 |
| 6670 |
} |
| 6671 |
} |
| 6672 |
} |
| 6673 |
impl UdpSocket { |
| 6674 |
#[allow(unused_unsafe, clippy::all)] |
| 6675 |
#[allow(async_fn_in_trait)] |
| 6676 |
pub fn set_unicast_hop_limit(&self, value: u8) -> Result<(), ErrorCode> { |
| 6677 |
unsafe { |
| 6678 |
#[repr(align(1))] |
| 6679 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 6680 |
let mut ret_area = RetArea( |
| 6681 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 6682 |
); |
| 6683 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 6684 |
#[cfg(target_arch = "wasm32")] |
| 6685 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 6686 |
unsafe extern "C" { |
| 6687 |
#[link_name = "[method]udp-socket.set-unicast-hop-limit"] |
| 6688 |
fn wit_import1(_: i32, _: i32, _: *mut u8); |
| 6689 |
} |
| 6690 |
#[cfg(not(target_arch = "wasm32"))] |
| 6691 |
unsafe extern "C" fn wit_import1(_: i32, _: i32, _: *mut u8) { |
| 6692 |
unreachable!() |
| 6693 |
} |
| 6694 |
wit_import1((self).handle() as i32, _rt::as_i32(&value), ptr0); |
| 6695 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 6696 |
let result4 = match l2 { |
| 6697 |
0 => { |
| 6698 |
let e = (); |
| 6699 |
Ok(e) |
| 6700 |
} |
| 6701 |
1 => { |
| 6702 |
let e = { |
| 6703 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 6704 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 6705 |
l3 as u8, |
| 6706 |
) |
| 6707 |
}; |
| 6708 |
Err(e) |
| 6709 |
} |
| 6710 |
_ => _rt::invalid_enum_discriminant(), |
| 6711 |
}; |
| 6712 |
result4 |
| 6713 |
} |
| 6714 |
} |
| 6715 |
} |
| 6716 |
impl UdpSocket { |
| 6717 |
#[allow(unused_unsafe, clippy::all)] |
| 6718 |
/// The kernel buffer space reserved for sends/receives on this socket. |
| 6719 |
/// |
| 6720 |
/// If the provided value is 0, an `invalid-argument` error is returned. |
| 6721 |
/// Any other value will never cause an error, but it might be silently clamped and/or rounded. |
| 6722 |
/// I.e. after setting a value, reading the same setting back may return a different value. |
| 6723 |
/// |
| 6724 |
/// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. |
| 6725 |
/// |
| 6726 |
/// # Typical errors |
| 6727 |
/// - `invalid-argument`: (set) The provided value was 0. |
| 6728 |
#[allow(async_fn_in_trait)] |
| 6729 |
pub fn receive_buffer_size(&self) -> Result<u64, ErrorCode> { |
| 6730 |
unsafe { |
| 6731 |
#[repr(align(8))] |
| 6732 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 6733 |
let mut ret_area = RetArea( |
| 6734 |
[::core::mem::MaybeUninit::uninit(); 16], |
| 6735 |
); |
| 6736 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 6737 |
#[cfg(target_arch = "wasm32")] |
| 6738 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 6739 |
unsafe extern "C" { |
| 6740 |
#[link_name = "[method]udp-socket.receive-buffer-size"] |
| 6741 |
fn wit_import1(_: i32, _: *mut u8); |
| 6742 |
} |
| 6743 |
#[cfg(not(target_arch = "wasm32"))] |
| 6744 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 6745 |
unreachable!() |
| 6746 |
} |
| 6747 |
wit_import1((self).handle() as i32, ptr0); |
| 6748 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 6749 |
let result5 = match l2 { |
| 6750 |
0 => { |
| 6751 |
let e = { |
| 6752 |
let l3 = *ptr0.add(8).cast::<i64>(); |
| 6753 |
l3 as u64 |
| 6754 |
}; |
| 6755 |
Ok(e) |
| 6756 |
} |
| 6757 |
1 => { |
| 6758 |
let e = { |
| 6759 |
let l4 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 6760 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 6761 |
l4 as u8, |
| 6762 |
) |
| 6763 |
}; |
| 6764 |
Err(e) |
| 6765 |
} |
| 6766 |
_ => _rt::invalid_enum_discriminant(), |
| 6767 |
}; |
| 6768 |
result5 |
| 6769 |
} |
| 6770 |
} |
| 6771 |
} |
| 6772 |
impl UdpSocket { |
| 6773 |
#[allow(unused_unsafe, clippy::all)] |
| 6774 |
#[allow(async_fn_in_trait)] |
| 6775 |
pub fn set_receive_buffer_size( |
| 6776 |
&self, |
| 6777 |
value: u64, |
| 6778 |
) -> Result<(), ErrorCode> { |
| 6779 |
unsafe { |
| 6780 |
#[repr(align(1))] |
| 6781 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 6782 |
let mut ret_area = RetArea( |
| 6783 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 6784 |
); |
| 6785 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 6786 |
#[cfg(target_arch = "wasm32")] |
| 6787 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 6788 |
unsafe extern "C" { |
| 6789 |
#[link_name = "[method]udp-socket.set-receive-buffer-size"] |
| 6790 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 6791 |
} |
| 6792 |
#[cfg(not(target_arch = "wasm32"))] |
| 6793 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 6794 |
unreachable!() |
| 6795 |
} |
| 6796 |
wit_import1((self).handle() as i32, _rt::as_i64(&value), ptr0); |
| 6797 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 6798 |
let result4 = match l2 { |
| 6799 |
0 => { |
| 6800 |
let e = (); |
| 6801 |
Ok(e) |
| 6802 |
} |
| 6803 |
1 => { |
| 6804 |
let e = { |
| 6805 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 6806 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 6807 |
l3 as u8, |
| 6808 |
) |
| 6809 |
}; |
| 6810 |
Err(e) |
| 6811 |
} |
| 6812 |
_ => _rt::invalid_enum_discriminant(), |
| 6813 |
}; |
| 6814 |
result4 |
| 6815 |
} |
| 6816 |
} |
| 6817 |
} |
| 6818 |
impl UdpSocket { |
| 6819 |
#[allow(unused_unsafe, clippy::all)] |
| 6820 |
#[allow(async_fn_in_trait)] |
| 6821 |
pub fn send_buffer_size(&self) -> Result<u64, ErrorCode> { |
| 6822 |
unsafe { |
| 6823 |
#[repr(align(8))] |
| 6824 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 6825 |
let mut ret_area = RetArea( |
| 6826 |
[::core::mem::MaybeUninit::uninit(); 16], |
| 6827 |
); |
| 6828 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 6829 |
#[cfg(target_arch = "wasm32")] |
| 6830 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 6831 |
unsafe extern "C" { |
| 6832 |
#[link_name = "[method]udp-socket.send-buffer-size"] |
| 6833 |
fn wit_import1(_: i32, _: *mut u8); |
| 6834 |
} |
| 6835 |
#[cfg(not(target_arch = "wasm32"))] |
| 6836 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 6837 |
unreachable!() |
| 6838 |
} |
| 6839 |
wit_import1((self).handle() as i32, ptr0); |
| 6840 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 6841 |
let result5 = match l2 { |
| 6842 |
0 => { |
| 6843 |
let e = { |
| 6844 |
let l3 = *ptr0.add(8).cast::<i64>(); |
| 6845 |
l3 as u64 |
| 6846 |
}; |
| 6847 |
Ok(e) |
| 6848 |
} |
| 6849 |
1 => { |
| 6850 |
let e = { |
| 6851 |
let l4 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 6852 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 6853 |
l4 as u8, |
| 6854 |
) |
| 6855 |
}; |
| 6856 |
Err(e) |
| 6857 |
} |
| 6858 |
_ => _rt::invalid_enum_discriminant(), |
| 6859 |
}; |
| 6860 |
result5 |
| 6861 |
} |
| 6862 |
} |
| 6863 |
} |
| 6864 |
impl UdpSocket { |
| 6865 |
#[allow(unused_unsafe, clippy::all)] |
| 6866 |
#[allow(async_fn_in_trait)] |
| 6867 |
pub fn set_send_buffer_size(&self, value: u64) -> Result<(), ErrorCode> { |
| 6868 |
unsafe { |
| 6869 |
#[repr(align(1))] |
| 6870 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 6871 |
let mut ret_area = RetArea( |
| 6872 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 6873 |
); |
| 6874 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 6875 |
#[cfg(target_arch = "wasm32")] |
| 6876 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 6877 |
unsafe extern "C" { |
| 6878 |
#[link_name = "[method]udp-socket.set-send-buffer-size"] |
| 6879 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 6880 |
} |
| 6881 |
#[cfg(not(target_arch = "wasm32"))] |
| 6882 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 6883 |
unreachable!() |
| 6884 |
} |
| 6885 |
wit_import1((self).handle() as i32, _rt::as_i64(&value), ptr0); |
| 6886 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 6887 |
let result4 = match l2 { |
| 6888 |
0 => { |
| 6889 |
let e = (); |
| 6890 |
Ok(e) |
| 6891 |
} |
| 6892 |
1 => { |
| 6893 |
let e = { |
| 6894 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 6895 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 6896 |
l3 as u8, |
| 6897 |
) |
| 6898 |
}; |
| 6899 |
Err(e) |
| 6900 |
} |
| 6901 |
_ => _rt::invalid_enum_discriminant(), |
| 6902 |
}; |
| 6903 |
result4 |
| 6904 |
} |
| 6905 |
} |
| 6906 |
} |
| 6907 |
impl UdpSocket { |
| 6908 |
#[allow(unused_unsafe, clippy::all)] |
| 6909 |
/// Create a `pollable` which will resolve once the socket is ready for I/O. |
| 6910 |
/// |
| 6911 |
/// Note: this function is here for WASI 0.2 only. |
| 6912 |
/// It's planned to be removed when `future` is natively supported in Preview3. |
| 6913 |
#[allow(async_fn_in_trait)] |
| 6914 |
pub fn subscribe(&self) -> Pollable { |
| 6915 |
unsafe { |
| 6916 |
#[cfg(target_arch = "wasm32")] |
| 6917 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 6918 |
unsafe extern "C" { |
| 6919 |
#[link_name = "[method]udp-socket.subscribe"] |
| 6920 |
fn wit_import0(_: i32) -> i32; |
| 6921 |
} |
| 6922 |
#[cfg(not(target_arch = "wasm32"))] |
| 6923 |
unsafe extern "C" fn wit_import0(_: i32) -> i32 { |
| 6924 |
unreachable!() |
| 6925 |
} |
| 6926 |
let ret = wit_import0((self).handle() as i32); |
| 6927 |
super::super::super::wasi::io::poll::Pollable::from_handle( |
| 6928 |
ret as u32, |
| 6929 |
) |
| 6930 |
} |
| 6931 |
} |
| 6932 |
} |
| 6933 |
impl IncomingDatagramStream { |
| 6934 |
#[allow(unused_unsafe, clippy::all)] |
| 6935 |
/// Receive messages on the socket. |
| 6936 |
/// |
| 6937 |
/// This function attempts to receive up to `max-results` datagrams on the socket without blocking. |
| 6938 |
/// The returned list may contain fewer elements than requested, but never more. |
| 6939 |
/// |
| 6940 |
/// This function returns successfully with an empty list when either: |
| 6941 |
/// - `max-results` is 0, or: |
| 6942 |
/// - `max-results` is greater than 0, but no results are immediately available. |
| 6943 |
/// This function never returns `error(would-block)`. |
| 6944 |
/// |
| 6945 |
/// # Typical errors |
| 6946 |
/// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) |
| 6947 |
/// - `connection-refused`: The connection was refused. (ECONNREFUSED) |
| 6948 |
/// |
| 6949 |
/// # References |
| 6950 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html> |
| 6951 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html> |
| 6952 |
/// - <https://man7.org/linux/man-pages/man2/recv.2.html> |
| 6953 |
/// - <https://man7.org/linux/man-pages/man2/recvmmsg.2.html> |
| 6954 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recv> |
| 6955 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recvfrom> |
| 6956 |
/// - <https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms741687(v=vs.85)> |
| 6957 |
/// - <https://man.freebsd.org/cgi/man.cgi?query=recv&sektion=2> |
| 6958 |
#[allow(async_fn_in_trait)] |
| 6959 |
pub fn receive( |
| 6960 |
&self, |
| 6961 |
max_results: u64, |
| 6962 |
) -> Result<_rt::Vec<IncomingDatagram>, ErrorCode> { |
| 6963 |
unsafe { |
| 6964 |
#[cfg_attr(target_pointer_width = "64", repr(align(8)))] |
| 6965 |
#[cfg_attr(target_pointer_width = "32", repr(align(4)))] |
| 6966 |
struct RetArea( |
| 6967 |
[::core::mem::MaybeUninit< |
| 6968 |
u8, |
| 6969 |
>; 3 * ::core::mem::size_of::<*const u8>()], |
| 6970 |
); |
| 6971 |
let mut ret_area = RetArea( |
| 6972 |
[::core::mem::MaybeUninit::uninit(); 3 |
| 6973 |
* ::core::mem::size_of::<*const u8>()], |
| 6974 |
); |
| 6975 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 6976 |
#[cfg(target_arch = "wasm32")] |
| 6977 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 6978 |
unsafe extern "C" { |
| 6979 |
#[link_name = "[method]incoming-datagram-stream.receive"] |
| 6980 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 6981 |
} |
| 6982 |
#[cfg(not(target_arch = "wasm32"))] |
| 6983 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 6984 |
unreachable!() |
| 6985 |
} |
| 6986 |
wit_import1( |
| 6987 |
(self).handle() as i32, |
| 6988 |
_rt::as_i64(&max_results), |
| 6989 |
ptr0, |
| 6990 |
); |
| 6991 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 6992 |
let result28 = match l2 { |
| 6993 |
0 => { |
| 6994 |
let e = { |
| 6995 |
let l3 = *ptr0 |
| 6996 |
.add(::core::mem::size_of::<*const u8>()) |
| 6997 |
.cast::<*mut u8>(); |
| 6998 |
let l4 = *ptr0 |
| 6999 |
.add(2 * ::core::mem::size_of::<*const u8>()) |
| 7000 |
.cast::<usize>(); |
| 7001 |
let base26 = l3; |
| 7002 |
let len26 = l4; |
| 7003 |
let mut result26 = _rt::Vec::with_capacity(len26); |
| 7004 |
for i in 0..len26 { |
| 7005 |
let base = base26 |
| 7006 |
.add(i * (32 + 2 * ::core::mem::size_of::<*const u8>())); |
| 7007 |
let e26 = { |
| 7008 |
let l5 = *base.add(0).cast::<*mut u8>(); |
| 7009 |
let l6 = *base |
| 7010 |
.add(::core::mem::size_of::<*const u8>()) |
| 7011 |
.cast::<usize>(); |
| 7012 |
let len7 = l6; |
| 7013 |
let l8 = i32::from( |
| 7014 |
*base |
| 7015 |
.add(2 * ::core::mem::size_of::<*const u8>()) |
| 7016 |
.cast::<u8>(), |
| 7017 |
); |
| 7018 |
use super::super::super::wasi::sockets::network::IpSocketAddress as V25; |
| 7019 |
let v25 = match l8 { |
| 7020 |
0 => { |
| 7021 |
let e25 = { |
| 7022 |
let l9 = i32::from( |
| 7023 |
*base |
| 7024 |
.add(4 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7025 |
.cast::<u16>(), |
| 7026 |
); |
| 7027 |
let l10 = i32::from( |
| 7028 |
*base |
| 7029 |
.add(6 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7030 |
.cast::<u8>(), |
| 7031 |
); |
| 7032 |
let l11 = i32::from( |
| 7033 |
*base |
| 7034 |
.add(7 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7035 |
.cast::<u8>(), |
| 7036 |
); |
| 7037 |
let l12 = i32::from( |
| 7038 |
*base |
| 7039 |
.add(8 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7040 |
.cast::<u8>(), |
| 7041 |
); |
| 7042 |
let l13 = i32::from( |
| 7043 |
*base |
| 7044 |
.add(9 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7045 |
.cast::<u8>(), |
| 7046 |
); |
| 7047 |
super::super::super::wasi::sockets::network::Ipv4SocketAddress { |
| 7048 |
port: l9 as u16, |
| 7049 |
address: (l10 as u8, l11 as u8, l12 as u8, l13 as u8), |
| 7050 |
} |
| 7051 |
}; |
| 7052 |
V25::Ipv4(e25) |
| 7053 |
} |
| 7054 |
n => { |
| 7055 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 7056 |
let e25 = { |
| 7057 |
let l14 = i32::from( |
| 7058 |
*base |
| 7059 |
.add(4 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7060 |
.cast::<u16>(), |
| 7061 |
); |
| 7062 |
let l15 = *base |
| 7063 |
.add(8 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7064 |
.cast::<i32>(); |
| 7065 |
let l16 = i32::from( |
| 7066 |
*base |
| 7067 |
.add(12 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7068 |
.cast::<u16>(), |
| 7069 |
); |
| 7070 |
let l17 = i32::from( |
| 7071 |
*base |
| 7072 |
.add(14 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7073 |
.cast::<u16>(), |
| 7074 |
); |
| 7075 |
let l18 = i32::from( |
| 7076 |
*base |
| 7077 |
.add(16 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7078 |
.cast::<u16>(), |
| 7079 |
); |
| 7080 |
let l19 = i32::from( |
| 7081 |
*base |
| 7082 |
.add(18 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7083 |
.cast::<u16>(), |
| 7084 |
); |
| 7085 |
let l20 = i32::from( |
| 7086 |
*base |
| 7087 |
.add(20 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7088 |
.cast::<u16>(), |
| 7089 |
); |
| 7090 |
let l21 = i32::from( |
| 7091 |
*base |
| 7092 |
.add(22 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7093 |
.cast::<u16>(), |
| 7094 |
); |
| 7095 |
let l22 = i32::from( |
| 7096 |
*base |
| 7097 |
.add(24 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7098 |
.cast::<u16>(), |
| 7099 |
); |
| 7100 |
let l23 = i32::from( |
| 7101 |
*base |
| 7102 |
.add(26 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7103 |
.cast::<u16>(), |
| 7104 |
); |
| 7105 |
let l24 = *base |
| 7106 |
.add(28 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7107 |
.cast::<i32>(); |
| 7108 |
super::super::super::wasi::sockets::network::Ipv6SocketAddress { |
| 7109 |
port: l14 as u16, |
| 7110 |
flow_info: l15 as u32, |
| 7111 |
address: ( |
| 7112 |
l16 as u16, |
| 7113 |
l17 as u16, |
| 7114 |
l18 as u16, |
| 7115 |
l19 as u16, |
| 7116 |
l20 as u16, |
| 7117 |
l21 as u16, |
| 7118 |
l22 as u16, |
| 7119 |
l23 as u16, |
| 7120 |
), |
| 7121 |
scope_id: l24 as u32, |
| 7122 |
} |
| 7123 |
}; |
| 7124 |
V25::Ipv6(e25) |
| 7125 |
} |
| 7126 |
}; |
| 7127 |
IncomingDatagram { |
| 7128 |
data: _rt::Vec::from_raw_parts(l5.cast(), len7, len7), |
| 7129 |
remote_address: v25, |
| 7130 |
} |
| 7131 |
}; |
| 7132 |
result26.push(e26); |
| 7133 |
} |
| 7134 |
_rt::cabi_dealloc( |
| 7135 |
base26, |
| 7136 |
len26 * (32 + 2 * ::core::mem::size_of::<*const u8>()), |
| 7137 |
::core::mem::size_of::<*const u8>(), |
| 7138 |
); |
| 7139 |
result26 |
| 7140 |
}; |
| 7141 |
Ok(e) |
| 7142 |
} |
| 7143 |
1 => { |
| 7144 |
let e = { |
| 7145 |
let l27 = i32::from( |
| 7146 |
*ptr0.add(::core::mem::size_of::<*const u8>()).cast::<u8>(), |
| 7147 |
); |
| 7148 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 7149 |
l27 as u8, |
| 7150 |
) |
| 7151 |
}; |
| 7152 |
Err(e) |
| 7153 |
} |
| 7154 |
_ => _rt::invalid_enum_discriminant(), |
| 7155 |
}; |
| 7156 |
result28 |
| 7157 |
} |
| 7158 |
} |
| 7159 |
} |
| 7160 |
impl IncomingDatagramStream { |
| 7161 |
#[allow(unused_unsafe, clippy::all)] |
| 7162 |
/// Create a `pollable` which will resolve once the stream is ready to receive again. |
| 7163 |
/// |
| 7164 |
/// Note: this function is here for WASI 0.2 only. |
| 7165 |
/// It's planned to be removed when `future` is natively supported in Preview3. |
| 7166 |
#[allow(async_fn_in_trait)] |
| 7167 |
pub fn subscribe(&self) -> Pollable { |
| 7168 |
unsafe { |
| 7169 |
#[cfg(target_arch = "wasm32")] |
| 7170 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 7171 |
unsafe extern "C" { |
| 7172 |
#[link_name = "[method]incoming-datagram-stream.subscribe"] |
| 7173 |
fn wit_import0(_: i32) -> i32; |
| 7174 |
} |
| 7175 |
#[cfg(not(target_arch = "wasm32"))] |
| 7176 |
unsafe extern "C" fn wit_import0(_: i32) -> i32 { |
| 7177 |
unreachable!() |
| 7178 |
} |
| 7179 |
let ret = wit_import0((self).handle() as i32); |
| 7180 |
super::super::super::wasi::io::poll::Pollable::from_handle( |
| 7181 |
ret as u32, |
| 7182 |
) |
| 7183 |
} |
| 7184 |
} |
| 7185 |
} |
| 7186 |
impl OutgoingDatagramStream { |
| 7187 |
#[allow(unused_unsafe, clippy::all)] |
| 7188 |
/// Check readiness for sending. This function never blocks. |
| 7189 |
/// |
| 7190 |
/// Returns the number of datagrams permitted for the next call to `send`, |
| 7191 |
/// or an error. Calling `send` with more datagrams than this function has |
| 7192 |
/// permitted will trap. |
| 7193 |
/// |
| 7194 |
/// When this function returns ok(0), the `subscribe` pollable will |
| 7195 |
/// become ready when this function will report at least ok(1), or an |
| 7196 |
/// error. |
| 7197 |
/// |
| 7198 |
/// Never returns `would-block`. |
| 7199 |
#[allow(async_fn_in_trait)] |
| 7200 |
pub fn check_send(&self) -> Result<u64, ErrorCode> { |
| 7201 |
unsafe { |
| 7202 |
#[repr(align(8))] |
| 7203 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 7204 |
let mut ret_area = RetArea( |
| 7205 |
[::core::mem::MaybeUninit::uninit(); 16], |
| 7206 |
); |
| 7207 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 7208 |
#[cfg(target_arch = "wasm32")] |
| 7209 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 7210 |
unsafe extern "C" { |
| 7211 |
#[link_name = "[method]outgoing-datagram-stream.check-send"] |
| 7212 |
fn wit_import1(_: i32, _: *mut u8); |
| 7213 |
} |
| 7214 |
#[cfg(not(target_arch = "wasm32"))] |
| 7215 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 7216 |
unreachable!() |
| 7217 |
} |
| 7218 |
wit_import1((self).handle() as i32, ptr0); |
| 7219 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 7220 |
let result5 = match l2 { |
| 7221 |
0 => { |
| 7222 |
let e = { |
| 7223 |
let l3 = *ptr0.add(8).cast::<i64>(); |
| 7224 |
l3 as u64 |
| 7225 |
}; |
| 7226 |
Ok(e) |
| 7227 |
} |
| 7228 |
1 => { |
| 7229 |
let e = { |
| 7230 |
let l4 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 7231 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 7232 |
l4 as u8, |
| 7233 |
) |
| 7234 |
}; |
| 7235 |
Err(e) |
| 7236 |
} |
| 7237 |
_ => _rt::invalid_enum_discriminant(), |
| 7238 |
}; |
| 7239 |
result5 |
| 7240 |
} |
| 7241 |
} |
| 7242 |
} |
| 7243 |
impl OutgoingDatagramStream { |
| 7244 |
#[allow(unused_unsafe, clippy::all)] |
| 7245 |
/// Send messages on the socket. |
| 7246 |
/// |
| 7247 |
/// This function attempts to send all provided `datagrams` on the socket without blocking and |
| 7248 |
/// returns how many messages were actually sent (or queued for sending). This function never |
| 7249 |
/// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` is returned. |
| 7250 |
/// |
| 7251 |
/// This function semantically behaves the same as iterating the `datagrams` list and sequentially |
| 7252 |
/// sending each individual datagram until either the end of the list has been reached or the first error occurred. |
| 7253 |
/// If at least one datagram has been sent successfully, this function never returns an error. |
| 7254 |
/// |
| 7255 |
/// If the input list is empty, the function returns `ok(0)`. |
| 7256 |
/// |
| 7257 |
/// Each call to `send` must be permitted by a preceding `check-send`. Implementations must trap if |
| 7258 |
/// either `check-send` was not called or `datagrams` contains more items than `check-send` permitted. |
| 7259 |
/// |
| 7260 |
/// # Typical errors |
| 7261 |
/// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) |
| 7262 |
/// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) |
| 7263 |
/// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) |
| 7264 |
/// - `invalid-argument`: The socket is in "connected" mode and `remote-address` is `some` value that does not match the address passed to `stream`. (EISCONN) |
| 7265 |
/// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` was provided. (EDESTADDRREQ) |
| 7266 |
/// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) |
| 7267 |
/// - `connection-refused`: The connection was refused. (ECONNREFUSED) |
| 7268 |
/// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) |
| 7269 |
/// |
| 7270 |
/// # References |
| 7271 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html> |
| 7272 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html> |
| 7273 |
/// - <https://man7.org/linux/man-pages/man2/send.2.html> |
| 7274 |
/// - <https://man7.org/linux/man-pages/man2/sendmmsg.2.html> |
| 7275 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-send> |
| 7276 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto> |
| 7277 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasendmsg> |
| 7278 |
/// - <https://man.freebsd.org/cgi/man.cgi?query=send&sektion=2> |
| 7279 |
#[allow(async_fn_in_trait)] |
| 7280 |
pub fn send( |
| 7281 |
&self, |
| 7282 |
datagrams: &[OutgoingDatagram], |
| 7283 |
) -> Result<u64, ErrorCode> { |
| 7284 |
unsafe { |
| 7285 |
#[repr(align(8))] |
| 7286 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 7287 |
let mut ret_area = RetArea( |
| 7288 |
[::core::mem::MaybeUninit::uninit(); 16], |
| 7289 |
); |
| 7290 |
let vec7 = datagrams; |
| 7291 |
let len7 = vec7.len(); |
| 7292 |
let layout7 = _rt::alloc::Layout::from_size_align( |
| 7293 |
vec7.len() * (32 + 3 * ::core::mem::size_of::<*const u8>()), |
| 7294 |
::core::mem::size_of::<*const u8>(), |
| 7295 |
) |
| 7296 |
.unwrap(); |
| 7297 |
let (result7, _cleanup7) = wit_bindgen::rt::Cleanup::new( |
| 7298 |
layout7, |
| 7299 |
); |
| 7300 |
for (i, e) in vec7.into_iter().enumerate() { |
| 7301 |
let base = result7 |
| 7302 |
.add(i * (32 + 3 * ::core::mem::size_of::<*const u8>())); |
| 7303 |
{ |
| 7304 |
let OutgoingDatagram { |
| 7305 |
data: data0, |
| 7306 |
remote_address: remote_address0, |
| 7307 |
} = e; |
| 7308 |
let vec1 = data0; |
| 7309 |
let ptr1 = vec1.as_ptr().cast::<u8>(); |
| 7310 |
let len1 = vec1.len(); |
| 7311 |
*base |
| 7312 |
.add(::core::mem::size_of::<*const u8>()) |
| 7313 |
.cast::<usize>() = len1; |
| 7314 |
*base.add(0).cast::<*mut u8>() = ptr1.cast_mut(); |
| 7315 |
match remote_address0 { |
| 7316 |
Some(e) => { |
| 7317 |
*base |
| 7318 |
.add(2 * ::core::mem::size_of::<*const u8>()) |
| 7319 |
.cast::<u8>() = (1i32) as u8; |
| 7320 |
use super::super::super::wasi::sockets::network::IpSocketAddress as V6; |
| 7321 |
match e { |
| 7322 |
V6::Ipv4(e) => { |
| 7323 |
*base |
| 7324 |
.add(4 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7325 |
.cast::<u8>() = (0i32) as u8; |
| 7326 |
let super::super::super::wasi::sockets::network::Ipv4SocketAddress { |
| 7327 |
port: port2, |
| 7328 |
address: address2, |
| 7329 |
} = e; |
| 7330 |
*base |
| 7331 |
.add(8 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7332 |
.cast::<u16>() = (_rt::as_i32(port2)) as u16; |
| 7333 |
let (t3_0, t3_1, t3_2, t3_3) = address2; |
| 7334 |
*base |
| 7335 |
.add(10 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7336 |
.cast::<u8>() = (_rt::as_i32(t3_0)) as u8; |
| 7337 |
*base |
| 7338 |
.add(11 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7339 |
.cast::<u8>() = (_rt::as_i32(t3_1)) as u8; |
| 7340 |
*base |
| 7341 |
.add(12 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7342 |
.cast::<u8>() = (_rt::as_i32(t3_2)) as u8; |
| 7343 |
*base |
| 7344 |
.add(13 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7345 |
.cast::<u8>() = (_rt::as_i32(t3_3)) as u8; |
| 7346 |
} |
| 7347 |
V6::Ipv6(e) => { |
| 7348 |
*base |
| 7349 |
.add(4 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7350 |
.cast::<u8>() = (1i32) as u8; |
| 7351 |
let super::super::super::wasi::sockets::network::Ipv6SocketAddress { |
| 7352 |
port: port4, |
| 7353 |
flow_info: flow_info4, |
| 7354 |
address: address4, |
| 7355 |
scope_id: scope_id4, |
| 7356 |
} = e; |
| 7357 |
*base |
| 7358 |
.add(8 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7359 |
.cast::<u16>() = (_rt::as_i32(port4)) as u16; |
| 7360 |
*base |
| 7361 |
.add(12 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7362 |
.cast::<i32>() = _rt::as_i32(flow_info4); |
| 7363 |
let (t5_0, t5_1, t5_2, t5_3, t5_4, t5_5, t5_6, t5_7) = address4; |
| 7364 |
*base |
| 7365 |
.add(16 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7366 |
.cast::<u16>() = (_rt::as_i32(t5_0)) as u16; |
| 7367 |
*base |
| 7368 |
.add(18 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7369 |
.cast::<u16>() = (_rt::as_i32(t5_1)) as u16; |
| 7370 |
*base |
| 7371 |
.add(20 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7372 |
.cast::<u16>() = (_rt::as_i32(t5_2)) as u16; |
| 7373 |
*base |
| 7374 |
.add(22 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7375 |
.cast::<u16>() = (_rt::as_i32(t5_3)) as u16; |
| 7376 |
*base |
| 7377 |
.add(24 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7378 |
.cast::<u16>() = (_rt::as_i32(t5_4)) as u16; |
| 7379 |
*base |
| 7380 |
.add(26 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7381 |
.cast::<u16>() = (_rt::as_i32(t5_5)) as u16; |
| 7382 |
*base |
| 7383 |
.add(28 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7384 |
.cast::<u16>() = (_rt::as_i32(t5_6)) as u16; |
| 7385 |
*base |
| 7386 |
.add(30 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7387 |
.cast::<u16>() = (_rt::as_i32(t5_7)) as u16; |
| 7388 |
*base |
| 7389 |
.add(32 + 2 * ::core::mem::size_of::<*const u8>()) |
| 7390 |
.cast::<i32>() = _rt::as_i32(scope_id4); |
| 7391 |
} |
| 7392 |
} |
| 7393 |
} |
| 7394 |
None => { |
| 7395 |
*base |
| 7396 |
.add(2 * ::core::mem::size_of::<*const u8>()) |
| 7397 |
.cast::<u8>() = (0i32) as u8; |
| 7398 |
} |
| 7399 |
}; |
| 7400 |
} |
| 7401 |
} |
| 7402 |
let ptr8 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 7403 |
#[cfg(target_arch = "wasm32")] |
| 7404 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 7405 |
unsafe extern "C" { |
| 7406 |
#[link_name = "[method]outgoing-datagram-stream.send"] |
| 7407 |
fn wit_import9(_: i32, _: *mut u8, _: usize, _: *mut u8); |
| 7408 |
} |
| 7409 |
#[cfg(not(target_arch = "wasm32"))] |
| 7410 |
unsafe extern "C" fn wit_import9( |
| 7411 |
_: i32, |
| 7412 |
_: *mut u8, |
| 7413 |
_: usize, |
| 7414 |
_: *mut u8, |
| 7415 |
) { |
| 7416 |
unreachable!() |
| 7417 |
} |
| 7418 |
wit_import9((self).handle() as i32, result7, len7, ptr8); |
| 7419 |
let l10 = i32::from(*ptr8.add(0).cast::<u8>()); |
| 7420 |
let result13 = match l10 { |
| 7421 |
0 => { |
| 7422 |
let e = { |
| 7423 |
let l11 = *ptr8.add(8).cast::<i64>(); |
| 7424 |
l11 as u64 |
| 7425 |
}; |
| 7426 |
Ok(e) |
| 7427 |
} |
| 7428 |
1 => { |
| 7429 |
let e = { |
| 7430 |
let l12 = i32::from(*ptr8.add(8).cast::<u8>()); |
| 7431 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 7432 |
l12 as u8, |
| 7433 |
) |
| 7434 |
}; |
| 7435 |
Err(e) |
| 7436 |
} |
| 7437 |
_ => _rt::invalid_enum_discriminant(), |
| 7438 |
}; |
| 7439 |
result13 |
| 7440 |
} |
| 7441 |
} |
| 7442 |
} |
| 7443 |
impl OutgoingDatagramStream { |
| 7444 |
#[allow(unused_unsafe, clippy::all)] |
| 7445 |
/// Create a `pollable` which will resolve once the stream is ready to send again. |
| 7446 |
/// |
| 7447 |
/// Note: this function is here for WASI 0.2 only. |
| 7448 |
/// It's planned to be removed when `future` is natively supported in Preview3. |
| 7449 |
#[allow(async_fn_in_trait)] |
| 7450 |
pub fn subscribe(&self) -> Pollable { |
| 7451 |
unsafe { |
| 7452 |
#[cfg(target_arch = "wasm32")] |
| 7453 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 7454 |
unsafe extern "C" { |
| 7455 |
#[link_name = "[method]outgoing-datagram-stream.subscribe"] |
| 7456 |
fn wit_import0(_: i32) -> i32; |
| 7457 |
} |
| 7458 |
#[cfg(not(target_arch = "wasm32"))] |
| 7459 |
unsafe extern "C" fn wit_import0(_: i32) -> i32 { |
| 7460 |
unreachable!() |
| 7461 |
} |
| 7462 |
let ret = wit_import0((self).handle() as i32); |
| 7463 |
super::super::super::wasi::io::poll::Pollable::from_handle( |
| 7464 |
ret as u32, |
| 7465 |
) |
| 7466 |
} |
| 7467 |
} |
| 7468 |
} |
| 7469 |
} |
| 7470 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 7471 |
pub mod udp_create_socket { |
| 7472 |
#[used] |
| 7473 |
#[doc(hidden)] |
| 7474 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 7475 |
use super::super::super::_rt; |
| 7476 |
pub type ErrorCode = super::super::super::wasi::sockets::network::ErrorCode; |
| 7477 |
pub type IpAddressFamily = super::super::super::wasi::sockets::network::IpAddressFamily; |
| 7478 |
pub type UdpSocket = super::super::super::wasi::sockets::udp::UdpSocket; |
| 7479 |
#[allow(unused_unsafe, clippy::all)] |
| 7480 |
/// Create a new UDP socket. |
| 7481 |
/// |
| 7482 |
/// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX. |
| 7483 |
/// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. |
| 7484 |
/// |
| 7485 |
/// This function does not require a network capability handle. This is considered to be safe because |
| 7486 |
/// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind` is called, |
| 7487 |
/// the socket is effectively an in-memory configuration object, unable to communicate with the outside world. |
| 7488 |
/// |
| 7489 |
/// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. |
| 7490 |
/// |
| 7491 |
/// # Typical errors |
| 7492 |
/// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) |
| 7493 |
/// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) |
| 7494 |
/// |
| 7495 |
/// # References: |
| 7496 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html> |
| 7497 |
/// - <https://man7.org/linux/man-pages/man2/socket.2.html> |
| 7498 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw> |
| 7499 |
/// - <https://man.freebsd.org/cgi/man.cgi?query=socket&sektion=2> |
| 7500 |
#[allow(async_fn_in_trait)] |
| 7501 |
pub fn create_udp_socket( |
| 7502 |
address_family: IpAddressFamily, |
| 7503 |
) -> Result<UdpSocket, ErrorCode> { |
| 7504 |
unsafe { |
| 7505 |
#[repr(align(4))] |
| 7506 |
struct RetArea([::core::mem::MaybeUninit<u8>; 8]); |
| 7507 |
let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); |
| 7508 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 7509 |
#[cfg(target_arch = "wasm32")] |
| 7510 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 7511 |
unsafe extern "C" { |
| 7512 |
#[link_name = "create-udp-socket"] |
| 7513 |
fn wit_import1(_: i32, _: *mut u8); |
| 7514 |
} |
| 7515 |
#[cfg(not(target_arch = "wasm32"))] |
| 7516 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 7517 |
unreachable!() |
| 7518 |
} |
| 7519 |
wit_import1(address_family.clone() as i32, ptr0); |
| 7520 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 7521 |
let result5 = match l2 { |
| 7522 |
0 => { |
| 7523 |
let e = { |
| 7524 |
let l3 = *ptr0.add(4).cast::<i32>(); |
| 7525 |
super::super::super::wasi::sockets::udp::UdpSocket::from_handle( |
| 7526 |
l3 as u32, |
| 7527 |
) |
| 7528 |
}; |
| 7529 |
Ok(e) |
| 7530 |
} |
| 7531 |
1 => { |
| 7532 |
let e = { |
| 7533 |
let l4 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 7534 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 7535 |
l4 as u8, |
| 7536 |
) |
| 7537 |
}; |
| 7538 |
Err(e) |
| 7539 |
} |
| 7540 |
_ => _rt::invalid_enum_discriminant(), |
| 7541 |
}; |
| 7542 |
result5 |
| 7543 |
} |
| 7544 |
} |
| 7545 |
} |
| 7546 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 7547 |
pub mod tcp { |
| 7548 |
#[used] |
| 7549 |
#[doc(hidden)] |
| 7550 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 7551 |
use super::super::super::_rt; |
| 7552 |
pub type InputStream = super::super::super::wasi::io::streams::InputStream; |
| 7553 |
pub type OutputStream = super::super::super::wasi::io::streams::OutputStream; |
| 7554 |
pub type Pollable = super::super::super::wasi::io::poll::Pollable; |
| 7555 |
pub type Duration = super::super::super::wasi::clocks::monotonic_clock::Duration; |
| 7556 |
pub type Network = super::super::super::wasi::sockets::network::Network; |
| 7557 |
pub type ErrorCode = super::super::super::wasi::sockets::network::ErrorCode; |
| 7558 |
pub type IpSocketAddress = super::super::super::wasi::sockets::network::IpSocketAddress; |
| 7559 |
pub type IpAddressFamily = super::super::super::wasi::sockets::network::IpAddressFamily; |
| 7560 |
#[repr(u8)] |
| 7561 |
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)] |
| 7562 |
pub enum ShutdownType { |
| 7563 |
/// Similar to `SHUT_RD` in POSIX. |
| 7564 |
Receive, |
| 7565 |
/// Similar to `SHUT_WR` in POSIX. |
| 7566 |
Send, |
| 7567 |
/// Similar to `SHUT_RDWR` in POSIX. |
| 7568 |
Both, |
| 7569 |
} |
| 7570 |
impl ::core::fmt::Debug for ShutdownType { |
| 7571 |
fn fmt( |
| 7572 |
&self, |
| 7573 |
f: &mut ::core::fmt::Formatter<'_>, |
| 7574 |
) -> ::core::fmt::Result { |
| 7575 |
match self { |
| 7576 |
ShutdownType::Receive => { |
| 7577 |
f.debug_tuple("ShutdownType::Receive").finish() |
| 7578 |
} |
| 7579 |
ShutdownType::Send => { |
| 7580 |
f.debug_tuple("ShutdownType::Send").finish() |
| 7581 |
} |
| 7582 |
ShutdownType::Both => { |
| 7583 |
f.debug_tuple("ShutdownType::Both").finish() |
| 7584 |
} |
| 7585 |
} |
| 7586 |
} |
| 7587 |
} |
| 7588 |
impl ShutdownType { |
| 7589 |
#[doc(hidden)] |
| 7590 |
pub unsafe fn _lift(val: u8) -> ShutdownType { |
| 7591 |
if !cfg!(debug_assertions) { |
| 7592 |
return unsafe { ::core::mem::transmute(val) }; |
| 7593 |
} |
| 7594 |
match val { |
| 7595 |
0 => ShutdownType::Receive, |
| 7596 |
1 => ShutdownType::Send, |
| 7597 |
2 => ShutdownType::Both, |
| 7598 |
_ => panic!("invalid enum discriminant"), |
| 7599 |
} |
| 7600 |
} |
| 7601 |
} |
| 7602 |
/// A TCP socket resource. |
| 7603 |
/// |
| 7604 |
/// The socket can be in one of the following states: |
| 7605 |
/// - `unbound` |
| 7606 |
/// - `bind-in-progress` |
| 7607 |
/// - `bound` (See note below) |
| 7608 |
/// - `listen-in-progress` |
| 7609 |
/// - `listening` |
| 7610 |
/// - `connect-in-progress` |
| 7611 |
/// - `connected` |
| 7612 |
/// - `closed` |
| 7613 |
/// See <https://github.com/WebAssembly/wasi-sockets/blob/main/TcpSocketOperationalSemantics.md> |
| 7614 |
/// for more information. |
| 7615 |
/// |
| 7616 |
/// Note: Except where explicitly mentioned, whenever this documentation uses |
| 7617 |
/// the term "bound" without backticks it actually means: in the `bound` state *or higher*. |
| 7618 |
/// (i.e. `bound`, `listen-in-progress`, `listening`, `connect-in-progress` or `connected`) |
| 7619 |
/// |
| 7620 |
/// In addition to the general error codes documented on the |
| 7621 |
/// `network::error-code` type, TCP socket methods may always return |
| 7622 |
/// `error(invalid-state)` when in the `closed` state. |
| 7623 |
#[derive(Debug)] |
| 7624 |
#[repr(transparent)] |
| 7625 |
pub struct TcpSocket { |
| 7626 |
handle: _rt::Resource<TcpSocket>, |
| 7627 |
} |
| 7628 |
impl TcpSocket { |
| 7629 |
#[doc(hidden)] |
| 7630 |
pub unsafe fn from_handle(handle: u32) -> Self { |
| 7631 |
Self { |
| 7632 |
handle: unsafe { _rt::Resource::from_handle(handle) }, |
| 7633 |
} |
| 7634 |
} |
| 7635 |
#[doc(hidden)] |
| 7636 |
pub fn take_handle(&self) -> u32 { |
| 7637 |
_rt::Resource::take_handle(&self.handle) |
| 7638 |
} |
| 7639 |
#[doc(hidden)] |
| 7640 |
pub fn handle(&self) -> u32 { |
| 7641 |
_rt::Resource::handle(&self.handle) |
| 7642 |
} |
| 7643 |
} |
| 7644 |
unsafe impl _rt::WasmResource for TcpSocket { |
| 7645 |
#[inline] |
| 7646 |
unsafe fn drop(_handle: u32) { |
| 7647 |
#[cfg(target_arch = "wasm32")] |
| 7648 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 7649 |
unsafe extern "C" { |
| 7650 |
#[link_name = "[resource-drop]tcp-socket"] |
| 7651 |
fn drop(_: i32); |
| 7652 |
} |
| 7653 |
#[cfg(not(target_arch = "wasm32"))] |
| 7654 |
unsafe extern "C" fn drop(_: i32) { |
| 7655 |
unreachable!() |
| 7656 |
} |
| 7657 |
unsafe { |
| 7658 |
drop(_handle as i32); |
| 7659 |
} |
| 7660 |
} |
| 7661 |
} |
| 7662 |
impl TcpSocket { |
| 7663 |
#[allow(unused_unsafe, clippy::all)] |
| 7664 |
/// Bind the socket to a specific network on the provided IP address and port. |
| 7665 |
/// |
| 7666 |
/// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which |
| 7667 |
/// network interface(s) to bind to. |
| 7668 |
/// If the TCP/UDP port is zero, the socket will be bound to a random free port. |
| 7669 |
/// |
| 7670 |
/// Bind can be attempted multiple times on the same socket, even with |
| 7671 |
/// different arguments on each iteration. But never concurrently and |
| 7672 |
/// only as long as the previous bind failed. Once a bind succeeds, the |
| 7673 |
/// binding can't be changed anymore. |
| 7674 |
/// |
| 7675 |
/// # Typical errors |
| 7676 |
/// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) |
| 7677 |
/// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) |
| 7678 |
/// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL) |
| 7679 |
/// - `invalid-state`: The socket is already bound. (EINVAL) |
| 7680 |
/// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) |
| 7681 |
/// - `address-in-use`: Address is already in use. (EADDRINUSE) |
| 7682 |
/// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) |
| 7683 |
/// - `not-in-progress`: A `bind` operation is not in progress. |
| 7684 |
/// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) |
| 7685 |
/// |
| 7686 |
/// # Implementors note |
| 7687 |
/// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT |
| 7688 |
/// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR |
| 7689 |
/// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior |
| 7690 |
/// and SO_REUSEADDR performs something different entirely. |
| 7691 |
/// |
| 7692 |
/// Unlike in POSIX, in WASI the bind operation is async. This enables |
| 7693 |
/// interactive WASI hosts to inject permission prompts. Runtimes that |
| 7694 |
/// don't want to make use of this ability can simply call the native |
| 7695 |
/// `bind` as part of either `start-bind` or `finish-bind`. |
| 7696 |
/// |
| 7697 |
/// # References |
| 7698 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html> |
| 7699 |
/// - <https://man7.org/linux/man-pages/man2/bind.2.html> |
| 7700 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-bind> |
| 7701 |
/// - <https://man.freebsd.org/cgi/man.cgi?query=bind&sektion=2&format=html> |
| 7702 |
#[allow(async_fn_in_trait)] |
| 7703 |
pub fn start_bind( |
| 7704 |
&self, |
| 7705 |
network: &Network, |
| 7706 |
local_address: IpSocketAddress, |
| 7707 |
) -> Result<(), ErrorCode> { |
| 7708 |
unsafe { |
| 7709 |
#[repr(align(1))] |
| 7710 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 7711 |
let mut ret_area = RetArea( |
| 7712 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 7713 |
); |
| 7714 |
use super::super::super::wasi::sockets::network::IpSocketAddress as V4; |
| 7715 |
let ( |
| 7716 |
result5_0, |
| 7717 |
result5_1, |
| 7718 |
result5_2, |
| 7719 |
result5_3, |
| 7720 |
result5_4, |
| 7721 |
result5_5, |
| 7722 |
result5_6, |
| 7723 |
result5_7, |
| 7724 |
result5_8, |
| 7725 |
result5_9, |
| 7726 |
result5_10, |
| 7727 |
result5_11, |
| 7728 |
) = match local_address { |
| 7729 |
V4::Ipv4(e) => { |
| 7730 |
let super::super::super::wasi::sockets::network::Ipv4SocketAddress { |
| 7731 |
port: port0, |
| 7732 |
address: address0, |
| 7733 |
} = e; |
| 7734 |
let (t1_0, t1_1, t1_2, t1_3) = address0; |
| 7735 |
( |
| 7736 |
0i32, |
| 7737 |
_rt::as_i32(port0), |
| 7738 |
_rt::as_i32(t1_0), |
| 7739 |
_rt::as_i32(t1_1), |
| 7740 |
_rt::as_i32(t1_2), |
| 7741 |
_rt::as_i32(t1_3), |
| 7742 |
0i32, |
| 7743 |
0i32, |
| 7744 |
0i32, |
| 7745 |
0i32, |
| 7746 |
0i32, |
| 7747 |
0i32, |
| 7748 |
) |
| 7749 |
} |
| 7750 |
V4::Ipv6(e) => { |
| 7751 |
let super::super::super::wasi::sockets::network::Ipv6SocketAddress { |
| 7752 |
port: port2, |
| 7753 |
flow_info: flow_info2, |
| 7754 |
address: address2, |
| 7755 |
scope_id: scope_id2, |
| 7756 |
} = e; |
| 7757 |
let (t3_0, t3_1, t3_2, t3_3, t3_4, t3_5, t3_6, t3_7) = address2; |
| 7758 |
( |
| 7759 |
1i32, |
| 7760 |
_rt::as_i32(port2), |
| 7761 |
_rt::as_i32(flow_info2), |
| 7762 |
_rt::as_i32(t3_0), |
| 7763 |
_rt::as_i32(t3_1), |
| 7764 |
_rt::as_i32(t3_2), |
| 7765 |
_rt::as_i32(t3_3), |
| 7766 |
_rt::as_i32(t3_4), |
| 7767 |
_rt::as_i32(t3_5), |
| 7768 |
_rt::as_i32(t3_6), |
| 7769 |
_rt::as_i32(t3_7), |
| 7770 |
_rt::as_i32(scope_id2), |
| 7771 |
) |
| 7772 |
} |
| 7773 |
}; |
| 7774 |
let ptr6 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 7775 |
#[cfg(target_arch = "wasm32")] |
| 7776 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 7777 |
unsafe extern "C" { |
| 7778 |
#[link_name = "[method]tcp-socket.start-bind"] |
| 7779 |
fn wit_import7( |
| 7780 |
_: i32, |
| 7781 |
_: i32, |
| 7782 |
_: i32, |
| 7783 |
_: i32, |
| 7784 |
_: i32, |
| 7785 |
_: i32, |
| 7786 |
_: i32, |
| 7787 |
_: i32, |
| 7788 |
_: i32, |
| 7789 |
_: i32, |
| 7790 |
_: i32, |
| 7791 |
_: i32, |
| 7792 |
_: i32, |
| 7793 |
_: i32, |
| 7794 |
_: *mut u8, |
| 7795 |
); |
| 7796 |
} |
| 7797 |
#[cfg(not(target_arch = "wasm32"))] |
| 7798 |
unsafe extern "C" fn wit_import7( |
| 7799 |
_: i32, |
| 7800 |
_: i32, |
| 7801 |
_: i32, |
| 7802 |
_: i32, |
| 7803 |
_: i32, |
| 7804 |
_: i32, |
| 7805 |
_: i32, |
| 7806 |
_: i32, |
| 7807 |
_: i32, |
| 7808 |
_: i32, |
| 7809 |
_: i32, |
| 7810 |
_: i32, |
| 7811 |
_: i32, |
| 7812 |
_: i32, |
| 7813 |
_: *mut u8, |
| 7814 |
) { |
| 7815 |
unreachable!() |
| 7816 |
} |
| 7817 |
wit_import7( |
| 7818 |
(self).handle() as i32, |
| 7819 |
(network).handle() as i32, |
| 7820 |
result5_0, |
| 7821 |
result5_1, |
| 7822 |
result5_2, |
| 7823 |
result5_3, |
| 7824 |
result5_4, |
| 7825 |
result5_5, |
| 7826 |
result5_6, |
| 7827 |
result5_7, |
| 7828 |
result5_8, |
| 7829 |
result5_9, |
| 7830 |
result5_10, |
| 7831 |
result5_11, |
| 7832 |
ptr6, |
| 7833 |
); |
| 7834 |
let l8 = i32::from(*ptr6.add(0).cast::<u8>()); |
| 7835 |
let result10 = match l8 { |
| 7836 |
0 => { |
| 7837 |
let e = (); |
| 7838 |
Ok(e) |
| 7839 |
} |
| 7840 |
1 => { |
| 7841 |
let e = { |
| 7842 |
let l9 = i32::from(*ptr6.add(1).cast::<u8>()); |
| 7843 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 7844 |
l9 as u8, |
| 7845 |
) |
| 7846 |
}; |
| 7847 |
Err(e) |
| 7848 |
} |
| 7849 |
_ => _rt::invalid_enum_discriminant(), |
| 7850 |
}; |
| 7851 |
result10 |
| 7852 |
} |
| 7853 |
} |
| 7854 |
} |
| 7855 |
impl TcpSocket { |
| 7856 |
#[allow(unused_unsafe, clippy::all)] |
| 7857 |
#[allow(async_fn_in_trait)] |
| 7858 |
pub fn finish_bind(&self) -> Result<(), ErrorCode> { |
| 7859 |
unsafe { |
| 7860 |
#[repr(align(1))] |
| 7861 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 7862 |
let mut ret_area = RetArea( |
| 7863 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 7864 |
); |
| 7865 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 7866 |
#[cfg(target_arch = "wasm32")] |
| 7867 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 7868 |
unsafe extern "C" { |
| 7869 |
#[link_name = "[method]tcp-socket.finish-bind"] |
| 7870 |
fn wit_import1(_: i32, _: *mut u8); |
| 7871 |
} |
| 7872 |
#[cfg(not(target_arch = "wasm32"))] |
| 7873 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 7874 |
unreachable!() |
| 7875 |
} |
| 7876 |
wit_import1((self).handle() as i32, ptr0); |
| 7877 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 7878 |
let result4 = match l2 { |
| 7879 |
0 => { |
| 7880 |
let e = (); |
| 7881 |
Ok(e) |
| 7882 |
} |
| 7883 |
1 => { |
| 7884 |
let e = { |
| 7885 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 7886 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 7887 |
l3 as u8, |
| 7888 |
) |
| 7889 |
}; |
| 7890 |
Err(e) |
| 7891 |
} |
| 7892 |
_ => _rt::invalid_enum_discriminant(), |
| 7893 |
}; |
| 7894 |
result4 |
| 7895 |
} |
| 7896 |
} |
| 7897 |
} |
| 7898 |
impl TcpSocket { |
| 7899 |
#[allow(unused_unsafe, clippy::all)] |
| 7900 |
/// Connect to a remote endpoint. |
| 7901 |
/// |
| 7902 |
/// On success: |
| 7903 |
/// - the socket is transitioned into the `connected` state. |
| 7904 |
/// - a pair of streams is returned that can be used to read & write to the connection |
| 7905 |
/// |
| 7906 |
/// After a failed connection attempt, the socket will be in the `closed` |
| 7907 |
/// state and the only valid action left is to `drop` the socket. A single |
| 7908 |
/// socket can not be used to connect more than once. |
| 7909 |
/// |
| 7910 |
/// # Typical errors |
| 7911 |
/// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) |
| 7912 |
/// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) |
| 7913 |
/// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos) |
| 7914 |
/// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) |
| 7915 |
/// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows) |
| 7916 |
/// - `invalid-argument`: The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. |
| 7917 |
/// - `invalid-state`: The socket is already in the `connected` state. (EISCONN) |
| 7918 |
/// - `invalid-state`: The socket is already in the `listening` state. (EOPNOTSUPP, EINVAL on Windows) |
| 7919 |
/// - `timeout`: Connection timed out. (ETIMEDOUT) |
| 7920 |
/// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) |
| 7921 |
/// - `connection-reset`: The connection was reset. (ECONNRESET) |
| 7922 |
/// - `connection-aborted`: The connection was aborted. (ECONNABORTED) |
| 7923 |
/// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) |
| 7924 |
/// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) |
| 7925 |
/// - `not-in-progress`: A connect operation is not in progress. |
| 7926 |
/// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) |
| 7927 |
/// |
| 7928 |
/// # Implementors note |
| 7929 |
/// The POSIX equivalent of `start-connect` is the regular `connect` syscall. |
| 7930 |
/// Because all WASI sockets are non-blocking this is expected to return |
| 7931 |
/// EINPROGRESS, which should be translated to `ok()` in WASI. |
| 7932 |
/// |
| 7933 |
/// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT` |
| 7934 |
/// with a timeout of 0 on the socket descriptor. Followed by a check for |
| 7935 |
/// the `SO_ERROR` socket option, in case the poll signaled readiness. |
| 7936 |
/// |
| 7937 |
/// # References |
| 7938 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html> |
| 7939 |
/// - <https://man7.org/linux/man-pages/man2/connect.2.html> |
| 7940 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect> |
| 7941 |
/// - <https://man.freebsd.org/cgi/man.cgi?connect> |
| 7942 |
#[allow(async_fn_in_trait)] |
| 7943 |
pub fn start_connect( |
| 7944 |
&self, |
| 7945 |
network: &Network, |
| 7946 |
remote_address: IpSocketAddress, |
| 7947 |
) -> Result<(), ErrorCode> { |
| 7948 |
unsafe { |
| 7949 |
#[repr(align(1))] |
| 7950 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 7951 |
let mut ret_area = RetArea( |
| 7952 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 7953 |
); |
| 7954 |
use super::super::super::wasi::sockets::network::IpSocketAddress as V4; |
| 7955 |
let ( |
| 7956 |
result5_0, |
| 7957 |
result5_1, |
| 7958 |
result5_2, |
| 7959 |
result5_3, |
| 7960 |
result5_4, |
| 7961 |
result5_5, |
| 7962 |
result5_6, |
| 7963 |
result5_7, |
| 7964 |
result5_8, |
| 7965 |
result5_9, |
| 7966 |
result5_10, |
| 7967 |
result5_11, |
| 7968 |
) = match remote_address { |
| 7969 |
V4::Ipv4(e) => { |
| 7970 |
let super::super::super::wasi::sockets::network::Ipv4SocketAddress { |
| 7971 |
port: port0, |
| 7972 |
address: address0, |
| 7973 |
} = e; |
| 7974 |
let (t1_0, t1_1, t1_2, t1_3) = address0; |
| 7975 |
( |
| 7976 |
0i32, |
| 7977 |
_rt::as_i32(port0), |
| 7978 |
_rt::as_i32(t1_0), |
| 7979 |
_rt::as_i32(t1_1), |
| 7980 |
_rt::as_i32(t1_2), |
| 7981 |
_rt::as_i32(t1_3), |
| 7982 |
0i32, |
| 7983 |
0i32, |
| 7984 |
0i32, |
| 7985 |
0i32, |
| 7986 |
0i32, |
| 7987 |
0i32, |
| 7988 |
) |
| 7989 |
} |
| 7990 |
V4::Ipv6(e) => { |
| 7991 |
let super::super::super::wasi::sockets::network::Ipv6SocketAddress { |
| 7992 |
port: port2, |
| 7993 |
flow_info: flow_info2, |
| 7994 |
address: address2, |
| 7995 |
scope_id: scope_id2, |
| 7996 |
} = e; |
| 7997 |
let (t3_0, t3_1, t3_2, t3_3, t3_4, t3_5, t3_6, t3_7) = address2; |
| 7998 |
( |
| 7999 |
1i32, |
| 8000 |
_rt::as_i32(port2), |
| 8001 |
_rt::as_i32(flow_info2), |
| 8002 |
_rt::as_i32(t3_0), |
| 8003 |
_rt::as_i32(t3_1), |
| 8004 |
_rt::as_i32(t3_2), |
| 8005 |
_rt::as_i32(t3_3), |
| 8006 |
_rt::as_i32(t3_4), |
| 8007 |
_rt::as_i32(t3_5), |
| 8008 |
_rt::as_i32(t3_6), |
| 8009 |
_rt::as_i32(t3_7), |
| 8010 |
_rt::as_i32(scope_id2), |
| 8011 |
) |
| 8012 |
} |
| 8013 |
}; |
| 8014 |
let ptr6 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 8015 |
#[cfg(target_arch = "wasm32")] |
| 8016 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8017 |
unsafe extern "C" { |
| 8018 |
#[link_name = "[method]tcp-socket.start-connect"] |
| 8019 |
fn wit_import7( |
| 8020 |
_: i32, |
| 8021 |
_: i32, |
| 8022 |
_: i32, |
| 8023 |
_: i32, |
| 8024 |
_: i32, |
| 8025 |
_: i32, |
| 8026 |
_: i32, |
| 8027 |
_: i32, |
| 8028 |
_: i32, |
| 8029 |
_: i32, |
| 8030 |
_: i32, |
| 8031 |
_: i32, |
| 8032 |
_: i32, |
| 8033 |
_: i32, |
| 8034 |
_: *mut u8, |
| 8035 |
); |
| 8036 |
} |
| 8037 |
#[cfg(not(target_arch = "wasm32"))] |
| 8038 |
unsafe extern "C" fn wit_import7( |
| 8039 |
_: i32, |
| 8040 |
_: i32, |
| 8041 |
_: i32, |
| 8042 |
_: i32, |
| 8043 |
_: i32, |
| 8044 |
_: i32, |
| 8045 |
_: i32, |
| 8046 |
_: i32, |
| 8047 |
_: i32, |
| 8048 |
_: i32, |
| 8049 |
_: i32, |
| 8050 |
_: i32, |
| 8051 |
_: i32, |
| 8052 |
_: i32, |
| 8053 |
_: *mut u8, |
| 8054 |
) { |
| 8055 |
unreachable!() |
| 8056 |
} |
| 8057 |
wit_import7( |
| 8058 |
(self).handle() as i32, |
| 8059 |
(network).handle() as i32, |
| 8060 |
result5_0, |
| 8061 |
result5_1, |
| 8062 |
result5_2, |
| 8063 |
result5_3, |
| 8064 |
result5_4, |
| 8065 |
result5_5, |
| 8066 |
result5_6, |
| 8067 |
result5_7, |
| 8068 |
result5_8, |
| 8069 |
result5_9, |
| 8070 |
result5_10, |
| 8071 |
result5_11, |
| 8072 |
ptr6, |
| 8073 |
); |
| 8074 |
let l8 = i32::from(*ptr6.add(0).cast::<u8>()); |
| 8075 |
let result10 = match l8 { |
| 8076 |
0 => { |
| 8077 |
let e = (); |
| 8078 |
Ok(e) |
| 8079 |
} |
| 8080 |
1 => { |
| 8081 |
let e = { |
| 8082 |
let l9 = i32::from(*ptr6.add(1).cast::<u8>()); |
| 8083 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 8084 |
l9 as u8, |
| 8085 |
) |
| 8086 |
}; |
| 8087 |
Err(e) |
| 8088 |
} |
| 8089 |
_ => _rt::invalid_enum_discriminant(), |
| 8090 |
}; |
| 8091 |
result10 |
| 8092 |
} |
| 8093 |
} |
| 8094 |
} |
| 8095 |
impl TcpSocket { |
| 8096 |
#[allow(unused_unsafe, clippy::all)] |
| 8097 |
#[allow(async_fn_in_trait)] |
| 8098 |
pub fn finish_connect( |
| 8099 |
&self, |
| 8100 |
) -> Result<(InputStream, OutputStream), ErrorCode> { |
| 8101 |
unsafe { |
| 8102 |
#[repr(align(4))] |
| 8103 |
struct RetArea([::core::mem::MaybeUninit<u8>; 12]); |
| 8104 |
let mut ret_area = RetArea( |
| 8105 |
[::core::mem::MaybeUninit::uninit(); 12], |
| 8106 |
); |
| 8107 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 8108 |
#[cfg(target_arch = "wasm32")] |
| 8109 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8110 |
unsafe extern "C" { |
| 8111 |
#[link_name = "[method]tcp-socket.finish-connect"] |
| 8112 |
fn wit_import1(_: i32, _: *mut u8); |
| 8113 |
} |
| 8114 |
#[cfg(not(target_arch = "wasm32"))] |
| 8115 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 8116 |
unreachable!() |
| 8117 |
} |
| 8118 |
wit_import1((self).handle() as i32, ptr0); |
| 8119 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 8120 |
let result6 = match l2 { |
| 8121 |
0 => { |
| 8122 |
let e = { |
| 8123 |
let l3 = *ptr0.add(4).cast::<i32>(); |
| 8124 |
let l4 = *ptr0.add(8).cast::<i32>(); |
| 8125 |
( |
| 8126 |
super::super::super::wasi::io::streams::InputStream::from_handle( |
| 8127 |
l3 as u32, |
| 8128 |
), |
| 8129 |
super::super::super::wasi::io::streams::OutputStream::from_handle( |
| 8130 |
l4 as u32, |
| 8131 |
), |
| 8132 |
) |
| 8133 |
}; |
| 8134 |
Ok(e) |
| 8135 |
} |
| 8136 |
1 => { |
| 8137 |
let e = { |
| 8138 |
let l5 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 8139 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 8140 |
l5 as u8, |
| 8141 |
) |
| 8142 |
}; |
| 8143 |
Err(e) |
| 8144 |
} |
| 8145 |
_ => _rt::invalid_enum_discriminant(), |
| 8146 |
}; |
| 8147 |
result6 |
| 8148 |
} |
| 8149 |
} |
| 8150 |
} |
| 8151 |
impl TcpSocket { |
| 8152 |
#[allow(unused_unsafe, clippy::all)] |
| 8153 |
/// Start listening for new connections. |
| 8154 |
/// |
| 8155 |
/// Transitions the socket into the `listening` state. |
| 8156 |
/// |
| 8157 |
/// Unlike POSIX, the socket must already be explicitly bound. |
| 8158 |
/// |
| 8159 |
/// # Typical errors |
| 8160 |
/// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) |
| 8161 |
/// - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD) |
| 8162 |
/// - `invalid-state`: The socket is already in the `listening` state. |
| 8163 |
/// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE) |
| 8164 |
/// - `not-in-progress`: A listen operation is not in progress. |
| 8165 |
/// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) |
| 8166 |
/// |
| 8167 |
/// # Implementors note |
| 8168 |
/// Unlike in POSIX, in WASI the listen operation is async. This enables |
| 8169 |
/// interactive WASI hosts to inject permission prompts. Runtimes that |
| 8170 |
/// don't want to make use of this ability can simply call the native |
| 8171 |
/// `listen` as part of either `start-listen` or `finish-listen`. |
| 8172 |
/// |
| 8173 |
/// # References |
| 8174 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html> |
| 8175 |
/// - <https://man7.org/linux/man-pages/man2/listen.2.html> |
| 8176 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-listen> |
| 8177 |
/// - <https://man.freebsd.org/cgi/man.cgi?query=listen&sektion=2> |
| 8178 |
#[allow(async_fn_in_trait)] |
| 8179 |
pub fn start_listen(&self) -> Result<(), ErrorCode> { |
| 8180 |
unsafe { |
| 8181 |
#[repr(align(1))] |
| 8182 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 8183 |
let mut ret_area = RetArea( |
| 8184 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 8185 |
); |
| 8186 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 8187 |
#[cfg(target_arch = "wasm32")] |
| 8188 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8189 |
unsafe extern "C" { |
| 8190 |
#[link_name = "[method]tcp-socket.start-listen"] |
| 8191 |
fn wit_import1(_: i32, _: *mut u8); |
| 8192 |
} |
| 8193 |
#[cfg(not(target_arch = "wasm32"))] |
| 8194 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 8195 |
unreachable!() |
| 8196 |
} |
| 8197 |
wit_import1((self).handle() as i32, ptr0); |
| 8198 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 8199 |
let result4 = match l2 { |
| 8200 |
0 => { |
| 8201 |
let e = (); |
| 8202 |
Ok(e) |
| 8203 |
} |
| 8204 |
1 => { |
| 8205 |
let e = { |
| 8206 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 8207 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 8208 |
l3 as u8, |
| 8209 |
) |
| 8210 |
}; |
| 8211 |
Err(e) |
| 8212 |
} |
| 8213 |
_ => _rt::invalid_enum_discriminant(), |
| 8214 |
}; |
| 8215 |
result4 |
| 8216 |
} |
| 8217 |
} |
| 8218 |
} |
| 8219 |
impl TcpSocket { |
| 8220 |
#[allow(unused_unsafe, clippy::all)] |
| 8221 |
#[allow(async_fn_in_trait)] |
| 8222 |
pub fn finish_listen(&self) -> Result<(), ErrorCode> { |
| 8223 |
unsafe { |
| 8224 |
#[repr(align(1))] |
| 8225 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 8226 |
let mut ret_area = RetArea( |
| 8227 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 8228 |
); |
| 8229 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 8230 |
#[cfg(target_arch = "wasm32")] |
| 8231 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8232 |
unsafe extern "C" { |
| 8233 |
#[link_name = "[method]tcp-socket.finish-listen"] |
| 8234 |
fn wit_import1(_: i32, _: *mut u8); |
| 8235 |
} |
| 8236 |
#[cfg(not(target_arch = "wasm32"))] |
| 8237 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 8238 |
unreachable!() |
| 8239 |
} |
| 8240 |
wit_import1((self).handle() as i32, ptr0); |
| 8241 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 8242 |
let result4 = match l2 { |
| 8243 |
0 => { |
| 8244 |
let e = (); |
| 8245 |
Ok(e) |
| 8246 |
} |
| 8247 |
1 => { |
| 8248 |
let e = { |
| 8249 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 8250 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 8251 |
l3 as u8, |
| 8252 |
) |
| 8253 |
}; |
| 8254 |
Err(e) |
| 8255 |
} |
| 8256 |
_ => _rt::invalid_enum_discriminant(), |
| 8257 |
}; |
| 8258 |
result4 |
| 8259 |
} |
| 8260 |
} |
| 8261 |
} |
| 8262 |
impl TcpSocket { |
| 8263 |
#[allow(unused_unsafe, clippy::all)] |
| 8264 |
/// Accept a new client socket. |
| 8265 |
/// |
| 8266 |
/// The returned socket is bound and in the `connected` state. The following properties are inherited from the listener socket: |
| 8267 |
/// - `address-family` |
| 8268 |
/// - `keep-alive-enabled` |
| 8269 |
/// - `keep-alive-idle-time` |
| 8270 |
/// - `keep-alive-interval` |
| 8271 |
/// - `keep-alive-count` |
| 8272 |
/// - `hop-limit` |
| 8273 |
/// - `receive-buffer-size` |
| 8274 |
/// - `send-buffer-size` |
| 8275 |
/// |
| 8276 |
/// On success, this function returns the newly accepted client socket along with |
| 8277 |
/// a pair of streams that can be used to read & write to the connection. |
| 8278 |
/// |
| 8279 |
/// # Typical errors |
| 8280 |
/// - `invalid-state`: Socket is not in the `listening` state. (EINVAL) |
| 8281 |
/// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN) |
| 8282 |
/// - `connection-aborted`: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED) |
| 8283 |
/// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) |
| 8284 |
/// |
| 8285 |
/// # References |
| 8286 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html> |
| 8287 |
/// - <https://man7.org/linux/man-pages/man2/accept.2.html> |
| 8288 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-accept> |
| 8289 |
/// - <https://man.freebsd.org/cgi/man.cgi?query=accept&sektion=2> |
| 8290 |
#[allow(async_fn_in_trait)] |
| 8291 |
pub fn accept( |
| 8292 |
&self, |
| 8293 |
) -> Result<(TcpSocket, InputStream, OutputStream), ErrorCode> { |
| 8294 |
unsafe { |
| 8295 |
#[repr(align(4))] |
| 8296 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 8297 |
let mut ret_area = RetArea( |
| 8298 |
[::core::mem::MaybeUninit::uninit(); 16], |
| 8299 |
); |
| 8300 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 8301 |
#[cfg(target_arch = "wasm32")] |
| 8302 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8303 |
unsafe extern "C" { |
| 8304 |
#[link_name = "[method]tcp-socket.accept"] |
| 8305 |
fn wit_import1(_: i32, _: *mut u8); |
| 8306 |
} |
| 8307 |
#[cfg(not(target_arch = "wasm32"))] |
| 8308 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 8309 |
unreachable!() |
| 8310 |
} |
| 8311 |
wit_import1((self).handle() as i32, ptr0); |
| 8312 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 8313 |
let result7 = match l2 { |
| 8314 |
0 => { |
| 8315 |
let e = { |
| 8316 |
let l3 = *ptr0.add(4).cast::<i32>(); |
| 8317 |
let l4 = *ptr0.add(8).cast::<i32>(); |
| 8318 |
let l5 = *ptr0.add(12).cast::<i32>(); |
| 8319 |
( |
| 8320 |
TcpSocket::from_handle(l3 as u32), |
| 8321 |
super::super::super::wasi::io::streams::InputStream::from_handle( |
| 8322 |
l4 as u32, |
| 8323 |
), |
| 8324 |
super::super::super::wasi::io::streams::OutputStream::from_handle( |
| 8325 |
l5 as u32, |
| 8326 |
), |
| 8327 |
) |
| 8328 |
}; |
| 8329 |
Ok(e) |
| 8330 |
} |
| 8331 |
1 => { |
| 8332 |
let e = { |
| 8333 |
let l6 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 8334 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 8335 |
l6 as u8, |
| 8336 |
) |
| 8337 |
}; |
| 8338 |
Err(e) |
| 8339 |
} |
| 8340 |
_ => _rt::invalid_enum_discriminant(), |
| 8341 |
}; |
| 8342 |
result7 |
| 8343 |
} |
| 8344 |
} |
| 8345 |
} |
| 8346 |
impl TcpSocket { |
| 8347 |
#[allow(unused_unsafe, clippy::all)] |
| 8348 |
/// Get the bound local address. |
| 8349 |
/// |
| 8350 |
/// POSIX mentions: |
| 8351 |
/// > If the socket has not been bound to a local name, the value |
| 8352 |
/// > stored in the object pointed to by `address` is unspecified. |
| 8353 |
/// |
| 8354 |
/// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. |
| 8355 |
/// |
| 8356 |
/// # Typical errors |
| 8357 |
/// - `invalid-state`: The socket is not bound to any local address. |
| 8358 |
/// |
| 8359 |
/// # References |
| 8360 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html> |
| 8361 |
/// - <https://man7.org/linux/man-pages/man2/getsockname.2.html> |
| 8362 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getsockname> |
| 8363 |
/// - <https://man.freebsd.org/cgi/man.cgi?getsockname> |
| 8364 |
#[allow(async_fn_in_trait)] |
| 8365 |
pub fn local_address(&self) -> Result<IpSocketAddress, ErrorCode> { |
| 8366 |
unsafe { |
| 8367 |
#[repr(align(4))] |
| 8368 |
struct RetArea([::core::mem::MaybeUninit<u8>; 36]); |
| 8369 |
let mut ret_area = RetArea( |
| 8370 |
[::core::mem::MaybeUninit::uninit(); 36], |
| 8371 |
); |
| 8372 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 8373 |
#[cfg(target_arch = "wasm32")] |
| 8374 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8375 |
unsafe extern "C" { |
| 8376 |
#[link_name = "[method]tcp-socket.local-address"] |
| 8377 |
fn wit_import1(_: i32, _: *mut u8); |
| 8378 |
} |
| 8379 |
#[cfg(not(target_arch = "wasm32"))] |
| 8380 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 8381 |
unreachable!() |
| 8382 |
} |
| 8383 |
wit_import1((self).handle() as i32, ptr0); |
| 8384 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 8385 |
let result22 = match l2 { |
| 8386 |
0 => { |
| 8387 |
let e = { |
| 8388 |
let l3 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 8389 |
use super::super::super::wasi::sockets::network::IpSocketAddress as V20; |
| 8390 |
let v20 = match l3 { |
| 8391 |
0 => { |
| 8392 |
let e20 = { |
| 8393 |
let l4 = i32::from(*ptr0.add(8).cast::<u16>()); |
| 8394 |
let l5 = i32::from(*ptr0.add(10).cast::<u8>()); |
| 8395 |
let l6 = i32::from(*ptr0.add(11).cast::<u8>()); |
| 8396 |
let l7 = i32::from(*ptr0.add(12).cast::<u8>()); |
| 8397 |
let l8 = i32::from(*ptr0.add(13).cast::<u8>()); |
| 8398 |
super::super::super::wasi::sockets::network::Ipv4SocketAddress { |
| 8399 |
port: l4 as u16, |
| 8400 |
address: (l5 as u8, l6 as u8, l7 as u8, l8 as u8), |
| 8401 |
} |
| 8402 |
}; |
| 8403 |
V20::Ipv4(e20) |
| 8404 |
} |
| 8405 |
n => { |
| 8406 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 8407 |
let e20 = { |
| 8408 |
let l9 = i32::from(*ptr0.add(8).cast::<u16>()); |
| 8409 |
let l10 = *ptr0.add(12).cast::<i32>(); |
| 8410 |
let l11 = i32::from(*ptr0.add(16).cast::<u16>()); |
| 8411 |
let l12 = i32::from(*ptr0.add(18).cast::<u16>()); |
| 8412 |
let l13 = i32::from(*ptr0.add(20).cast::<u16>()); |
| 8413 |
let l14 = i32::from(*ptr0.add(22).cast::<u16>()); |
| 8414 |
let l15 = i32::from(*ptr0.add(24).cast::<u16>()); |
| 8415 |
let l16 = i32::from(*ptr0.add(26).cast::<u16>()); |
| 8416 |
let l17 = i32::from(*ptr0.add(28).cast::<u16>()); |
| 8417 |
let l18 = i32::from(*ptr0.add(30).cast::<u16>()); |
| 8418 |
let l19 = *ptr0.add(32).cast::<i32>(); |
| 8419 |
super::super::super::wasi::sockets::network::Ipv6SocketAddress { |
| 8420 |
port: l9 as u16, |
| 8421 |
flow_info: l10 as u32, |
| 8422 |
address: ( |
| 8423 |
l11 as u16, |
| 8424 |
l12 as u16, |
| 8425 |
l13 as u16, |
| 8426 |
l14 as u16, |
| 8427 |
l15 as u16, |
| 8428 |
l16 as u16, |
| 8429 |
l17 as u16, |
| 8430 |
l18 as u16, |
| 8431 |
), |
| 8432 |
scope_id: l19 as u32, |
| 8433 |
} |
| 8434 |
}; |
| 8435 |
V20::Ipv6(e20) |
| 8436 |
} |
| 8437 |
}; |
| 8438 |
v20 |
| 8439 |
}; |
| 8440 |
Ok(e) |
| 8441 |
} |
| 8442 |
1 => { |
| 8443 |
let e = { |
| 8444 |
let l21 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 8445 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 8446 |
l21 as u8, |
| 8447 |
) |
| 8448 |
}; |
| 8449 |
Err(e) |
| 8450 |
} |
| 8451 |
_ => _rt::invalid_enum_discriminant(), |
| 8452 |
}; |
| 8453 |
result22 |
| 8454 |
} |
| 8455 |
} |
| 8456 |
} |
| 8457 |
impl TcpSocket { |
| 8458 |
#[allow(unused_unsafe, clippy::all)] |
| 8459 |
/// Get the remote address. |
| 8460 |
/// |
| 8461 |
/// # Typical errors |
| 8462 |
/// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) |
| 8463 |
/// |
| 8464 |
/// # References |
| 8465 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html> |
| 8466 |
/// - <https://man7.org/linux/man-pages/man2/getpeername.2.html> |
| 8467 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getpeername> |
| 8468 |
/// - <https://man.freebsd.org/cgi/man.cgi?query=getpeername&sektion=2&n=1> |
| 8469 |
#[allow(async_fn_in_trait)] |
| 8470 |
pub fn remote_address(&self) -> Result<IpSocketAddress, ErrorCode> { |
| 8471 |
unsafe { |
| 8472 |
#[repr(align(4))] |
| 8473 |
struct RetArea([::core::mem::MaybeUninit<u8>; 36]); |
| 8474 |
let mut ret_area = RetArea( |
| 8475 |
[::core::mem::MaybeUninit::uninit(); 36], |
| 8476 |
); |
| 8477 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 8478 |
#[cfg(target_arch = "wasm32")] |
| 8479 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8480 |
unsafe extern "C" { |
| 8481 |
#[link_name = "[method]tcp-socket.remote-address"] |
| 8482 |
fn wit_import1(_: i32, _: *mut u8); |
| 8483 |
} |
| 8484 |
#[cfg(not(target_arch = "wasm32"))] |
| 8485 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 8486 |
unreachable!() |
| 8487 |
} |
| 8488 |
wit_import1((self).handle() as i32, ptr0); |
| 8489 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 8490 |
let result22 = match l2 { |
| 8491 |
0 => { |
| 8492 |
let e = { |
| 8493 |
let l3 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 8494 |
use super::super::super::wasi::sockets::network::IpSocketAddress as V20; |
| 8495 |
let v20 = match l3 { |
| 8496 |
0 => { |
| 8497 |
let e20 = { |
| 8498 |
let l4 = i32::from(*ptr0.add(8).cast::<u16>()); |
| 8499 |
let l5 = i32::from(*ptr0.add(10).cast::<u8>()); |
| 8500 |
let l6 = i32::from(*ptr0.add(11).cast::<u8>()); |
| 8501 |
let l7 = i32::from(*ptr0.add(12).cast::<u8>()); |
| 8502 |
let l8 = i32::from(*ptr0.add(13).cast::<u8>()); |
| 8503 |
super::super::super::wasi::sockets::network::Ipv4SocketAddress { |
| 8504 |
port: l4 as u16, |
| 8505 |
address: (l5 as u8, l6 as u8, l7 as u8, l8 as u8), |
| 8506 |
} |
| 8507 |
}; |
| 8508 |
V20::Ipv4(e20) |
| 8509 |
} |
| 8510 |
n => { |
| 8511 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 8512 |
let e20 = { |
| 8513 |
let l9 = i32::from(*ptr0.add(8).cast::<u16>()); |
| 8514 |
let l10 = *ptr0.add(12).cast::<i32>(); |
| 8515 |
let l11 = i32::from(*ptr0.add(16).cast::<u16>()); |
| 8516 |
let l12 = i32::from(*ptr0.add(18).cast::<u16>()); |
| 8517 |
let l13 = i32::from(*ptr0.add(20).cast::<u16>()); |
| 8518 |
let l14 = i32::from(*ptr0.add(22).cast::<u16>()); |
| 8519 |
let l15 = i32::from(*ptr0.add(24).cast::<u16>()); |
| 8520 |
let l16 = i32::from(*ptr0.add(26).cast::<u16>()); |
| 8521 |
let l17 = i32::from(*ptr0.add(28).cast::<u16>()); |
| 8522 |
let l18 = i32::from(*ptr0.add(30).cast::<u16>()); |
| 8523 |
let l19 = *ptr0.add(32).cast::<i32>(); |
| 8524 |
super::super::super::wasi::sockets::network::Ipv6SocketAddress { |
| 8525 |
port: l9 as u16, |
| 8526 |
flow_info: l10 as u32, |
| 8527 |
address: ( |
| 8528 |
l11 as u16, |
| 8529 |
l12 as u16, |
| 8530 |
l13 as u16, |
| 8531 |
l14 as u16, |
| 8532 |
l15 as u16, |
| 8533 |
l16 as u16, |
| 8534 |
l17 as u16, |
| 8535 |
l18 as u16, |
| 8536 |
), |
| 8537 |
scope_id: l19 as u32, |
| 8538 |
} |
| 8539 |
}; |
| 8540 |
V20::Ipv6(e20) |
| 8541 |
} |
| 8542 |
}; |
| 8543 |
v20 |
| 8544 |
}; |
| 8545 |
Ok(e) |
| 8546 |
} |
| 8547 |
1 => { |
| 8548 |
let e = { |
| 8549 |
let l21 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 8550 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 8551 |
l21 as u8, |
| 8552 |
) |
| 8553 |
}; |
| 8554 |
Err(e) |
| 8555 |
} |
| 8556 |
_ => _rt::invalid_enum_discriminant(), |
| 8557 |
}; |
| 8558 |
result22 |
| 8559 |
} |
| 8560 |
} |
| 8561 |
} |
| 8562 |
impl TcpSocket { |
| 8563 |
#[allow(unused_unsafe, clippy::all)] |
| 8564 |
/// Whether the socket is in the `listening` state. |
| 8565 |
/// |
| 8566 |
/// Equivalent to the SO_ACCEPTCONN socket option. |
| 8567 |
#[allow(async_fn_in_trait)] |
| 8568 |
pub fn is_listening(&self) -> bool { |
| 8569 |
unsafe { |
| 8570 |
#[cfg(target_arch = "wasm32")] |
| 8571 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8572 |
unsafe extern "C" { |
| 8573 |
#[link_name = "[method]tcp-socket.is-listening"] |
| 8574 |
fn wit_import0(_: i32) -> i32; |
| 8575 |
} |
| 8576 |
#[cfg(not(target_arch = "wasm32"))] |
| 8577 |
unsafe extern "C" fn wit_import0(_: i32) -> i32 { |
| 8578 |
unreachable!() |
| 8579 |
} |
| 8580 |
let ret = wit_import0((self).handle() as i32); |
| 8581 |
_rt::bool_lift(ret as u8) |
| 8582 |
} |
| 8583 |
} |
| 8584 |
} |
| 8585 |
impl TcpSocket { |
| 8586 |
#[allow(unused_unsafe, clippy::all)] |
| 8587 |
/// Whether this is a IPv4 or IPv6 socket. |
| 8588 |
/// |
| 8589 |
/// Equivalent to the SO_DOMAIN socket option. |
| 8590 |
#[allow(async_fn_in_trait)] |
| 8591 |
pub fn address_family(&self) -> IpAddressFamily { |
| 8592 |
unsafe { |
| 8593 |
#[cfg(target_arch = "wasm32")] |
| 8594 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8595 |
unsafe extern "C" { |
| 8596 |
#[link_name = "[method]tcp-socket.address-family"] |
| 8597 |
fn wit_import0(_: i32) -> i32; |
| 8598 |
} |
| 8599 |
#[cfg(not(target_arch = "wasm32"))] |
| 8600 |
unsafe extern "C" fn wit_import0(_: i32) -> i32 { |
| 8601 |
unreachable!() |
| 8602 |
} |
| 8603 |
let ret = wit_import0((self).handle() as i32); |
| 8604 |
super::super::super::wasi::sockets::network::IpAddressFamily::_lift( |
| 8605 |
ret as u8, |
| 8606 |
) |
| 8607 |
} |
| 8608 |
} |
| 8609 |
} |
| 8610 |
impl TcpSocket { |
| 8611 |
#[allow(unused_unsafe, clippy::all)] |
| 8612 |
/// Hints the desired listen queue size. Implementations are free to ignore this. |
| 8613 |
/// |
| 8614 |
/// If the provided value is 0, an `invalid-argument` error is returned. |
| 8615 |
/// Any other value will never cause an error, but it might be silently clamped and/or rounded. |
| 8616 |
/// |
| 8617 |
/// # Typical errors |
| 8618 |
/// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. |
| 8619 |
/// - `invalid-argument`: (set) The provided value was 0. |
| 8620 |
/// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state. |
| 8621 |
#[allow(async_fn_in_trait)] |
| 8622 |
pub fn set_listen_backlog_size( |
| 8623 |
&self, |
| 8624 |
value: u64, |
| 8625 |
) -> Result<(), ErrorCode> { |
| 8626 |
unsafe { |
| 8627 |
#[repr(align(1))] |
| 8628 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 8629 |
let mut ret_area = RetArea( |
| 8630 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 8631 |
); |
| 8632 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 8633 |
#[cfg(target_arch = "wasm32")] |
| 8634 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8635 |
unsafe extern "C" { |
| 8636 |
#[link_name = "[method]tcp-socket.set-listen-backlog-size"] |
| 8637 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 8638 |
} |
| 8639 |
#[cfg(not(target_arch = "wasm32"))] |
| 8640 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 8641 |
unreachable!() |
| 8642 |
} |
| 8643 |
wit_import1((self).handle() as i32, _rt::as_i64(&value), ptr0); |
| 8644 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 8645 |
let result4 = match l2 { |
| 8646 |
0 => { |
| 8647 |
let e = (); |
| 8648 |
Ok(e) |
| 8649 |
} |
| 8650 |
1 => { |
| 8651 |
let e = { |
| 8652 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 8653 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 8654 |
l3 as u8, |
| 8655 |
) |
| 8656 |
}; |
| 8657 |
Err(e) |
| 8658 |
} |
| 8659 |
_ => _rt::invalid_enum_discriminant(), |
| 8660 |
}; |
| 8661 |
result4 |
| 8662 |
} |
| 8663 |
} |
| 8664 |
} |
| 8665 |
impl TcpSocket { |
| 8666 |
#[allow(unused_unsafe, clippy::all)] |
| 8667 |
/// Enables or disables keepalive. |
| 8668 |
/// |
| 8669 |
/// The keepalive behavior can be adjusted using: |
| 8670 |
/// - `keep-alive-idle-time` |
| 8671 |
/// - `keep-alive-interval` |
| 8672 |
/// - `keep-alive-count` |
| 8673 |
/// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true. |
| 8674 |
/// |
| 8675 |
/// Equivalent to the SO_KEEPALIVE socket option. |
| 8676 |
#[allow(async_fn_in_trait)] |
| 8677 |
pub fn keep_alive_enabled(&self) -> Result<bool, ErrorCode> { |
| 8678 |
unsafe { |
| 8679 |
#[repr(align(1))] |
| 8680 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 8681 |
let mut ret_area = RetArea( |
| 8682 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 8683 |
); |
| 8684 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 8685 |
#[cfg(target_arch = "wasm32")] |
| 8686 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8687 |
unsafe extern "C" { |
| 8688 |
#[link_name = "[method]tcp-socket.keep-alive-enabled"] |
| 8689 |
fn wit_import1(_: i32, _: *mut u8); |
| 8690 |
} |
| 8691 |
#[cfg(not(target_arch = "wasm32"))] |
| 8692 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 8693 |
unreachable!() |
| 8694 |
} |
| 8695 |
wit_import1((self).handle() as i32, ptr0); |
| 8696 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 8697 |
let result5 = match l2 { |
| 8698 |
0 => { |
| 8699 |
let e = { |
| 8700 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 8701 |
_rt::bool_lift(l3 as u8) |
| 8702 |
}; |
| 8703 |
Ok(e) |
| 8704 |
} |
| 8705 |
1 => { |
| 8706 |
let e = { |
| 8707 |
let l4 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 8708 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 8709 |
l4 as u8, |
| 8710 |
) |
| 8711 |
}; |
| 8712 |
Err(e) |
| 8713 |
} |
| 8714 |
_ => _rt::invalid_enum_discriminant(), |
| 8715 |
}; |
| 8716 |
result5 |
| 8717 |
} |
| 8718 |
} |
| 8719 |
} |
| 8720 |
impl TcpSocket { |
| 8721 |
#[allow(unused_unsafe, clippy::all)] |
| 8722 |
#[allow(async_fn_in_trait)] |
| 8723 |
pub fn set_keep_alive_enabled( |
| 8724 |
&self, |
| 8725 |
value: bool, |
| 8726 |
) -> Result<(), ErrorCode> { |
| 8727 |
unsafe { |
| 8728 |
#[repr(align(1))] |
| 8729 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 8730 |
let mut ret_area = RetArea( |
| 8731 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 8732 |
); |
| 8733 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 8734 |
#[cfg(target_arch = "wasm32")] |
| 8735 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8736 |
unsafe extern "C" { |
| 8737 |
#[link_name = "[method]tcp-socket.set-keep-alive-enabled"] |
| 8738 |
fn wit_import1(_: i32, _: i32, _: *mut u8); |
| 8739 |
} |
| 8740 |
#[cfg(not(target_arch = "wasm32"))] |
| 8741 |
unsafe extern "C" fn wit_import1(_: i32, _: i32, _: *mut u8) { |
| 8742 |
unreachable!() |
| 8743 |
} |
| 8744 |
wit_import1( |
| 8745 |
(self).handle() as i32, |
| 8746 |
match &value { |
| 8747 |
true => 1, |
| 8748 |
false => 0, |
| 8749 |
}, |
| 8750 |
ptr0, |
| 8751 |
); |
| 8752 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 8753 |
let result4 = match l2 { |
| 8754 |
0 => { |
| 8755 |
let e = (); |
| 8756 |
Ok(e) |
| 8757 |
} |
| 8758 |
1 => { |
| 8759 |
let e = { |
| 8760 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 8761 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 8762 |
l3 as u8, |
| 8763 |
) |
| 8764 |
}; |
| 8765 |
Err(e) |
| 8766 |
} |
| 8767 |
_ => _rt::invalid_enum_discriminant(), |
| 8768 |
}; |
| 8769 |
result4 |
| 8770 |
} |
| 8771 |
} |
| 8772 |
} |
| 8773 |
impl TcpSocket { |
| 8774 |
#[allow(unused_unsafe, clippy::all)] |
| 8775 |
/// Amount of time the connection has to be idle before TCP starts sending keepalive packets. |
| 8776 |
/// |
| 8777 |
/// If the provided value is 0, an `invalid-argument` error is returned. |
| 8778 |
/// Any other value will never cause an error, but it might be silently clamped and/or rounded. |
| 8779 |
/// I.e. after setting a value, reading the same setting back may return a different value. |
| 8780 |
/// |
| 8781 |
/// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) |
| 8782 |
/// |
| 8783 |
/// # Typical errors |
| 8784 |
/// - `invalid-argument`: (set) The provided value was 0. |
| 8785 |
#[allow(async_fn_in_trait)] |
| 8786 |
pub fn keep_alive_idle_time(&self) -> Result<Duration, ErrorCode> { |
| 8787 |
unsafe { |
| 8788 |
#[repr(align(8))] |
| 8789 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 8790 |
let mut ret_area = RetArea( |
| 8791 |
[::core::mem::MaybeUninit::uninit(); 16], |
| 8792 |
); |
| 8793 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 8794 |
#[cfg(target_arch = "wasm32")] |
| 8795 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8796 |
unsafe extern "C" { |
| 8797 |
#[link_name = "[method]tcp-socket.keep-alive-idle-time"] |
| 8798 |
fn wit_import1(_: i32, _: *mut u8); |
| 8799 |
} |
| 8800 |
#[cfg(not(target_arch = "wasm32"))] |
| 8801 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 8802 |
unreachable!() |
| 8803 |
} |
| 8804 |
wit_import1((self).handle() as i32, ptr0); |
| 8805 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 8806 |
let result5 = match l2 { |
| 8807 |
0 => { |
| 8808 |
let e = { |
| 8809 |
let l3 = *ptr0.add(8).cast::<i64>(); |
| 8810 |
l3 as u64 |
| 8811 |
}; |
| 8812 |
Ok(e) |
| 8813 |
} |
| 8814 |
1 => { |
| 8815 |
let e = { |
| 8816 |
let l4 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 8817 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 8818 |
l4 as u8, |
| 8819 |
) |
| 8820 |
}; |
| 8821 |
Err(e) |
| 8822 |
} |
| 8823 |
_ => _rt::invalid_enum_discriminant(), |
| 8824 |
}; |
| 8825 |
result5 |
| 8826 |
} |
| 8827 |
} |
| 8828 |
} |
| 8829 |
impl TcpSocket { |
| 8830 |
#[allow(unused_unsafe, clippy::all)] |
| 8831 |
#[allow(async_fn_in_trait)] |
| 8832 |
pub fn set_keep_alive_idle_time( |
| 8833 |
&self, |
| 8834 |
value: Duration, |
| 8835 |
) -> Result<(), ErrorCode> { |
| 8836 |
unsafe { |
| 8837 |
#[repr(align(1))] |
| 8838 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 8839 |
let mut ret_area = RetArea( |
| 8840 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 8841 |
); |
| 8842 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 8843 |
#[cfg(target_arch = "wasm32")] |
| 8844 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8845 |
unsafe extern "C" { |
| 8846 |
#[link_name = "[method]tcp-socket.set-keep-alive-idle-time"] |
| 8847 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 8848 |
} |
| 8849 |
#[cfg(not(target_arch = "wasm32"))] |
| 8850 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 8851 |
unreachable!() |
| 8852 |
} |
| 8853 |
wit_import1((self).handle() as i32, _rt::as_i64(value), ptr0); |
| 8854 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 8855 |
let result4 = match l2 { |
| 8856 |
0 => { |
| 8857 |
let e = (); |
| 8858 |
Ok(e) |
| 8859 |
} |
| 8860 |
1 => { |
| 8861 |
let e = { |
| 8862 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 8863 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 8864 |
l3 as u8, |
| 8865 |
) |
| 8866 |
}; |
| 8867 |
Err(e) |
| 8868 |
} |
| 8869 |
_ => _rt::invalid_enum_discriminant(), |
| 8870 |
}; |
| 8871 |
result4 |
| 8872 |
} |
| 8873 |
} |
| 8874 |
} |
| 8875 |
impl TcpSocket { |
| 8876 |
#[allow(unused_unsafe, clippy::all)] |
| 8877 |
/// The time between keepalive packets. |
| 8878 |
/// |
| 8879 |
/// If the provided value is 0, an `invalid-argument` error is returned. |
| 8880 |
/// Any other value will never cause an error, but it might be silently clamped and/or rounded. |
| 8881 |
/// I.e. after setting a value, reading the same setting back may return a different value. |
| 8882 |
/// |
| 8883 |
/// Equivalent to the TCP_KEEPINTVL socket option. |
| 8884 |
/// |
| 8885 |
/// # Typical errors |
| 8886 |
/// - `invalid-argument`: (set) The provided value was 0. |
| 8887 |
#[allow(async_fn_in_trait)] |
| 8888 |
pub fn keep_alive_interval(&self) -> Result<Duration, ErrorCode> { |
| 8889 |
unsafe { |
| 8890 |
#[repr(align(8))] |
| 8891 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 8892 |
let mut ret_area = RetArea( |
| 8893 |
[::core::mem::MaybeUninit::uninit(); 16], |
| 8894 |
); |
| 8895 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 8896 |
#[cfg(target_arch = "wasm32")] |
| 8897 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8898 |
unsafe extern "C" { |
| 8899 |
#[link_name = "[method]tcp-socket.keep-alive-interval"] |
| 8900 |
fn wit_import1(_: i32, _: *mut u8); |
| 8901 |
} |
| 8902 |
#[cfg(not(target_arch = "wasm32"))] |
| 8903 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 8904 |
unreachable!() |
| 8905 |
} |
| 8906 |
wit_import1((self).handle() as i32, ptr0); |
| 8907 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 8908 |
let result5 = match l2 { |
| 8909 |
0 => { |
| 8910 |
let e = { |
| 8911 |
let l3 = *ptr0.add(8).cast::<i64>(); |
| 8912 |
l3 as u64 |
| 8913 |
}; |
| 8914 |
Ok(e) |
| 8915 |
} |
| 8916 |
1 => { |
| 8917 |
let e = { |
| 8918 |
let l4 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 8919 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 8920 |
l4 as u8, |
| 8921 |
) |
| 8922 |
}; |
| 8923 |
Err(e) |
| 8924 |
} |
| 8925 |
_ => _rt::invalid_enum_discriminant(), |
| 8926 |
}; |
| 8927 |
result5 |
| 8928 |
} |
| 8929 |
} |
| 8930 |
} |
| 8931 |
impl TcpSocket { |
| 8932 |
#[allow(unused_unsafe, clippy::all)] |
| 8933 |
#[allow(async_fn_in_trait)] |
| 8934 |
pub fn set_keep_alive_interval( |
| 8935 |
&self, |
| 8936 |
value: Duration, |
| 8937 |
) -> Result<(), ErrorCode> { |
| 8938 |
unsafe { |
| 8939 |
#[repr(align(1))] |
| 8940 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 8941 |
let mut ret_area = RetArea( |
| 8942 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 8943 |
); |
| 8944 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 8945 |
#[cfg(target_arch = "wasm32")] |
| 8946 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 8947 |
unsafe extern "C" { |
| 8948 |
#[link_name = "[method]tcp-socket.set-keep-alive-interval"] |
| 8949 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 8950 |
} |
| 8951 |
#[cfg(not(target_arch = "wasm32"))] |
| 8952 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 8953 |
unreachable!() |
| 8954 |
} |
| 8955 |
wit_import1((self).handle() as i32, _rt::as_i64(value), ptr0); |
| 8956 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 8957 |
let result4 = match l2 { |
| 8958 |
0 => { |
| 8959 |
let e = (); |
| 8960 |
Ok(e) |
| 8961 |
} |
| 8962 |
1 => { |
| 8963 |
let e = { |
| 8964 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 8965 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 8966 |
l3 as u8, |
| 8967 |
) |
| 8968 |
}; |
| 8969 |
Err(e) |
| 8970 |
} |
| 8971 |
_ => _rt::invalid_enum_discriminant(), |
| 8972 |
}; |
| 8973 |
result4 |
| 8974 |
} |
| 8975 |
} |
| 8976 |
} |
| 8977 |
impl TcpSocket { |
| 8978 |
#[allow(unused_unsafe, clippy::all)] |
| 8979 |
/// The maximum amount of keepalive packets TCP should send before aborting the connection. |
| 8980 |
/// |
| 8981 |
/// If the provided value is 0, an `invalid-argument` error is returned. |
| 8982 |
/// Any other value will never cause an error, but it might be silently clamped and/or rounded. |
| 8983 |
/// I.e. after setting a value, reading the same setting back may return a different value. |
| 8984 |
/// |
| 8985 |
/// Equivalent to the TCP_KEEPCNT socket option. |
| 8986 |
/// |
| 8987 |
/// # Typical errors |
| 8988 |
/// - `invalid-argument`: (set) The provided value was 0. |
| 8989 |
#[allow(async_fn_in_trait)] |
| 8990 |
pub fn keep_alive_count(&self) -> Result<u32, ErrorCode> { |
| 8991 |
unsafe { |
| 8992 |
#[repr(align(4))] |
| 8993 |
struct RetArea([::core::mem::MaybeUninit<u8>; 8]); |
| 8994 |
let mut ret_area = RetArea( |
| 8995 |
[::core::mem::MaybeUninit::uninit(); 8], |
| 8996 |
); |
| 8997 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 8998 |
#[cfg(target_arch = "wasm32")] |
| 8999 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 9000 |
unsafe extern "C" { |
| 9001 |
#[link_name = "[method]tcp-socket.keep-alive-count"] |
| 9002 |
fn wit_import1(_: i32, _: *mut u8); |
| 9003 |
} |
| 9004 |
#[cfg(not(target_arch = "wasm32"))] |
| 9005 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 9006 |
unreachable!() |
| 9007 |
} |
| 9008 |
wit_import1((self).handle() as i32, ptr0); |
| 9009 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 9010 |
let result5 = match l2 { |
| 9011 |
0 => { |
| 9012 |
let e = { |
| 9013 |
let l3 = *ptr0.add(4).cast::<i32>(); |
| 9014 |
l3 as u32 |
| 9015 |
}; |
| 9016 |
Ok(e) |
| 9017 |
} |
| 9018 |
1 => { |
| 9019 |
let e = { |
| 9020 |
let l4 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 9021 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 9022 |
l4 as u8, |
| 9023 |
) |
| 9024 |
}; |
| 9025 |
Err(e) |
| 9026 |
} |
| 9027 |
_ => _rt::invalid_enum_discriminant(), |
| 9028 |
}; |
| 9029 |
result5 |
| 9030 |
} |
| 9031 |
} |
| 9032 |
} |
| 9033 |
impl TcpSocket { |
| 9034 |
#[allow(unused_unsafe, clippy::all)] |
| 9035 |
#[allow(async_fn_in_trait)] |
| 9036 |
pub fn set_keep_alive_count(&self, value: u32) -> Result<(), ErrorCode> { |
| 9037 |
unsafe { |
| 9038 |
#[repr(align(1))] |
| 9039 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 9040 |
let mut ret_area = RetArea( |
| 9041 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 9042 |
); |
| 9043 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 9044 |
#[cfg(target_arch = "wasm32")] |
| 9045 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 9046 |
unsafe extern "C" { |
| 9047 |
#[link_name = "[method]tcp-socket.set-keep-alive-count"] |
| 9048 |
fn wit_import1(_: i32, _: i32, _: *mut u8); |
| 9049 |
} |
| 9050 |
#[cfg(not(target_arch = "wasm32"))] |
| 9051 |
unsafe extern "C" fn wit_import1(_: i32, _: i32, _: *mut u8) { |
| 9052 |
unreachable!() |
| 9053 |
} |
| 9054 |
wit_import1((self).handle() as i32, _rt::as_i32(&value), ptr0); |
| 9055 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 9056 |
let result4 = match l2 { |
| 9057 |
0 => { |
| 9058 |
let e = (); |
| 9059 |
Ok(e) |
| 9060 |
} |
| 9061 |
1 => { |
| 9062 |
let e = { |
| 9063 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 9064 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 9065 |
l3 as u8, |
| 9066 |
) |
| 9067 |
}; |
| 9068 |
Err(e) |
| 9069 |
} |
| 9070 |
_ => _rt::invalid_enum_discriminant(), |
| 9071 |
}; |
| 9072 |
result4 |
| 9073 |
} |
| 9074 |
} |
| 9075 |
} |
| 9076 |
impl TcpSocket { |
| 9077 |
#[allow(unused_unsafe, clippy::all)] |
| 9078 |
/// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. |
| 9079 |
/// |
| 9080 |
/// If the provided value is 0, an `invalid-argument` error is returned. |
| 9081 |
/// |
| 9082 |
/// # Typical errors |
| 9083 |
/// - `invalid-argument`: (set) The TTL value must be 1 or higher. |
| 9084 |
#[allow(async_fn_in_trait)] |
| 9085 |
pub fn hop_limit(&self) -> Result<u8, ErrorCode> { |
| 9086 |
unsafe { |
| 9087 |
#[repr(align(1))] |
| 9088 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 9089 |
let mut ret_area = RetArea( |
| 9090 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 9091 |
); |
| 9092 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 9093 |
#[cfg(target_arch = "wasm32")] |
| 9094 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 9095 |
unsafe extern "C" { |
| 9096 |
#[link_name = "[method]tcp-socket.hop-limit"] |
| 9097 |
fn wit_import1(_: i32, _: *mut u8); |
| 9098 |
} |
| 9099 |
#[cfg(not(target_arch = "wasm32"))] |
| 9100 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 9101 |
unreachable!() |
| 9102 |
} |
| 9103 |
wit_import1((self).handle() as i32, ptr0); |
| 9104 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 9105 |
let result5 = match l2 { |
| 9106 |
0 => { |
| 9107 |
let e = { |
| 9108 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 9109 |
l3 as u8 |
| 9110 |
}; |
| 9111 |
Ok(e) |
| 9112 |
} |
| 9113 |
1 => { |
| 9114 |
let e = { |
| 9115 |
let l4 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 9116 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 9117 |
l4 as u8, |
| 9118 |
) |
| 9119 |
}; |
| 9120 |
Err(e) |
| 9121 |
} |
| 9122 |
_ => _rt::invalid_enum_discriminant(), |
| 9123 |
}; |
| 9124 |
result5 |
| 9125 |
} |
| 9126 |
} |
| 9127 |
} |
| 9128 |
impl TcpSocket { |
| 9129 |
#[allow(unused_unsafe, clippy::all)] |
| 9130 |
#[allow(async_fn_in_trait)] |
| 9131 |
pub fn set_hop_limit(&self, value: u8) -> Result<(), ErrorCode> { |
| 9132 |
unsafe { |
| 9133 |
#[repr(align(1))] |
| 9134 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 9135 |
let mut ret_area = RetArea( |
| 9136 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 9137 |
); |
| 9138 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 9139 |
#[cfg(target_arch = "wasm32")] |
| 9140 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 9141 |
unsafe extern "C" { |
| 9142 |
#[link_name = "[method]tcp-socket.set-hop-limit"] |
| 9143 |
fn wit_import1(_: i32, _: i32, _: *mut u8); |
| 9144 |
} |
| 9145 |
#[cfg(not(target_arch = "wasm32"))] |
| 9146 |
unsafe extern "C" fn wit_import1(_: i32, _: i32, _: *mut u8) { |
| 9147 |
unreachable!() |
| 9148 |
} |
| 9149 |
wit_import1((self).handle() as i32, _rt::as_i32(&value), ptr0); |
| 9150 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 9151 |
let result4 = match l2 { |
| 9152 |
0 => { |
| 9153 |
let e = (); |
| 9154 |
Ok(e) |
| 9155 |
} |
| 9156 |
1 => { |
| 9157 |
let e = { |
| 9158 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 9159 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 9160 |
l3 as u8, |
| 9161 |
) |
| 9162 |
}; |
| 9163 |
Err(e) |
| 9164 |
} |
| 9165 |
_ => _rt::invalid_enum_discriminant(), |
| 9166 |
}; |
| 9167 |
result4 |
| 9168 |
} |
| 9169 |
} |
| 9170 |
} |
| 9171 |
impl TcpSocket { |
| 9172 |
#[allow(unused_unsafe, clippy::all)] |
| 9173 |
/// The kernel buffer space reserved for sends/receives on this socket. |
| 9174 |
/// |
| 9175 |
/// If the provided value is 0, an `invalid-argument` error is returned. |
| 9176 |
/// Any other value will never cause an error, but it might be silently clamped and/or rounded. |
| 9177 |
/// I.e. after setting a value, reading the same setting back may return a different value. |
| 9178 |
/// |
| 9179 |
/// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. |
| 9180 |
/// |
| 9181 |
/// # Typical errors |
| 9182 |
/// - `invalid-argument`: (set) The provided value was 0. |
| 9183 |
#[allow(async_fn_in_trait)] |
| 9184 |
pub fn receive_buffer_size(&self) -> Result<u64, ErrorCode> { |
| 9185 |
unsafe { |
| 9186 |
#[repr(align(8))] |
| 9187 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 9188 |
let mut ret_area = RetArea( |
| 9189 |
[::core::mem::MaybeUninit::uninit(); 16], |
| 9190 |
); |
| 9191 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 9192 |
#[cfg(target_arch = "wasm32")] |
| 9193 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 9194 |
unsafe extern "C" { |
| 9195 |
#[link_name = "[method]tcp-socket.receive-buffer-size"] |
| 9196 |
fn wit_import1(_: i32, _: *mut u8); |
| 9197 |
} |
| 9198 |
#[cfg(not(target_arch = "wasm32"))] |
| 9199 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 9200 |
unreachable!() |
| 9201 |
} |
| 9202 |
wit_import1((self).handle() as i32, ptr0); |
| 9203 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 9204 |
let result5 = match l2 { |
| 9205 |
0 => { |
| 9206 |
let e = { |
| 9207 |
let l3 = *ptr0.add(8).cast::<i64>(); |
| 9208 |
l3 as u64 |
| 9209 |
}; |
| 9210 |
Ok(e) |
| 9211 |
} |
| 9212 |
1 => { |
| 9213 |
let e = { |
| 9214 |
let l4 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 9215 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 9216 |
l4 as u8, |
| 9217 |
) |
| 9218 |
}; |
| 9219 |
Err(e) |
| 9220 |
} |
| 9221 |
_ => _rt::invalid_enum_discriminant(), |
| 9222 |
}; |
| 9223 |
result5 |
| 9224 |
} |
| 9225 |
} |
| 9226 |
} |
| 9227 |
impl TcpSocket { |
| 9228 |
#[allow(unused_unsafe, clippy::all)] |
| 9229 |
#[allow(async_fn_in_trait)] |
| 9230 |
pub fn set_receive_buffer_size( |
| 9231 |
&self, |
| 9232 |
value: u64, |
| 9233 |
) -> Result<(), ErrorCode> { |
| 9234 |
unsafe { |
| 9235 |
#[repr(align(1))] |
| 9236 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 9237 |
let mut ret_area = RetArea( |
| 9238 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 9239 |
); |
| 9240 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 9241 |
#[cfg(target_arch = "wasm32")] |
| 9242 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 9243 |
unsafe extern "C" { |
| 9244 |
#[link_name = "[method]tcp-socket.set-receive-buffer-size"] |
| 9245 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 9246 |
} |
| 9247 |
#[cfg(not(target_arch = "wasm32"))] |
| 9248 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 9249 |
unreachable!() |
| 9250 |
} |
| 9251 |
wit_import1((self).handle() as i32, _rt::as_i64(&value), ptr0); |
| 9252 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 9253 |
let result4 = match l2 { |
| 9254 |
0 => { |
| 9255 |
let e = (); |
| 9256 |
Ok(e) |
| 9257 |
} |
| 9258 |
1 => { |
| 9259 |
let e = { |
| 9260 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 9261 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 9262 |
l3 as u8, |
| 9263 |
) |
| 9264 |
}; |
| 9265 |
Err(e) |
| 9266 |
} |
| 9267 |
_ => _rt::invalid_enum_discriminant(), |
| 9268 |
}; |
| 9269 |
result4 |
| 9270 |
} |
| 9271 |
} |
| 9272 |
} |
| 9273 |
impl TcpSocket { |
| 9274 |
#[allow(unused_unsafe, clippy::all)] |
| 9275 |
#[allow(async_fn_in_trait)] |
| 9276 |
pub fn send_buffer_size(&self) -> Result<u64, ErrorCode> { |
| 9277 |
unsafe { |
| 9278 |
#[repr(align(8))] |
| 9279 |
struct RetArea([::core::mem::MaybeUninit<u8>; 16]); |
| 9280 |
let mut ret_area = RetArea( |
| 9281 |
[::core::mem::MaybeUninit::uninit(); 16], |
| 9282 |
); |
| 9283 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 9284 |
#[cfg(target_arch = "wasm32")] |
| 9285 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 9286 |
unsafe extern "C" { |
| 9287 |
#[link_name = "[method]tcp-socket.send-buffer-size"] |
| 9288 |
fn wit_import1(_: i32, _: *mut u8); |
| 9289 |
} |
| 9290 |
#[cfg(not(target_arch = "wasm32"))] |
| 9291 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 9292 |
unreachable!() |
| 9293 |
} |
| 9294 |
wit_import1((self).handle() as i32, ptr0); |
| 9295 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 9296 |
let result5 = match l2 { |
| 9297 |
0 => { |
| 9298 |
let e = { |
| 9299 |
let l3 = *ptr0.add(8).cast::<i64>(); |
| 9300 |
l3 as u64 |
| 9301 |
}; |
| 9302 |
Ok(e) |
| 9303 |
} |
| 9304 |
1 => { |
| 9305 |
let e = { |
| 9306 |
let l4 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 9307 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 9308 |
l4 as u8, |
| 9309 |
) |
| 9310 |
}; |
| 9311 |
Err(e) |
| 9312 |
} |
| 9313 |
_ => _rt::invalid_enum_discriminant(), |
| 9314 |
}; |
| 9315 |
result5 |
| 9316 |
} |
| 9317 |
} |
| 9318 |
} |
| 9319 |
impl TcpSocket { |
| 9320 |
#[allow(unused_unsafe, clippy::all)] |
| 9321 |
#[allow(async_fn_in_trait)] |
| 9322 |
pub fn set_send_buffer_size(&self, value: u64) -> Result<(), ErrorCode> { |
| 9323 |
unsafe { |
| 9324 |
#[repr(align(1))] |
| 9325 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 9326 |
let mut ret_area = RetArea( |
| 9327 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 9328 |
); |
| 9329 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 9330 |
#[cfg(target_arch = "wasm32")] |
| 9331 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 9332 |
unsafe extern "C" { |
| 9333 |
#[link_name = "[method]tcp-socket.set-send-buffer-size"] |
| 9334 |
fn wit_import1(_: i32, _: i64, _: *mut u8); |
| 9335 |
} |
| 9336 |
#[cfg(not(target_arch = "wasm32"))] |
| 9337 |
unsafe extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) { |
| 9338 |
unreachable!() |
| 9339 |
} |
| 9340 |
wit_import1((self).handle() as i32, _rt::as_i64(&value), ptr0); |
| 9341 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 9342 |
let result4 = match l2 { |
| 9343 |
0 => { |
| 9344 |
let e = (); |
| 9345 |
Ok(e) |
| 9346 |
} |
| 9347 |
1 => { |
| 9348 |
let e = { |
| 9349 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 9350 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 9351 |
l3 as u8, |
| 9352 |
) |
| 9353 |
}; |
| 9354 |
Err(e) |
| 9355 |
} |
| 9356 |
_ => _rt::invalid_enum_discriminant(), |
| 9357 |
}; |
| 9358 |
result4 |
| 9359 |
} |
| 9360 |
} |
| 9361 |
} |
| 9362 |
impl TcpSocket { |
| 9363 |
#[allow(unused_unsafe, clippy::all)] |
| 9364 |
/// Create a `pollable` which can be used to poll for, or block on, |
| 9365 |
/// completion of any of the asynchronous operations of this socket. |
| 9366 |
/// |
| 9367 |
/// When `finish-bind`, `finish-listen`, `finish-connect` or `accept` |
| 9368 |
/// return `error(would-block)`, this pollable can be used to wait for |
| 9369 |
/// their success or failure, after which the method can be retried. |
| 9370 |
/// |
| 9371 |
/// The pollable is not limited to the async operation that happens to be |
| 9372 |
/// in progress at the time of calling `subscribe` (if any). Theoretically, |
| 9373 |
/// `subscribe` only has to be called once per socket and can then be |
| 9374 |
/// (re)used for the remainder of the socket's lifetime. |
| 9375 |
/// |
| 9376 |
/// See <https://github.com/WebAssembly/wasi-sockets/blob/main/TcpSocketOperationalSemantics.md#pollable-readiness> |
| 9377 |
/// for more information. |
| 9378 |
/// |
| 9379 |
/// Note: this function is here for WASI 0.2 only. |
| 9380 |
/// It's planned to be removed when `future` is natively supported in Preview3. |
| 9381 |
#[allow(async_fn_in_trait)] |
| 9382 |
pub fn subscribe(&self) -> Pollable { |
| 9383 |
unsafe { |
| 9384 |
#[cfg(target_arch = "wasm32")] |
| 9385 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 9386 |
unsafe extern "C" { |
| 9387 |
#[link_name = "[method]tcp-socket.subscribe"] |
| 9388 |
fn wit_import0(_: i32) -> i32; |
| 9389 |
} |
| 9390 |
#[cfg(not(target_arch = "wasm32"))] |
| 9391 |
unsafe extern "C" fn wit_import0(_: i32) -> i32 { |
| 9392 |
unreachable!() |
| 9393 |
} |
| 9394 |
let ret = wit_import0((self).handle() as i32); |
| 9395 |
super::super::super::wasi::io::poll::Pollable::from_handle( |
| 9396 |
ret as u32, |
| 9397 |
) |
| 9398 |
} |
| 9399 |
} |
| 9400 |
} |
| 9401 |
impl TcpSocket { |
| 9402 |
#[allow(unused_unsafe, clippy::all)] |
| 9403 |
/// Initiate a graceful shutdown. |
| 9404 |
/// |
| 9405 |
/// - `receive`: The socket is not expecting to receive any data from |
| 9406 |
/// the peer. The `input-stream` associated with this socket will be |
| 9407 |
/// closed. Any data still in the receive queue at time of calling |
| 9408 |
/// this method will be discarded. |
| 9409 |
/// - `send`: The socket has no more data to send to the peer. The `output-stream` |
| 9410 |
/// associated with this socket will be closed and a FIN packet will be sent. |
| 9411 |
/// - `both`: Same effect as `receive` & `send` combined. |
| 9412 |
/// |
| 9413 |
/// This function is idempotent; shutting down a direction more than once |
| 9414 |
/// has no effect and returns `ok`. |
| 9415 |
/// |
| 9416 |
/// The shutdown function does not close (drop) the socket. |
| 9417 |
/// |
| 9418 |
/// # Typical errors |
| 9419 |
/// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) |
| 9420 |
/// |
| 9421 |
/// # References |
| 9422 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/shutdown.html> |
| 9423 |
/// - <https://man7.org/linux/man-pages/man2/shutdown.2.html> |
| 9424 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-shutdown> |
| 9425 |
/// - <https://man.freebsd.org/cgi/man.cgi?query=shutdown&sektion=2> |
| 9426 |
#[allow(async_fn_in_trait)] |
| 9427 |
pub fn shutdown( |
| 9428 |
&self, |
| 9429 |
shutdown_type: ShutdownType, |
| 9430 |
) -> Result<(), ErrorCode> { |
| 9431 |
unsafe { |
| 9432 |
#[repr(align(1))] |
| 9433 |
struct RetArea([::core::mem::MaybeUninit<u8>; 2]); |
| 9434 |
let mut ret_area = RetArea( |
| 9435 |
[::core::mem::MaybeUninit::uninit(); 2], |
| 9436 |
); |
| 9437 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 9438 |
#[cfg(target_arch = "wasm32")] |
| 9439 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 9440 |
unsafe extern "C" { |
| 9441 |
#[link_name = "[method]tcp-socket.shutdown"] |
| 9442 |
fn wit_import1(_: i32, _: i32, _: *mut u8); |
| 9443 |
} |
| 9444 |
#[cfg(not(target_arch = "wasm32"))] |
| 9445 |
unsafe extern "C" fn wit_import1(_: i32, _: i32, _: *mut u8) { |
| 9446 |
unreachable!() |
| 9447 |
} |
| 9448 |
wit_import1( |
| 9449 |
(self).handle() as i32, |
| 9450 |
shutdown_type.clone() as i32, |
| 9451 |
ptr0, |
| 9452 |
); |
| 9453 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 9454 |
let result4 = match l2 { |
| 9455 |
0 => { |
| 9456 |
let e = (); |
| 9457 |
Ok(e) |
| 9458 |
} |
| 9459 |
1 => { |
| 9460 |
let e = { |
| 9461 |
let l3 = i32::from(*ptr0.add(1).cast::<u8>()); |
| 9462 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 9463 |
l3 as u8, |
| 9464 |
) |
| 9465 |
}; |
| 9466 |
Err(e) |
| 9467 |
} |
| 9468 |
_ => _rt::invalid_enum_discriminant(), |
| 9469 |
}; |
| 9470 |
result4 |
| 9471 |
} |
| 9472 |
} |
| 9473 |
} |
| 9474 |
} |
| 9475 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 9476 |
pub mod tcp_create_socket { |
| 9477 |
#[used] |
| 9478 |
#[doc(hidden)] |
| 9479 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 9480 |
use super::super::super::_rt; |
| 9481 |
pub type ErrorCode = super::super::super::wasi::sockets::network::ErrorCode; |
| 9482 |
pub type IpAddressFamily = super::super::super::wasi::sockets::network::IpAddressFamily; |
| 9483 |
pub type TcpSocket = super::super::super::wasi::sockets::tcp::TcpSocket; |
| 9484 |
#[allow(unused_unsafe, clippy::all)] |
| 9485 |
/// Create a new TCP socket. |
| 9486 |
/// |
| 9487 |
/// Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX. |
| 9488 |
/// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. |
| 9489 |
/// |
| 9490 |
/// This function does not require a network capability handle. This is considered to be safe because |
| 9491 |
/// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind`/`connect` |
| 9492 |
/// is called, the socket is effectively an in-memory configuration object, unable to communicate with the outside world. |
| 9493 |
/// |
| 9494 |
/// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. |
| 9495 |
/// |
| 9496 |
/// # Typical errors |
| 9497 |
/// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) |
| 9498 |
/// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) |
| 9499 |
/// |
| 9500 |
/// # References |
| 9501 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html> |
| 9502 |
/// - <https://man7.org/linux/man-pages/man2/socket.2.html> |
| 9503 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw> |
| 9504 |
/// - <https://man.freebsd.org/cgi/man.cgi?query=socket&sektion=2> |
| 9505 |
#[allow(async_fn_in_trait)] |
| 9506 |
pub fn create_tcp_socket( |
| 9507 |
address_family: IpAddressFamily, |
| 9508 |
) -> Result<TcpSocket, ErrorCode> { |
| 9509 |
unsafe { |
| 9510 |
#[repr(align(4))] |
| 9511 |
struct RetArea([::core::mem::MaybeUninit<u8>; 8]); |
| 9512 |
let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); |
| 9513 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 9514 |
#[cfg(target_arch = "wasm32")] |
| 9515 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 9516 |
unsafe extern "C" { |
| 9517 |
#[link_name = "create-tcp-socket"] |
| 9518 |
fn wit_import1(_: i32, _: *mut u8); |
| 9519 |
} |
| 9520 |
#[cfg(not(target_arch = "wasm32"))] |
| 9521 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 9522 |
unreachable!() |
| 9523 |
} |
| 9524 |
wit_import1(address_family.clone() as i32, ptr0); |
| 9525 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 9526 |
let result5 = match l2 { |
| 9527 |
0 => { |
| 9528 |
let e = { |
| 9529 |
let l3 = *ptr0.add(4).cast::<i32>(); |
| 9530 |
super::super::super::wasi::sockets::tcp::TcpSocket::from_handle( |
| 9531 |
l3 as u32, |
| 9532 |
) |
| 9533 |
}; |
| 9534 |
Ok(e) |
| 9535 |
} |
| 9536 |
1 => { |
| 9537 |
let e = { |
| 9538 |
let l4 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 9539 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 9540 |
l4 as u8, |
| 9541 |
) |
| 9542 |
}; |
| 9543 |
Err(e) |
| 9544 |
} |
| 9545 |
_ => _rt::invalid_enum_discriminant(), |
| 9546 |
}; |
| 9547 |
result5 |
| 9548 |
} |
| 9549 |
} |
| 9550 |
} |
| 9551 |
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] |
| 9552 |
pub mod ip_name_lookup { |
| 9553 |
#[used] |
| 9554 |
#[doc(hidden)] |
| 9555 |
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; |
| 9556 |
use super::super::super::_rt; |
| 9557 |
pub type Pollable = super::super::super::wasi::io::poll::Pollable; |
| 9558 |
pub type Network = super::super::super::wasi::sockets::network::Network; |
| 9559 |
pub type ErrorCode = super::super::super::wasi::sockets::network::ErrorCode; |
| 9560 |
pub type IpAddress = super::super::super::wasi::sockets::network::IpAddress; |
| 9561 |
#[derive(Debug)] |
| 9562 |
#[repr(transparent)] |
| 9563 |
pub struct ResolveAddressStream { |
| 9564 |
handle: _rt::Resource<ResolveAddressStream>, |
| 9565 |
} |
| 9566 |
impl ResolveAddressStream { |
| 9567 |
#[doc(hidden)] |
| 9568 |
pub unsafe fn from_handle(handle: u32) -> Self { |
| 9569 |
Self { |
| 9570 |
handle: unsafe { _rt::Resource::from_handle(handle) }, |
| 9571 |
} |
| 9572 |
} |
| 9573 |
#[doc(hidden)] |
| 9574 |
pub fn take_handle(&self) -> u32 { |
| 9575 |
_rt::Resource::take_handle(&self.handle) |
| 9576 |
} |
| 9577 |
#[doc(hidden)] |
| 9578 |
pub fn handle(&self) -> u32 { |
| 9579 |
_rt::Resource::handle(&self.handle) |
| 9580 |
} |
| 9581 |
} |
| 9582 |
unsafe impl _rt::WasmResource for ResolveAddressStream { |
| 9583 |
#[inline] |
| 9584 |
unsafe fn drop(_handle: u32) { |
| 9585 |
#[cfg(target_arch = "wasm32")] |
| 9586 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 9587 |
unsafe extern "C" { |
| 9588 |
#[link_name = "[resource-drop]resolve-address-stream"] |
| 9589 |
fn drop(_: i32); |
| 9590 |
} |
| 9591 |
#[cfg(not(target_arch = "wasm32"))] |
| 9592 |
unsafe extern "C" fn drop(_: i32) { |
| 9593 |
unreachable!() |
| 9594 |
} |
| 9595 |
unsafe { |
| 9596 |
drop(_handle as i32); |
| 9597 |
} |
| 9598 |
} |
| 9599 |
} |
| 9600 |
#[allow(unused_unsafe, clippy::all)] |
| 9601 |
/// Resolve an internet host name to a list of IP addresses. |
| 9602 |
/// |
| 9603 |
/// Unicode domain names are automatically converted to ASCII using IDNA encoding. |
| 9604 |
/// If the input is an IP address string, the address is parsed and returned |
| 9605 |
/// as-is without making any external requests. |
| 9606 |
/// |
| 9607 |
/// See the wasi-socket proposal README.md for a comparison with getaddrinfo. |
| 9608 |
/// |
| 9609 |
/// This function never blocks. It either immediately fails or immediately |
| 9610 |
/// returns successfully with a `resolve-address-stream` that can be used |
| 9611 |
/// to (asynchronously) fetch the results. |
| 9612 |
/// |
| 9613 |
/// # Typical errors |
| 9614 |
/// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address. |
| 9615 |
/// |
| 9616 |
/// # References: |
| 9617 |
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html> |
| 9618 |
/// - <https://man7.org/linux/man-pages/man3/getaddrinfo.3.html> |
| 9619 |
/// - <https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo> |
| 9620 |
/// - <https://man.freebsd.org/cgi/man.cgi?query=getaddrinfo&sektion=3> |
| 9621 |
#[allow(async_fn_in_trait)] |
| 9622 |
pub fn resolve_addresses( |
| 9623 |
network: &Network, |
| 9624 |
name: &str, |
| 9625 |
) -> Result<ResolveAddressStream, ErrorCode> { |
| 9626 |
unsafe { |
| 9627 |
#[repr(align(4))] |
| 9628 |
struct RetArea([::core::mem::MaybeUninit<u8>; 8]); |
| 9629 |
let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); |
| 9630 |
let vec0 = name; |
| 9631 |
let ptr0 = vec0.as_ptr().cast::<u8>(); |
| 9632 |
let len0 = vec0.len(); |
| 9633 |
let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 9634 |
#[cfg(target_arch = "wasm32")] |
| 9635 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 9636 |
unsafe extern "C" { |
| 9637 |
#[link_name = "resolve-addresses"] |
| 9638 |
fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8); |
| 9639 |
} |
| 9640 |
#[cfg(not(target_arch = "wasm32"))] |
| 9641 |
unsafe extern "C" fn wit_import2( |
| 9642 |
_: i32, |
| 9643 |
_: *mut u8, |
| 9644 |
_: usize, |
| 9645 |
_: *mut u8, |
| 9646 |
) { |
| 9647 |
unreachable!() |
| 9648 |
} |
| 9649 |
wit_import2((network).handle() as i32, ptr0.cast_mut(), len0, ptr1); |
| 9650 |
let l3 = i32::from(*ptr1.add(0).cast::<u8>()); |
| 9651 |
let result6 = match l3 { |
| 9652 |
0 => { |
| 9653 |
let e = { |
| 9654 |
let l4 = *ptr1.add(4).cast::<i32>(); |
| 9655 |
ResolveAddressStream::from_handle(l4 as u32) |
| 9656 |
}; |
| 9657 |
Ok(e) |
| 9658 |
} |
| 9659 |
1 => { |
| 9660 |
let e = { |
| 9661 |
let l5 = i32::from(*ptr1.add(4).cast::<u8>()); |
| 9662 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 9663 |
l5 as u8, |
| 9664 |
) |
| 9665 |
}; |
| 9666 |
Err(e) |
| 9667 |
} |
| 9668 |
_ => _rt::invalid_enum_discriminant(), |
| 9669 |
}; |
| 9670 |
result6 |
| 9671 |
} |
| 9672 |
} |
| 9673 |
impl ResolveAddressStream { |
| 9674 |
#[allow(unused_unsafe, clippy::all)] |
| 9675 |
/// Returns the next address from the resolver. |
| 9676 |
/// |
| 9677 |
/// This function should be called multiple times. On each call, it will |
| 9678 |
/// return the next address in connection order preference. If all |
| 9679 |
/// addresses have been exhausted, this function returns `none`. |
| 9680 |
/// |
| 9681 |
/// This function never returns IPv4-mapped IPv6 addresses. |
| 9682 |
/// |
| 9683 |
/// # Typical errors |
| 9684 |
/// - `name-unresolvable`: Name does not exist or has no suitable associated IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY) |
| 9685 |
/// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN) |
| 9686 |
/// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL) |
| 9687 |
/// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) |
| 9688 |
#[allow(async_fn_in_trait)] |
| 9689 |
pub fn resolve_next_address( |
| 9690 |
&self, |
| 9691 |
) -> Result<Option<IpAddress>, ErrorCode> { |
| 9692 |
unsafe { |
| 9693 |
#[repr(align(2))] |
| 9694 |
struct RetArea([::core::mem::MaybeUninit<u8>; 22]); |
| 9695 |
let mut ret_area = RetArea( |
| 9696 |
[::core::mem::MaybeUninit::uninit(); 22], |
| 9697 |
); |
| 9698 |
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>(); |
| 9699 |
#[cfg(target_arch = "wasm32")] |
| 9700 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 9701 |
unsafe extern "C" { |
| 9702 |
#[link_name = "[method]resolve-address-stream.resolve-next-address"] |
| 9703 |
fn wit_import1(_: i32, _: *mut u8); |
| 9704 |
} |
| 9705 |
#[cfg(not(target_arch = "wasm32"))] |
| 9706 |
unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { |
| 9707 |
unreachable!() |
| 9708 |
} |
| 9709 |
wit_import1((self).handle() as i32, ptr0); |
| 9710 |
let l2 = i32::from(*ptr0.add(0).cast::<u8>()); |
| 9711 |
let result19 = match l2 { |
| 9712 |
0 => { |
| 9713 |
let e = { |
| 9714 |
let l3 = i32::from(*ptr0.add(2).cast::<u8>()); |
| 9715 |
match l3 { |
| 9716 |
0 => None, |
| 9717 |
1 => { |
| 9718 |
let e = { |
| 9719 |
let l4 = i32::from(*ptr0.add(4).cast::<u8>()); |
| 9720 |
use super::super::super::wasi::sockets::network::IpAddress as V17; |
| 9721 |
let v17 = match l4 { |
| 9722 |
0 => { |
| 9723 |
let e17 = { |
| 9724 |
let l5 = i32::from(*ptr0.add(6).cast::<u8>()); |
| 9725 |
let l6 = i32::from(*ptr0.add(7).cast::<u8>()); |
| 9726 |
let l7 = i32::from(*ptr0.add(8).cast::<u8>()); |
| 9727 |
let l8 = i32::from(*ptr0.add(9).cast::<u8>()); |
| 9728 |
(l5 as u8, l6 as u8, l7 as u8, l8 as u8) |
| 9729 |
}; |
| 9730 |
V17::Ipv4(e17) |
| 9731 |
} |
| 9732 |
n => { |
| 9733 |
debug_assert_eq!(n, 1, "invalid enum discriminant"); |
| 9734 |
let e17 = { |
| 9735 |
let l9 = i32::from(*ptr0.add(6).cast::<u16>()); |
| 9736 |
let l10 = i32::from(*ptr0.add(8).cast::<u16>()); |
| 9737 |
let l11 = i32::from(*ptr0.add(10).cast::<u16>()); |
| 9738 |
let l12 = i32::from(*ptr0.add(12).cast::<u16>()); |
| 9739 |
let l13 = i32::from(*ptr0.add(14).cast::<u16>()); |
| 9740 |
let l14 = i32::from(*ptr0.add(16).cast::<u16>()); |
| 9741 |
let l15 = i32::from(*ptr0.add(18).cast::<u16>()); |
| 9742 |
let l16 = i32::from(*ptr0.add(20).cast::<u16>()); |
| 9743 |
( |
| 9744 |
l9 as u16, |
| 9745 |
l10 as u16, |
| 9746 |
l11 as u16, |
| 9747 |
l12 as u16, |
| 9748 |
l13 as u16, |
| 9749 |
l14 as u16, |
| 9750 |
l15 as u16, |
| 9751 |
l16 as u16, |
| 9752 |
) |
| 9753 |
}; |
| 9754 |
V17::Ipv6(e17) |
| 9755 |
} |
| 9756 |
}; |
| 9757 |
v17 |
| 9758 |
}; |
| 9759 |
Some(e) |
| 9760 |
} |
| 9761 |
_ => _rt::invalid_enum_discriminant(), |
| 9762 |
} |
| 9763 |
}; |
| 9764 |
Ok(e) |
| 9765 |
} |
| 9766 |
1 => { |
| 9767 |
let e = { |
| 9768 |
let l18 = i32::from(*ptr0.add(2).cast::<u8>()); |
| 9769 |
super::super::super::wasi::sockets::network::ErrorCode::_lift( |
| 9770 |
l18 as u8, |
| 9771 |
) |
| 9772 |
}; |
| 9773 |
Err(e) |
| 9774 |
} |
| 9775 |
_ => _rt::invalid_enum_discriminant(), |
| 9776 |
}; |
| 9777 |
result19 |
| 9778 |
} |
| 9779 |
} |
| 9780 |
} |
| 9781 |
impl ResolveAddressStream { |
| 9782 |
#[allow(unused_unsafe, clippy::all)] |
| 9783 |
/// Create a `pollable` which will resolve once the stream is ready for I/O. |
| 9784 |
/// |
| 9785 |
/// Note: this function is here for WASI 0.2 only. |
| 9786 |
/// It's planned to be removed when `future` is natively supported in Preview3. |
| 9787 |
#[allow(async_fn_in_trait)] |
| 9788 |
pub fn subscribe(&self) -> Pollable { |
| 9789 |
unsafe { |
| 9790 |
#[cfg(target_arch = "wasm32")] |
| 9791 |
#[link(wasm_import_module = "wasi:sockets/[email protected]")] |
| 9792 |
unsafe extern "C" { |
| 9793 |
#[link_name = "[method]resolve-address-stream.subscribe"] |
| 9794 |
fn wit_import0(_: i32) -> i32; |
| 9795 |
} |
| 9796 |
#[cfg(not(target_arch = "wasm32"))] |
| 9797 |
unsafe extern "C" fn wit_import0(_: i32) -> i32 { |
| 9798 |
unreachable!() |
| 9799 |
} |
| 9800 |
let ret = wit_import0((self).handle() as i32); |
| 9801 |
super::super::super::wasi::io::poll::Pollable::from_handle( |
| 9802 |
ret as u32, |
| 9803 |
) |
| 9804 |
} |
| 9805 |
} |
| 9806 |
} |
| 9807 |
} |
| 9808 |
} |
| 9809 |
} |
| 9810 |
#[rustfmt::skip] |
| 9811 |
mod _rt { |
| 9812 |
#![allow(dead_code, clippy::all)] |
| 9813 |
pub use alloc_crate::vec::Vec; |
| 9814 |
pub use alloc_crate::string::String; |
| 9815 |
pub unsafe fn string_lift(bytes: Vec<u8>) -> String { |
| 9816 |
if cfg!(debug_assertions) { |
| 9817 |
String::from_utf8(bytes).unwrap() |
| 9818 |
} else { |
| 9819 |
unsafe { String::from_utf8_unchecked(bytes) } |
| 9820 |
} |
| 9821 |
} |
| 9822 |
pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) { |
| 9823 |
if size == 0 { |
| 9824 |
return; |
| 9825 |
} |
| 9826 |
unsafe { |
| 9827 |
let layout = alloc::Layout::from_size_align_unchecked(size, align); |
| 9828 |
alloc::dealloc(ptr, layout); |
| 9829 |
} |
| 9830 |
} |
| 9831 |
pub unsafe fn invalid_enum_discriminant<T>() -> T { |
| 9832 |
if cfg!(debug_assertions) { |
| 9833 |
panic!("invalid enum discriminant") |
| 9834 |
} else { |
| 9835 |
unsafe { core::hint::unreachable_unchecked() } |
| 9836 |
} |
| 9837 |
} |
| 9838 |
use core::fmt; |
| 9839 |
use core::marker; |
| 9840 |
use core::sync::atomic::{AtomicU32, Ordering::Relaxed}; |
| 9841 |
/// A type which represents a component model resource, either imported or |
| 9842 |
/// exported into this component. |
| 9843 |
/// |
| 9844 |
/// This is a low-level wrapper which handles the lifetime of the resource |
| 9845 |
/// (namely this has a destructor). The `T` provided defines the component model |
| 9846 |
/// intrinsics that this wrapper uses. |
| 9847 |
/// |
| 9848 |
/// One of the chief purposes of this type is to provide `Deref` implementations |
| 9849 |
/// to access the underlying data when it is owned. |
| 9850 |
/// |
| 9851 |
/// This type is primarily used in generated code for exported and imported |
| 9852 |
/// resources. |
| 9853 |
#[repr(transparent)] |
| 9854 |
pub struct Resource<T: WasmResource> { |
| 9855 |
handle: AtomicU32, |
| 9856 |
_marker: marker::PhantomData<T>, |
| 9857 |
} |
| 9858 |
/// A trait which all wasm resources implement, namely providing the ability to |
| 9859 |
/// drop a resource. |
| 9860 |
/// |
| 9861 |
/// This generally is implemented by generated code, not user-facing code. |
| 9862 |
#[allow(clippy::missing_safety_doc)] |
| 9863 |
pub unsafe trait WasmResource { |
| 9864 |
/// Invokes the `[resource-drop]...` intrinsic. |
| 9865 |
unsafe fn drop(handle: u32); |
| 9866 |
} |
| 9867 |
impl<T: WasmResource> Resource<T> { |
| 9868 |
#[doc(hidden)] |
| 9869 |
pub unsafe fn from_handle(handle: u32) -> Self { |
| 9870 |
debug_assert!(handle != 0 && handle != u32::MAX); |
| 9871 |
Self { |
| 9872 |
handle: AtomicU32::new(handle), |
| 9873 |
_marker: marker::PhantomData, |
| 9874 |
} |
| 9875 |
} |
| 9876 |
/// Takes ownership of the handle owned by `resource`. |
| 9877 |
/// |
| 9878 |
/// Note that this ideally would be `into_handle` taking `Resource<T>` by |
| 9879 |
/// ownership. The code generator does not enable that in all situations, |
| 9880 |
/// unfortunately, so this is provided instead. |
| 9881 |
/// |
| 9882 |
/// Also note that `take_handle` is in theory only ever called on values |
| 9883 |
/// owned by a generated function. For example a generated function might |
| 9884 |
/// take `Resource<T>` as an argument but then call `take_handle` on a |
| 9885 |
/// reference to that argument. In that sense the dynamic nature of |
| 9886 |
/// `take_handle` should only be exposed internally to generated code, not |
| 9887 |
/// to user code. |
| 9888 |
#[doc(hidden)] |
| 9889 |
pub fn take_handle(resource: &Resource<T>) -> u32 { |
| 9890 |
resource.handle.swap(u32::MAX, Relaxed) |
| 9891 |
} |
| 9892 |
#[doc(hidden)] |
| 9893 |
pub fn handle(resource: &Resource<T>) -> u32 { |
| 9894 |
resource.handle.load(Relaxed) |
| 9895 |
} |
| 9896 |
} |
| 9897 |
impl<T: WasmResource> fmt::Debug for Resource<T> { |
| 9898 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 9899 |
f.debug_struct("Resource").field("handle", &self.handle).finish() |
| 9900 |
} |
| 9901 |
} |
| 9902 |
impl<T: WasmResource> Drop for Resource<T> { |
| 9903 |
fn drop(&mut self) { |
| 9904 |
unsafe { |
| 9905 |
match self.handle.load(Relaxed) { |
| 9906 |
u32::MAX => {} |
| 9907 |
other => T::drop(other), |
| 9908 |
} |
| 9909 |
} |
| 9910 |
} |
| 9911 |
} |
| 9912 |
pub unsafe fn bool_lift(val: u8) -> bool { |
| 9913 |
if cfg!(debug_assertions) { |
| 9914 |
match val { |
| 9915 |
0 => false, |
| 9916 |
1 => true, |
| 9917 |
_ => panic!("invalid bool discriminant"), |
| 9918 |
} |
| 9919 |
} else { |
| 9920 |
val != 0 |
| 9921 |
} |
| 9922 |
} |
| 9923 |
pub use alloc_crate::alloc; |
| 9924 |
pub fn as_i64<T: AsI64>(t: T) -> i64 { |
| 9925 |
t.as_i64() |
| 9926 |
} |
| 9927 |
pub trait AsI64 { |
| 9928 |
fn as_i64(self) -> i64; |
| 9929 |
} |
| 9930 |
impl<'a, T: Copy + AsI64> AsI64 for &'a T { |
| 9931 |
fn as_i64(self) -> i64 { |
| 9932 |
(*self).as_i64() |
| 9933 |
} |
| 9934 |
} |
| 9935 |
impl AsI64 for i64 { |
| 9936 |
#[inline] |
| 9937 |
fn as_i64(self) -> i64 { |
| 9938 |
self as i64 |
| 9939 |
} |
| 9940 |
} |
| 9941 |
impl AsI64 for u64 { |
| 9942 |
#[inline] |
| 9943 |
fn as_i64(self) -> i64 { |
| 9944 |
self as i64 |
| 9945 |
} |
| 9946 |
} |
| 9947 |
pub fn as_i32<T: AsI32>(t: T) -> i32 { |
| 9948 |
t.as_i32() |
| 9949 |
} |
| 9950 |
pub trait AsI32 { |
| 9951 |
fn as_i32(self) -> i32; |
| 9952 |
} |
| 9953 |
impl<'a, T: Copy + AsI32> AsI32 for &'a T { |
| 9954 |
fn as_i32(self) -> i32 { |
| 9955 |
(*self).as_i32() |
| 9956 |
} |
| 9957 |
} |
| 9958 |
impl AsI32 for i32 { |
| 9959 |
#[inline] |
| 9960 |
fn as_i32(self) -> i32 { |
| 9961 |
self as i32 |
| 9962 |
} |
| 9963 |
} |
| 9964 |
impl AsI32 for u32 { |
| 9965 |
#[inline] |
| 9966 |
fn as_i32(self) -> i32 { |
| 9967 |
self as i32 |
| 9968 |
} |
| 9969 |
} |
| 9970 |
impl AsI32 for i16 { |
| 9971 |
#[inline] |
| 9972 |
fn as_i32(self) -> i32 { |
| 9973 |
self as i32 |
| 9974 |
} |
| 9975 |
} |
| 9976 |
impl AsI32 for u16 { |
| 9977 |
#[inline] |
| 9978 |
fn as_i32(self) -> i32 { |
| 9979 |
self as i32 |
| 9980 |
} |
| 9981 |
} |
| 9982 |
impl AsI32 for i8 { |
| 9983 |
#[inline] |
| 9984 |
fn as_i32(self) -> i32 { |
| 9985 |
self as i32 |
| 9986 |
} |
| 9987 |
} |
| 9988 |
impl AsI32 for u8 { |
| 9989 |
#[inline] |
| 9990 |
fn as_i32(self) -> i32 { |
| 9991 |
self as i32 |
| 9992 |
} |
| 9993 |
} |
| 9994 |
impl AsI32 for char { |
| 9995 |
#[inline] |
| 9996 |
fn as_i32(self) -> i32 { |
| 9997 |
self as i32 |
| 9998 |
} |
| 9999 |
} |
| 10000 |
impl AsI32 for usize { |
| 10001 |
#[inline] |
| 10002 |
fn as_i32(self) -> i32 { |
| 10003 |
self as i32 |
| 10004 |
} |
| 10005 |
} |
| 10006 |
extern crate alloc as alloc_crate; |
| 10007 |
} |
| 10008 |
#[rustfmt::skip] |
| 10009 |
#[cfg(target_arch = "wasm32")] |
| 10010 |
|
| 10011 |
#[cfg_attr(feature = "rustc-dep-of-std", unsafe(link_section = "component-type:wit-bindgen:0.46.0:wasi:[email protected]:imports:encoded worldrust-wasip2-1.0.1+wasi-0.2.4-from-crates-io-in-libstd"))] |
| 10012 |
#[cfg_attr(not(feature = "rustc-dep-of-std"), unsafe(link_section = "component-type:wit-bindgen:0.46.0:wasi:[email protected]:imports:encoded worldrust-wasip2-1.0.1+wasi-0.2.4-from-crates-io"))] |
| 10013 |
|
| 10014 |
#[doc(hidden)] |
| 10015 |
#[allow(clippy::octal_escapes)] |
| 10016 |
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 10730] = *b"\ |
| 10017 |
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xecR\x01A\x02\x01AG\x01\ |
| 10018 |
B\x0a\x01o\x02ss\x01p\0\x01@\0\0\x01\x04\0\x0fget-environment\x01\x02\x01ps\x01@\ |
| 10019 |
\0\0\x03\x04\0\x0dget-arguments\x01\x04\x01ks\x01@\0\0\x05\x04\0\x0binitial-cwd\x01\ |
| 10020 |
\x06\x03\0\x1awasi:cli/[email protected]\x05\0\x01B\x03\x01j\0\0\x01@\x01\x06sta\ |
| 10021 |
tus\0\x01\0\x04\0\x04exit\x01\x01\x03\0\x13wasi:cli/[email protected]\x05\x01\x01B\x04\x04\ |
| 10022 |
\0\x05error\x03\x01\x01h\0\x01@\x01\x04self\x01\0s\x04\0\x1d[method]error.to-deb\ |
| 10023 |
ug-string\x01\x02\x03\0\x13wasi:io/[email protected]\x05\x02\x01B\x0a\x04\0\x08pollabl\ |
| 10024 |
e\x03\x01\x01h\0\x01@\x01\x04self\x01\0\x7f\x04\0\x16[method]pollable.ready\x01\x02\ |
| 10025 |
\x01@\x01\x04self\x01\x01\0\x04\0\x16[method]pollable.block\x01\x03\x01p\x01\x01\ |
| 10026 |
py\x01@\x01\x02in\x04\0\x05\x04\0\x04poll\x01\x06\x03\0\x12wasi:io/[email protected]\x05\ |
| 10027 |
\x03\x02\x03\0\x02\x05error\x02\x03\0\x03\x08pollable\x01B(\x02\x03\x02\x01\x04\x04\ |
| 10028 |
\0\x05error\x03\0\0\x02\x03\x02\x01\x05\x04\0\x08pollable\x03\0\x02\x01i\x01\x01\ |
| 10029 |
q\x02\x15last-operation-failed\x01\x04\0\x06closed\0\0\x04\0\x0cstream-error\x03\ |
| 10030 |
\0\x05\x04\0\x0cinput-stream\x03\x01\x04\0\x0doutput-stream\x03\x01\x01h\x07\x01\ |
| 10031 |
p}\x01j\x01\x0a\x01\x06\x01@\x02\x04self\x09\x03lenw\0\x0b\x04\0\x19[method]inpu\ |
| 10032 |
t-stream.read\x01\x0c\x04\0\"[method]input-stream.blocking-read\x01\x0c\x01j\x01\ |
| 10033 |
w\x01\x06\x01@\x02\x04self\x09\x03lenw\0\x0d\x04\0\x19[method]input-stream.skip\x01\ |
| 10034 |
\x0e\x04\0\"[method]input-stream.blocking-skip\x01\x0e\x01i\x03\x01@\x01\x04self\ |
| 10035 |
\x09\0\x0f\x04\0\x1e[method]input-stream.subscribe\x01\x10\x01h\x08\x01@\x01\x04\ |
| 10036 |
self\x11\0\x0d\x04\0![method]output-stream.check-write\x01\x12\x01j\0\x01\x06\x01\ |
| 10037 |
@\x02\x04self\x11\x08contents\x0a\0\x13\x04\0\x1b[method]output-stream.write\x01\ |
| 10038 |
\x14\x04\0.[method]output-stream.blocking-write-and-flush\x01\x14\x01@\x01\x04se\ |
| 10039 |
lf\x11\0\x13\x04\0\x1b[method]output-stream.flush\x01\x15\x04\0$[method]output-s\ |
| 10040 |
tream.blocking-flush\x01\x15\x01@\x01\x04self\x11\0\x0f\x04\0\x1f[method]output-\ |
| 10041 |
stream.subscribe\x01\x16\x01@\x02\x04self\x11\x03lenw\0\x13\x04\0\"[method]outpu\ |
| 10042 |
t-stream.write-zeroes\x01\x17\x04\05[method]output-stream.blocking-write-zeroes-\ |
| 10043 |
and-flush\x01\x17\x01@\x03\x04self\x11\x03src\x09\x03lenw\0\x0d\x04\0\x1c[method\ |
| 10044 |
]output-stream.splice\x01\x18\x04\0%[method]output-stream.blocking-splice\x01\x18\ |
| 10045 |
\x03\0\x15wasi:io/[email protected]\x05\x06\x02\x03\0\x04\x0cinput-stream\x01B\x05\x02\ |
| 10046 |
\x03\x02\x01\x07\x04\0\x0cinput-stream\x03\0\0\x01i\x01\x01@\0\0\x02\x04\0\x09ge\ |
| 10047 |
t-stdin\x01\x03\x03\0\x14wasi:cli/[email protected]\x05\x08\x02\x03\0\x04\x0doutput-st\ |
| 10048 |
ream\x01B\x05\x02\x03\x02\x01\x09\x04\0\x0doutput-stream\x03\0\0\x01i\x01\x01@\0\ |
| 10049 |
\0\x02\x04\0\x0aget-stdout\x01\x03\x03\0\x15wasi:cli/[email protected]\x05\x0a\x01B\x05\ |
| 10050 |
\x02\x03\x02\x01\x09\x04\0\x0doutput-stream\x03\0\0\x01i\x01\x01@\0\0\x02\x04\0\x0a\ |
| 10051 |
get-stderr\x01\x03\x03\0\x15wasi:cli/[email protected]\x05\x0b\x01B\x01\x04\0\x0eterm\ |
| 10052 |
inal-input\x03\x01\x03\0\x1dwasi:cli/[email protected]\x05\x0c\x01B\x01\x04\0\ |
| 10053 |
\x0fterminal-output\x03\x01\x03\0\x1ewasi:cli/[email protected]\x05\x0d\x02\x03\ |
| 10054 |
\0\x08\x0eterminal-input\x01B\x06\x02\x03\x02\x01\x0e\x04\0\x0eterminal-input\x03\ |
| 10055 |
\0\0\x01i\x01\x01k\x02\x01@\0\0\x03\x04\0\x12get-terminal-stdin\x01\x04\x03\0\x1d\ |
| 10056 |
wasi:cli/[email protected]\x05\x0f\x02\x03\0\x09\x0fterminal-output\x01B\x06\x02\ |
| 10057 |
\x03\x02\x01\x10\x04\0\x0fterminal-output\x03\0\0\x01i\x01\x01k\x02\x01@\0\0\x03\ |
| 10058 |
\x04\0\x13get-terminal-stdout\x01\x04\x03\0\x1ewasi:cli/[email protected]\x05\ |
| 10059 |
\x11\x01B\x06\x02\x03\x02\x01\x10\x04\0\x0fterminal-output\x03\0\0\x01i\x01\x01k\ |
| 10060 |
\x02\x01@\0\0\x03\x04\0\x13get-terminal-stderr\x01\x04\x03\0\x1ewasi:cli/termina\ |
| 10061 |
[email protected]\x05\x12\x01B\x0f\x02\x03\x02\x01\x05\x04\0\x08pollable\x03\0\0\x01\ |
| 10062 |
w\x04\0\x07instant\x03\0\x02\x01w\x04\0\x08duration\x03\0\x04\x01@\0\0\x03\x04\0\ |
| 10063 |
\x03now\x01\x06\x01@\0\0\x05\x04\0\x0aresolution\x01\x07\x01i\x01\x01@\x01\x04wh\ |
| 10064 |
en\x03\0\x08\x04\0\x11subscribe-instant\x01\x09\x01@\x01\x04when\x05\0\x08\x04\0\ |
| 10065 |
\x12subscribe-duration\x01\x0a\x03\0!wasi:clocks/[email protected]\x05\x13\x01\ |
| 10066 |
B\x05\x01r\x02\x07secondsw\x0bnanosecondsy\x04\0\x08datetime\x03\0\0\x01@\0\0\x01\ |
| 10067 |
\x04\0\x03now\x01\x02\x04\0\x0aresolution\x01\x02\x03\0\x1cwasi:clocks/wall-cloc\ |
| 10068 |
[email protected]\x05\x14\x02\x03\0\x04\x05error\x02\x03\0\x0e\x08datetime\x01Br\x02\x03\x02\ |
| 10069 |
\x01\x07\x04\0\x0cinput-stream\x03\0\0\x02\x03\x02\x01\x09\x04\0\x0doutput-strea\ |
| 10070 |
m\x03\0\x02\x02\x03\x02\x01\x15\x04\0\x05error\x03\0\x04\x02\x03\x02\x01\x16\x04\ |
| 10071 |
\0\x08datetime\x03\0\x06\x01w\x04\0\x08filesize\x03\0\x08\x01m\x08\x07unknown\x0c\ |
| 10072 |
block-device\x10character-device\x09directory\x04fifo\x0dsymbolic-link\x0cregula\ |
| 10073 |
r-file\x06socket\x04\0\x0fdescriptor-type\x03\0\x0a\x01n\x06\x04read\x05write\x13\ |
| 10074 |
file-integrity-sync\x13data-integrity-sync\x14requested-write-sync\x10mutate-dir\ |
| 10075 |
ectory\x04\0\x10descriptor-flags\x03\0\x0c\x01n\x01\x0esymlink-follow\x04\0\x0ap\ |
| 10076 |
ath-flags\x03\0\x0e\x01n\x04\x06create\x09directory\x09exclusive\x08truncate\x04\ |
| 10077 |
\0\x0aopen-flags\x03\0\x10\x01w\x04\0\x0alink-count\x03\0\x12\x01k\x07\x01r\x06\x04\ |
| 10078 |
type\x0b\x0alink-count\x13\x04size\x09\x15data-access-timestamp\x14\x1bdata-modi\ |
| 10079 |
fication-timestamp\x14\x17status-change-timestamp\x14\x04\0\x0fdescriptor-stat\x03\ |
| 10080 |
\0\x15\x01q\x03\x09no-change\0\0\x03now\0\0\x09timestamp\x01\x07\0\x04\0\x0dnew-\ |
| 10081 |
timestamp\x03\0\x17\x01r\x02\x04type\x0b\x04names\x04\0\x0fdirectory-entry\x03\0\ |
| 10082 |
\x19\x01m%\x06access\x0bwould-block\x07already\x0ebad-descriptor\x04busy\x08dead\ |
| 10083 |
lock\x05quota\x05exist\x0efile-too-large\x15illegal-byte-sequence\x0bin-progress\ |
| 10084 |
\x0binterrupted\x07invalid\x02io\x0cis-directory\x04loop\x0etoo-many-links\x0cme\ |
| 10085 |
ssage-size\x0dname-too-long\x09no-device\x08no-entry\x07no-lock\x13insufficient-\ |
| 10086 |
memory\x12insufficient-space\x0dnot-directory\x09not-empty\x0fnot-recoverable\x0b\ |
| 10087 |
unsupported\x06no-tty\x0eno-such-device\x08overflow\x0dnot-permitted\x04pipe\x09\ |
| 10088 |
read-only\x0cinvalid-seek\x0etext-file-busy\x0ccross-device\x04\0\x0aerror-code\x03\ |
| 10089 |
\0\x1b\x01m\x06\x06normal\x0asequential\x06random\x09will-need\x09dont-need\x08n\ |
| 10090 |
o-reuse\x04\0\x06advice\x03\0\x1d\x01r\x02\x05lowerw\x05upperw\x04\0\x13metadata\ |
| 10091 |
-hash-value\x03\0\x1f\x04\0\x0adescriptor\x03\x01\x04\0\x16directory-entry-strea\ |
| 10092 |
m\x03\x01\x01h!\x01i\x01\x01j\x01$\x01\x1c\x01@\x02\x04self#\x06offset\x09\0%\x04\ |
| 10093 |
\0\"[method]descriptor.read-via-stream\x01&\x01i\x03\x01j\x01'\x01\x1c\x01@\x02\x04\ |
| 10094 |
self#\x06offset\x09\0(\x04\0#[method]descriptor.write-via-stream\x01)\x01@\x01\x04\ |
| 10095 |
self#\0(\x04\0$[method]descriptor.append-via-stream\x01*\x01j\0\x01\x1c\x01@\x04\ |
| 10096 |
\x04self#\x06offset\x09\x06length\x09\x06advice\x1e\0+\x04\0\x19[method]descript\ |
| 10097 |
or.advise\x01,\x01@\x01\x04self#\0+\x04\0\x1c[method]descriptor.sync-data\x01-\x01\ |
| 10098 |
j\x01\x0d\x01\x1c\x01@\x01\x04self#\0.\x04\0\x1c[method]descriptor.get-flags\x01\ |
| 10099 |
/\x01j\x01\x0b\x01\x1c\x01@\x01\x04self#\00\x04\0\x1b[method]descriptor.get-type\ |
| 10100 |
\x011\x01@\x02\x04self#\x04size\x09\0+\x04\0\x1b[method]descriptor.set-size\x012\ |
| 10101 |
\x01@\x03\x04self#\x15data-access-timestamp\x18\x1bdata-modification-timestamp\x18\ |
| 10102 |
\0+\x04\0\x1c[method]descriptor.set-times\x013\x01p}\x01o\x024\x7f\x01j\x015\x01\ |
| 10103 |
\x1c\x01@\x03\x04self#\x06length\x09\x06offset\x09\06\x04\0\x17[method]descripto\ |
| 10104 |
r.read\x017\x01j\x01\x09\x01\x1c\x01@\x03\x04self#\x06buffer4\x06offset\x09\08\x04\ |
| 10105 |
\0\x18[method]descriptor.write\x019\x01i\"\x01j\x01:\x01\x1c\x01@\x01\x04self#\0\ |
| 10106 |
;\x04\0![method]descriptor.read-directory\x01<\x04\0\x17[method]descriptor.sync\x01\ |
| 10107 |
-\x01@\x02\x04self#\x04paths\0+\x04\0&[method]descriptor.create-directory-at\x01\ |
| 10108 |
=\x01j\x01\x16\x01\x1c\x01@\x01\x04self#\0>\x04\0\x17[method]descriptor.stat\x01\ |
| 10109 |
?\x01@\x03\x04self#\x0apath-flags\x0f\x04paths\0>\x04\0\x1a[method]descriptor.st\ |
| 10110 |
at-at\x01@\x01@\x05\x04self#\x0apath-flags\x0f\x04paths\x15data-access-timestamp\ |
| 10111 |
\x18\x1bdata-modification-timestamp\x18\0+\x04\0\x1f[method]descriptor.set-times\ |
| 10112 |
-at\x01A\x01@\x05\x04self#\x0eold-path-flags\x0f\x08old-paths\x0enew-descriptor#\ |
| 10113 |
\x08new-paths\0+\x04\0\x1a[method]descriptor.link-at\x01B\x01i!\x01j\x01\xc3\0\x01\ |
| 10114 |
\x1c\x01@\x05\x04self#\x0apath-flags\x0f\x04paths\x0aopen-flags\x11\x05flags\x0d\ |
| 10115 |
\0\xc4\0\x04\0\x1a[method]descriptor.open-at\x01E\x01j\x01s\x01\x1c\x01@\x02\x04\ |
| 10116 |
self#\x04paths\0\xc6\0\x04\0\x1e[method]descriptor.readlink-at\x01G\x04\0&[metho\ |
| 10117 |
d]descriptor.remove-directory-at\x01=\x01@\x04\x04self#\x08old-paths\x0enew-desc\ |
| 10118 |
riptor#\x08new-paths\0+\x04\0\x1c[method]descriptor.rename-at\x01H\x01@\x03\x04s\ |
| 10119 |
elf#\x08old-paths\x08new-paths\0+\x04\0\x1d[method]descriptor.symlink-at\x01I\x04\ |
| 10120 |
\0![method]descriptor.unlink-file-at\x01=\x01@\x02\x04self#\x05other#\0\x7f\x04\0\ |
| 10121 |
![method]descriptor.is-same-object\x01J\x01j\x01\x20\x01\x1c\x01@\x01\x04self#\0\ |
| 10122 |
\xcb\0\x04\0\x20[method]descriptor.metadata-hash\x01L\x01@\x03\x04self#\x0apath-\ |
| 10123 |
flags\x0f\x04paths\0\xcb\0\x04\0#[method]descriptor.metadata-hash-at\x01M\x01h\"\ |
| 10124 |
\x01k\x1a\x01j\x01\xcf\0\x01\x1c\x01@\x01\x04self\xce\0\0\xd0\0\x04\03[method]di\ |
| 10125 |
rectory-entry-stream.read-directory-entry\x01Q\x01h\x05\x01k\x1c\x01@\x01\x03err\ |
| 10126 |
\xd2\0\0\xd3\0\x04\0\x15filesystem-error-code\x01T\x03\0\x1bwasi:filesystem/type\ |
| 10127 |
[email protected]\x05\x17\x02\x03\0\x0f\x0adescriptor\x01B\x07\x02\x03\x02\x01\x18\x04\0\x0a\ |
| 10128 |
descriptor\x03\0\0\x01i\x01\x01o\x02\x02s\x01p\x03\x01@\0\0\x04\x04\0\x0fget-dir\ |
| 10129 |
ectories\x01\x05\x03\0\x1ewasi:filesystem/[email protected]\x05\x19\x01B\x11\x04\0\x07\ |
| 10130 |
network\x03\x01\x01m\x15\x07unknown\x0daccess-denied\x0dnot-supported\x10invalid\ |
| 10131 |
-argument\x0dout-of-memory\x07timeout\x14concurrency-conflict\x0fnot-in-progress\ |
| 10132 |
\x0bwould-block\x0dinvalid-state\x10new-socket-limit\x14address-not-bindable\x0e\ |
| 10133 |
address-in-use\x12remote-unreachable\x12connection-refused\x10connection-reset\x12\ |
| 10134 |
connection-aborted\x12datagram-too-large\x11name-unresolvable\x1atemporary-resol\ |
| 10135 |
ver-failure\x1apermanent-resolver-failure\x04\0\x0aerror-code\x03\0\x01\x01m\x02\ |
| 10136 |
\x04ipv4\x04ipv6\x04\0\x11ip-address-family\x03\0\x03\x01o\x04}}}}\x04\0\x0cipv4\ |
| 10137 |
-address\x03\0\x05\x01o\x08{{{{{{{{\x04\0\x0cipv6-address\x03\0\x07\x01q\x02\x04\ |
| 10138 |
ipv4\x01\x06\0\x04ipv6\x01\x08\0\x04\0\x0aip-address\x03\0\x09\x01r\x02\x04port{\ |
| 10139 |
\x07address\x06\x04\0\x13ipv4-socket-address\x03\0\x0b\x01r\x04\x04port{\x09flow\ |
| 10140 |
-infoy\x07address\x08\x08scope-idy\x04\0\x13ipv6-socket-address\x03\0\x0d\x01q\x02\ |
| 10141 |
\x04ipv4\x01\x0c\0\x04ipv6\x01\x0e\0\x04\0\x11ip-socket-address\x03\0\x0f\x03\0\x1a\ |
| 10142 |
wasi:sockets/[email protected]\x05\x1a\x02\x03\0\x11\x07network\x01B\x05\x02\x03\x02\ |
| 10143 |
\x01\x1b\x04\0\x07network\x03\0\0\x01i\x01\x01@\0\0\x02\x04\0\x10instance-networ\ |
| 10144 |
k\x01\x03\x03\0#wasi:sockets/[email protected]\x05\x1c\x02\x03\0\x11\x0aerr\ |
| 10145 |
or-code\x02\x03\0\x11\x11ip-socket-address\x02\x03\0\x11\x11ip-address-family\x01\ |
| 10146 |
BD\x02\x03\x02\x01\x05\x04\0\x08pollable\x03\0\0\x02\x03\x02\x01\x1b\x04\0\x07ne\ |
| 10147 |
twork\x03\0\x02\x02\x03\x02\x01\x1d\x04\0\x0aerror-code\x03\0\x04\x02\x03\x02\x01\ |
| 10148 |
\x1e\x04\0\x11ip-socket-address\x03\0\x06\x02\x03\x02\x01\x1f\x04\0\x11ip-addres\ |
| 10149 |
s-family\x03\0\x08\x01p}\x01r\x02\x04data\x0a\x0eremote-address\x07\x04\0\x11inc\ |
| 10150 |
oming-datagram\x03\0\x0b\x01k\x07\x01r\x02\x04data\x0a\x0eremote-address\x0d\x04\ |
| 10151 |
\0\x11outgoing-datagram\x03\0\x0e\x04\0\x0audp-socket\x03\x01\x04\0\x18incoming-\ |
| 10152 |
datagram-stream\x03\x01\x04\0\x18outgoing-datagram-stream\x03\x01\x01h\x10\x01h\x03\ |
| 10153 |
\x01j\0\x01\x05\x01@\x03\x04self\x13\x07network\x14\x0dlocal-address\x07\0\x15\x04\ |
| 10154 |
\0\x1d[method]udp-socket.start-bind\x01\x16\x01@\x01\x04self\x13\0\x15\x04\0\x1e\ |
| 10155 |
[method]udp-socket.finish-bind\x01\x17\x01i\x11\x01i\x12\x01o\x02\x18\x19\x01j\x01\ |
| 10156 |
\x1a\x01\x05\x01@\x02\x04self\x13\x0eremote-address\x0d\0\x1b\x04\0\x19[method]u\ |
| 10157 |
dp-socket.stream\x01\x1c\x01j\x01\x07\x01\x05\x01@\x01\x04self\x13\0\x1d\x04\0\x20\ |
| 10158 |
[method]udp-socket.local-address\x01\x1e\x04\0![method]udp-socket.remote-address\ |
| 10159 |
\x01\x1e\x01@\x01\x04self\x13\0\x09\x04\0![method]udp-socket.address-family\x01\x1f\ |
| 10160 |
\x01j\x01}\x01\x05\x01@\x01\x04self\x13\0\x20\x04\0$[method]udp-socket.unicast-h\ |
| 10161 |
op-limit\x01!\x01@\x02\x04self\x13\x05value}\0\x15\x04\0([method]udp-socket.set-\ |
| 10162 |
unicast-hop-limit\x01\"\x01j\x01w\x01\x05\x01@\x01\x04self\x13\0#\x04\0&[method]\ |
| 10163 |
udp-socket.receive-buffer-size\x01$\x01@\x02\x04self\x13\x05valuew\0\x15\x04\0*[\ |
| 10164 |
method]udp-socket.set-receive-buffer-size\x01%\x04\0#[method]udp-socket.send-buf\ |
| 10165 |
fer-size\x01$\x04\0'[method]udp-socket.set-send-buffer-size\x01%\x01i\x01\x01@\x01\ |
| 10166 |
\x04self\x13\0&\x04\0\x1c[method]udp-socket.subscribe\x01'\x01h\x11\x01p\x0c\x01\ |
| 10167 |
j\x01)\x01\x05\x01@\x02\x04self(\x0bmax-resultsw\0*\x04\0([method]incoming-datag\ |
| 10168 |
ram-stream.receive\x01+\x01@\x01\x04self(\0&\x04\0*[method]incoming-datagram-str\ |
| 10169 |
eam.subscribe\x01,\x01h\x12\x01@\x01\x04self-\0#\x04\0+[method]outgoing-datagram\ |
| 10170 |
-stream.check-send\x01.\x01p\x0f\x01@\x02\x04self-\x09datagrams/\0#\x04\0%[metho\ |
| 10171 |
d]outgoing-datagram-stream.send\x010\x01@\x01\x04self-\0&\x04\0*[method]outgoing\ |
| 10172 |
-datagram-stream.subscribe\x011\x03\0\x16wasi:sockets/[email protected]\x05\x20\x02\x03\0\ |
| 10173 |
\x13\x0audp-socket\x01B\x0c\x02\x03\x02\x01\x1b\x04\0\x07network\x03\0\0\x02\x03\ |
| 10174 |
\x02\x01\x1d\x04\0\x0aerror-code\x03\0\x02\x02\x03\x02\x01\x1f\x04\0\x11ip-addre\ |
| 10175 |
ss-family\x03\0\x04\x02\x03\x02\x01!\x04\0\x0audp-socket\x03\0\x06\x01i\x07\x01j\ |
| 10176 |
\x01\x08\x01\x03\x01@\x01\x0eaddress-family\x05\0\x09\x04\0\x11create-udp-socket\ |
| 10177 |
\x01\x0a\x03\0$wasi:sockets/[email protected]\x05\"\x02\x03\0\x0d\x08durat\ |
| 10178 |
ion\x01BT\x02\x03\x02\x01\x07\x04\0\x0cinput-stream\x03\0\0\x02\x03\x02\x01\x09\x04\ |
| 10179 |
\0\x0doutput-stream\x03\0\x02\x02\x03\x02\x01\x05\x04\0\x08pollable\x03\0\x04\x02\ |
| 10180 |
\x03\x02\x01#\x04\0\x08duration\x03\0\x06\x02\x03\x02\x01\x1b\x04\0\x07network\x03\ |
| 10181 |
\0\x08\x02\x03\x02\x01\x1d\x04\0\x0aerror-code\x03\0\x0a\x02\x03\x02\x01\x1e\x04\ |
| 10182 |
\0\x11ip-socket-address\x03\0\x0c\x02\x03\x02\x01\x1f\x04\0\x11ip-address-family\ |
| 10183 |
\x03\0\x0e\x01m\x03\x07receive\x04send\x04both\x04\0\x0dshutdown-type\x03\0\x10\x04\ |
| 10184 |
\0\x0atcp-socket\x03\x01\x01h\x12\x01h\x09\x01j\0\x01\x0b\x01@\x03\x04self\x13\x07\ |
| 10185 |
network\x14\x0dlocal-address\x0d\0\x15\x04\0\x1d[method]tcp-socket.start-bind\x01\ |
| 10186 |
\x16\x01@\x01\x04self\x13\0\x15\x04\0\x1e[method]tcp-socket.finish-bind\x01\x17\x01\ |
| 10187 |
@\x03\x04self\x13\x07network\x14\x0eremote-address\x0d\0\x15\x04\0\x20[method]tc\ |
| 10188 |
p-socket.start-connect\x01\x18\x01i\x01\x01i\x03\x01o\x02\x19\x1a\x01j\x01\x1b\x01\ |
| 10189 |
\x0b\x01@\x01\x04self\x13\0\x1c\x04\0![method]tcp-socket.finish-connect\x01\x1d\x04\ |
| 10190 |
\0\x1f[method]tcp-socket.start-listen\x01\x17\x04\0\x20[method]tcp-socket.finish\ |
| 10191 |
-listen\x01\x17\x01i\x12\x01o\x03\x1e\x19\x1a\x01j\x01\x1f\x01\x0b\x01@\x01\x04s\ |
| 10192 |
elf\x13\0\x20\x04\0\x19[method]tcp-socket.accept\x01!\x01j\x01\x0d\x01\x0b\x01@\x01\ |
| 10193 |
\x04self\x13\0\"\x04\0\x20[method]tcp-socket.local-address\x01#\x04\0![method]tc\ |
| 10194 |
p-socket.remote-address\x01#\x01@\x01\x04self\x13\0\x7f\x04\0\x1f[method]tcp-soc\ |
| 10195 |
ket.is-listening\x01$\x01@\x01\x04self\x13\0\x0f\x04\0![method]tcp-socket.addres\ |
| 10196 |
s-family\x01%\x01@\x02\x04self\x13\x05valuew\0\x15\x04\0*[method]tcp-socket.set-\ |
| 10197 |
listen-backlog-size\x01&\x01j\x01\x7f\x01\x0b\x01@\x01\x04self\x13\0'\x04\0%[met\ |
| 10198 |
hod]tcp-socket.keep-alive-enabled\x01(\x01@\x02\x04self\x13\x05value\x7f\0\x15\x04\ |
| 10199 |
\0)[method]tcp-socket.set-keep-alive-enabled\x01)\x01j\x01\x07\x01\x0b\x01@\x01\x04\ |
| 10200 |
self\x13\0*\x04\0'[method]tcp-socket.keep-alive-idle-time\x01+\x01@\x02\x04self\x13\ |
| 10201 |
\x05value\x07\0\x15\x04\0+[method]tcp-socket.set-keep-alive-idle-time\x01,\x04\0\ |
| 10202 |
&[method]tcp-socket.keep-alive-interval\x01+\x04\0*[method]tcp-socket.set-keep-a\ |
| 10203 |
live-interval\x01,\x01j\x01y\x01\x0b\x01@\x01\x04self\x13\0-\x04\0#[method]tcp-s\ |
| 10204 |
ocket.keep-alive-count\x01.\x01@\x02\x04self\x13\x05valuey\0\x15\x04\0'[method]t\ |
| 10205 |
cp-socket.set-keep-alive-count\x01/\x01j\x01}\x01\x0b\x01@\x01\x04self\x13\00\x04\ |
| 10206 |
\0\x1c[method]tcp-socket.hop-limit\x011\x01@\x02\x04self\x13\x05value}\0\x15\x04\ |
| 10207 |
\0\x20[method]tcp-socket.set-hop-limit\x012\x01j\x01w\x01\x0b\x01@\x01\x04self\x13\ |
| 10208 |
\03\x04\0&[method]tcp-socket.receive-buffer-size\x014\x04\0*[method]tcp-socket.s\ |
| 10209 |
et-receive-buffer-size\x01&\x04\0#[method]tcp-socket.send-buffer-size\x014\x04\0\ |
| 10210 |
'[method]tcp-socket.set-send-buffer-size\x01&\x01i\x05\x01@\x01\x04self\x13\05\x04\ |
| 10211 |
\0\x1c[method]tcp-socket.subscribe\x016\x01@\x02\x04self\x13\x0dshutdown-type\x11\ |
| 10212 |
\0\x15\x04\0\x1b[method]tcp-socket.shutdown\x017\x03\0\x16wasi:sockets/[email protected]\ |
| 10213 |
\x05$\x02\x03\0\x15\x0atcp-socket\x01B\x0c\x02\x03\x02\x01\x1b\x04\0\x07network\x03\ |
| 10214 |
\0\0\x02\x03\x02\x01\x1d\x04\0\x0aerror-code\x03\0\x02\x02\x03\x02\x01\x1f\x04\0\ |
| 10215 |
\x11ip-address-family\x03\0\x04\x02\x03\x02\x01%\x04\0\x0atcp-socket\x03\0\x06\x01\ |
| 10216 |
i\x07\x01j\x01\x08\x01\x03\x01@\x01\x0eaddress-family\x05\0\x09\x04\0\x11create-\ |
| 10217 |
tcp-socket\x01\x0a\x03\0$wasi:sockets/[email protected]\x05&\x02\x03\0\x11\ |
| 10218 |
\x0aip-address\x01B\x16\x02\x03\x02\x01\x05\x04\0\x08pollable\x03\0\0\x02\x03\x02\ |
| 10219 |
\x01\x1b\x04\0\x07network\x03\0\x02\x02\x03\x02\x01\x1d\x04\0\x0aerror-code\x03\0\ |
| 10220 |
\x04\x02\x03\x02\x01'\x04\0\x0aip-address\x03\0\x06\x04\0\x16resolve-address-str\ |
| 10221 |
eam\x03\x01\x01h\x08\x01k\x07\x01j\x01\x0a\x01\x05\x01@\x01\x04self\x09\0\x0b\x04\ |
| 10222 |
\03[method]resolve-address-stream.resolve-next-address\x01\x0c\x01i\x01\x01@\x01\ |
| 10223 |
\x04self\x09\0\x0d\x04\0([method]resolve-address-stream.subscribe\x01\x0e\x01h\x03\ |
| 10224 |
\x01i\x08\x01j\x01\x10\x01\x05\x01@\x02\x07network\x0f\x04names\0\x11\x04\0\x11r\ |
| 10225 |
esolve-addresses\x01\x12\x03\0!wasi:sockets/[email protected]\x05(\x01B\x05\x01\ |
| 10226 |
p}\x01@\x01\x03lenw\0\0\x04\0\x10get-random-bytes\x01\x01\x01@\0\0w\x04\0\x0eget\ |
| 10227 |
-random-u64\x01\x02\x03\0\x18wasi:random/[email protected]\x05)\x01B\x05\x01p}\x01@\x01\ |
| 10228 |
\x03lenw\0\0\x04\0\x19get-insecure-random-bytes\x01\x01\x01@\0\0w\x04\0\x17get-i\ |
| 10229 |
nsecure-random-u64\x01\x02\x03\0\x1awasi:random/[email protected]\x05*\x01B\x03\x01\ |
| 10230 |
o\x02ww\x01@\0\0\0\x04\0\x0dinsecure-seed\x01\x01\x03\0\x1fwasi:random/insecure-\ |
| 10231 |
[email protected]\x05+\x04\0\x16wasi:cli/[email protected]\x04\0\x0b\x0d\x01\0\x07imports\x03\ |
| 10232 |
\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.239.0\x10wit-\ |
| 10233 |
bindgen-rust\x060.46.0"; |
| 10234 |
#[inline(never)] |
| 10235 |
#[doc(hidden)] |
| 10236 |
pub fn __link_custom_section_describing_imports() { |
| 10237 |
wit_bindgen::rt::maybe_link_cabi_realloc(); |
| 10238 |
} |