This commit is contained in:
nora 2022-04-01 22:50:59 +02:00
parent 398a2dc2d6
commit 19e43ea5a2
2 changed files with 14 additions and 2 deletions

View file

@ -1,2 +1,2 @@
# survey
epoll(7) things for fun and profit
low level linux io

View file

@ -4,7 +4,7 @@ use std::{
io::{Read, Write},
mem,
mem::MaybeUninit,
os::unix,
os::{unix, unix::io::RawFd},
};
const SOCKADDR_IN_SIZE: libc::socklen_t = mem::size_of::<libc::sockaddr_in>() as _;
@ -87,6 +87,12 @@ impl Debug for SyncTcpListener {
}
}
impl unix::io::AsRawFd for SyncTcpListener {
fn as_raw_fd(&self) -> RawFd {
self.fd
}
}
pub struct SyncTcpStream {
fd: unix::io::RawFd,
peer_sockaddr: libc::sockaddr_in,
@ -134,6 +140,12 @@ impl Debug for SyncTcpStream {
}
}
impl unix::io::AsRawFd for SyncTcpStream {
fn as_raw_fd(&self) -> RawFd {
self.fd
}
}
fn format_addr(addr: libc::sockaddr_in) -> String {
let bytes = addr.sin_addr.s_addr.to_be_bytes();
format!(