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 16macro_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 27cfg_tcp! { 28 mod tcp; 29 pub use self::tcp::{TcpListener, TcpStream}; 30} 31 32cfg_udp! { 33 mod udp; 34 pub use self::udp::{UdpSocket, ConnectedUdpSocket}; 35} 36 37mod uds; 38pub use uds::{SocketAddr, UnixDatagram, UnixListener, UnixStream}; 39 40#[cfg(target_os = "linux")] 41mod epoll; 42#[cfg(target_os = "linux")] 43pub use epoll::{Event, Events, Selector}; 44 45mod socket_addr; 46 47#[cfg(target_os = "macos")] 48mod kqueue; 49#[cfg(target_os = "macos")] 50pub use kqueue::{Event, Events, Selector}; 51 52pub(crate) mod socket; 53mod waker; 54 55pub(crate) use waker::WakerInner; 56 57mod source_fd; 58pub use source_fd::SourceFd; 59