1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
//! Implementations of io-lifetimes' traits for socket2's types. In the
//! future, we'll prefer to have crates provide their own impls; this is
//! just a temporary measure.
#[cfg(any(unix, target_os = "wasi"))]
use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd};
#[cfg(windows)]
use crate::{AsSocket, BorrowedSocket, FromSocket, IntoSocket, OwnedSocket};
#[cfg(unix)]
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd};
#[cfg(target_os = "wasi")]
use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd};
#[cfg(windows)]
use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket};
#[cfg(any(unix, target_os = "wasi"))]
impl AsFd for socket2::Socket {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
}
}
#[cfg(windows)]
impl AsSocket for socket2::Socket {
#[inline]
fn as_socket(&self) -> BorrowedSocket<'_> {
unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) }
}
}
#[cfg(any(unix, target_os = "wasi"))]
impl IntoFd for socket2::Socket {
#[inline]
fn into_fd(self) -> OwnedFd {
unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) }
}
}
#[cfg(any(unix, target_os = "wasi"))]
impl From<socket2::Socket> for OwnedFd {
#[inline]
fn from(owned: socket2::Socket) -> Self {
unsafe { OwnedFd::from_raw_fd(owned.into_raw_fd()) }
}
}
#[cfg(windows)]
impl IntoSocket for socket2::Socket {
#[inline]
fn into_socket(self) -> OwnedSocket {
unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) }
}
}
#[cfg(windows)]
impl From<socket2::Socket> for OwnedSocket {
#[inline]
fn from(owned: socket2::Socket) -> Self {
unsafe { Self::from_raw_socket(owned.into_raw_socket()) }
}
}
#[cfg(any(unix, target_os = "wasi"))]
impl FromFd for socket2::Socket {
#[inline]
fn from_fd(owned: OwnedFd) -> Self {
unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
}
}
#[cfg(any(unix, target_os = "wasi"))]
impl From<OwnedFd> for socket2::Socket {
#[inline]
fn from(owned: OwnedFd) -> Self {
unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
}
}
#[cfg(windows)]
impl FromSocket for socket2::Socket {
#[inline]
fn from_socket(owned: OwnedSocket) -> Self {
unsafe { Self::from_raw_socket(owned.into_raw_socket()) }
}
}
#[cfg(windows)]
impl From<OwnedSocket> for socket2::Socket {
#[inline]
fn from(owned: OwnedSocket) -> Self {
unsafe { Self::from_raw_socket(owned.into_raw_socket()) }
}
}
|