mirror of
https://github.com/wez/wezterm.git
synced 2024-08-17 10:10:23 +03:00
fixup naming and impl for socket traits
This commit is contained in:
parent
5ac61ec8d3
commit
5f9bb5c3b0
@ -131,13 +131,13 @@ pub trait FromRawFileDescriptor {
|
||||
}
|
||||
|
||||
pub trait AsRawSocketDescriptor {
|
||||
fn as_raw_socket_descriptor(&self) -> SocketDescriptor;
|
||||
fn as_socket_descriptor(&self) -> SocketDescriptor;
|
||||
}
|
||||
pub trait IntoRawSocketDescriptor {
|
||||
fn into_raw_socket_descriptor(self) -> SocketDescriptor;
|
||||
fn into_socket_descriptor(self) -> SocketDescriptor;
|
||||
}
|
||||
pub trait FromRawSocketDescriptor {
|
||||
unsafe fn from_raw_socket_descriptor(fd: SocketDescriptor) -> Self;
|
||||
unsafe fn from_socket_descriptor(fd: SocketDescriptor) -> Self;
|
||||
}
|
||||
|
||||
/// `OwnedHandle` allows managing the lifetime of the platform `RawFileDescriptor`
|
||||
|
@ -34,19 +34,19 @@ impl<T: FromRawFd> FromRawFileDescriptor for T {
|
||||
}
|
||||
|
||||
impl<T: AsRawFd> AsRawSocketDescriptor for T {
|
||||
fn as_raw_socket_descriptor(&self) -> SocketDescriptor {
|
||||
fn as_socket_descriptor(&self) -> SocketDescriptor {
|
||||
self.as_raw_fd()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IntoRawFd> IntoRawSocketDescriptor for T {
|
||||
fn into_raw_socket_descriptor(self) -> SocketDescriptor {
|
||||
fn into_socket_descriptor(self) -> SocketDescriptor {
|
||||
self.into_raw_fd()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FromRawFd> FromRawSocketDescriptor for T {
|
||||
unsafe fn from_raw_socket_descriptor(fd: SocketDescriptor) -> Self {
|
||||
unsafe fn from_socket_descriptor(fd: SocketDescriptor) -> Self {
|
||||
Self::from_raw_fd(fd)
|
||||
}
|
||||
}
|
||||
|
@ -53,26 +53,26 @@ impl<T: FromRawHandle> FromRawFileDescriptor for T {
|
||||
}
|
||||
|
||||
impl<T: AsRawSocket> AsRawSocketDescriptor for T {
|
||||
fn as_raw_socket_descriptor(&self) -> SocketDescriptor {
|
||||
fn as_socket_descriptor(&self) -> SocketDescriptor {
|
||||
self.as_raw_socket() as SocketDescriptor
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IntoRawSocket> IntoRawSocketDescriptor for T {
|
||||
fn into_raw_socket_descriptor(self) -> SocketDescriptor {
|
||||
fn into_socket_descriptor(self) -> SocketDescriptor {
|
||||
self.into_raw_socket() as SocketDescriptor
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FromRawSocket> FromRawSocketDescriptor for T {
|
||||
unsafe fn from_raw_socket_descriptor(handle: SocketDescriptor) -> Self {
|
||||
unsafe fn from_socket_descriptor(handle: SocketDescriptor) -> Self {
|
||||
Self::from_raw_socket(handle as _)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for OwnedHandle {}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum HandleType {
|
||||
Char,
|
||||
Disk,
|
||||
@ -198,6 +198,36 @@ impl FromRawHandle for FileDescriptor {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoRawSocket for FileDescriptor {
|
||||
fn into_raw_socket(self) -> RawSocket {
|
||||
// FIXME: this isn't a guaranteed conversion!
|
||||
debug_assert_eq!(
|
||||
handle_type(self.handle.as_raw_handle() as _),
|
||||
HandleType::Socket
|
||||
);
|
||||
self.handle.into_raw_handle() as RawSocket
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRawSocket for FileDescriptor {
|
||||
fn as_raw_socket(&self) -> RawSocket {
|
||||
// FIXME: this isn't a guaranteed conversion!
|
||||
debug_assert_eq!(
|
||||
handle_type(self.handle.as_raw_handle() as _),
|
||||
HandleType::Socket
|
||||
);
|
||||
self.handle.as_raw_handle() as RawSocket
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRawSocket for FileDescriptor {
|
||||
unsafe fn from_raw_socket(handle: RawSocket) -> FileDescriptor {
|
||||
Self {
|
||||
handle: OwnedHandle::from_raw_handle(handle as RawHandle),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl io::Read for FileDescriptor {
|
||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> {
|
||||
let mut num_read = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user