1 // Copyright (c) 2023 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 //! Event-driven non-blocking Tcp/Udp for unix 15 16 macro_rules! syscall { 17 ($fn: ident ( $($arg: expr),* $(,)* ) ) => {{ 18 let res = unsafe { libc::$fn($($arg, )*) }; 19 if res == -1 { 20 Err(std::io::Error::last_os_error()) 21 } else { 22 Ok(res) 23 } 24 }}; 25 } 26 27 cfg_tcp! { 28 mod tcp; 29 pub use self::tcp::{TcpListener, TcpStream}; 30 } 31 32 cfg_udp! { 33 mod udp; 34 pub use self::udp::{UdpSocket, ConnectedUdpSocket}; 35 } 36 37 mod uds; 38 pub use uds::{SocketAddr, UnixDatagram, UnixListener, UnixStream}; 39 40 #[cfg(target_os = "linux")] 41 mod epoll; 42 #[cfg(target_os = "linux")] 43 pub use epoll::{Event, Events, Selector}; 44 45 mod socket_addr; 46 47 #[cfg(target_os = "macos")] 48 mod kqueue; 49 #[cfg(target_os = "macos")] 50 pub use kqueue::{Event, Events, Selector}; 51 52 pub(crate) mod socket; 53 mod waker; 54 55 pub(crate) use waker::WakerInner; 56 57 mod source_fd; 58 pub use source_fd::SourceFd; 59