mirror of
https://github.com/async-rs/async-std.git
synced 2025-01-16 10:49:55 +00:00
fix windows trait declarations for rawsocket
This commit is contained in:
parent
7a9afbd81c
commit
1a6d4f6a2f
3 changed files with 36 additions and 3 deletions
|
@ -229,7 +229,10 @@ cfg_unix! {
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg_windows! {
|
cfg_windows! {
|
||||||
use crate::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle, AsRawSocket, RawSocket, FromRawSocket};
|
use crate::os::windows::io::{
|
||||||
|
AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle,
|
||||||
|
AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket,
|
||||||
|
};
|
||||||
|
|
||||||
impl AsRawSocket for TcpListener {
|
impl AsRawSocket for TcpListener {
|
||||||
fn as_raw_socket(&self) -> RawSocket {
|
fn as_raw_socket(&self) -> RawSocket {
|
||||||
|
|
|
@ -402,7 +402,7 @@ cfg_windows! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoRawSocket for crate::net::tcp::TcpListener {
|
impl IntoRawSocket for TcpStream {
|
||||||
fn into_raw_socket(self) -> RawSocket {
|
fn into_raw_socket(self) -> RawSocket {
|
||||||
// TODO(stjepang): This does not mean `RawFd` is now the sole owner of the file
|
// TODO(stjepang): This does not mean `RawFd` is now the sole owner of the file
|
||||||
// descriptor because it's possible that there are other clones of this `TcpStream`
|
// descriptor because it's possible that there are other clones of this `TcpStream`
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
cfg_not_docs! {
|
cfg_not_docs! {
|
||||||
pub use std::os::windows::io::{
|
pub use std::os::windows::io::{
|
||||||
AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle, RawSocket,
|
AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle,
|
||||||
|
AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,4 +46,33 @@ cfg_docs! {
|
||||||
/// it once it's no longer needed.
|
/// it once it's no longer needed.
|
||||||
fn into_raw_handle(self) -> RawHandle;
|
fn into_raw_handle(self) -> RawHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates I/O objects from raw sockets.
|
||||||
|
pub trait FromRawSocket {
|
||||||
|
/// Creates a new I/O object from the given raw socket.
|
||||||
|
///
|
||||||
|
/// This function will consume ownership of the socket provided and it will be closed when the returned object goes out of scope.
|
||||||
|
///
|
||||||
|
/// This function is also unsafe as the primitives currently returned have the contract that they are the sole owner of the
|
||||||
|
/// file descriptor they are wrapping. Usage of this function could accidentally allow violating this contract which can cause
|
||||||
|
/// memory unsafety in code that relies on it being true.
|
||||||
|
unsafe fn from_raw_socket(sock: RawSocket) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extracts raw sockets.
|
||||||
|
pub trait AsRawSocket {
|
||||||
|
/// Extracts the underlying raw socket from this object.
|
||||||
|
fn as_raw_socket(&self) -> RawSocket;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A trait to express the ability to consume an object and acquire ownership of
|
||||||
|
/// its raw `SOCKET`.
|
||||||
|
pub trait IntoRawSocket {
|
||||||
|
/// Consumes this object, returning the raw underlying socket.
|
||||||
|
///
|
||||||
|
/// This function **transfers ownership** of the underlying socket to the
|
||||||
|
/// caller. Callers are then the unique owners of the socket and must close
|
||||||
|
/// it once it's no longer needed.
|
||||||
|
fn into_raw_socket(self) -> RawSocket;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue