diff --git a/src/runtime2/stdlib/internet.rs b/src/runtime2/stdlib/internet.rs index 0013332ee7c5c7b50eae94a319637d642214ad80..3071b975015dea74e0ec67b71b91528cab76089b 100644 --- a/src/runtime2/stdlib/internet.rs +++ b/src/runtime2/stdlib/internet.rs @@ -6,6 +6,7 @@ use libc::{ sockaddr_in, sockaddr_in6, in_addr, in6_addr, socket, bind, listen, accept, connect, close, }; +use mio::{event, Interest, Registry, Token}; #[derive(Debug)] pub enum SocketError { @@ -193,7 +194,31 @@ impl Drop for SocketRawRx { } } +// The following is essentially stolen from `mio`'s io_source.rs file. +#[cfg(unix)] +trait AsRawFileDescriptor { + fn as_raw_file_descriptor(&self) -> c_int; +} + +impl AsRawFileDescriptor for SocketTcpClient { + fn as_raw_file_descriptor(&self) -> c_int { + return self.socket_handle; + } +} + +impl event::Source for T { + fn register(&mut self, registry: &Registry, token: Token, interests: Interest) -> std::io::Result<()> { + registry.selector().register() + } + + fn reregister(&mut self, registry: &Registry, token: Token, interests: Interest) -> std::io::Result<()> { + todo!() + } + fn deregister(&mut self, registry: &Registry) -> std::io::Result<()> { + todo!() + } +} /// Performs the `socket` and `bind` calls. fn create_and_bind_socket(socket_type: libc::c_int, protocol: libc::c_int, ip: IpAddr, port: u16) -> Result {