1 // Copyright 2022 The Chromium OS Authors. All rights reserved. 2 // SPDX-License-Identifier: Apache-2.0 3 4 //! Unix specific code that keeps rest of the code in the crate platform independent. 5 6 use std::io::Result; 7 use std::os::unix::net::{UnixListener, UnixStream}; 8 9 /// Alias to enable platform independent code. 10 pub type SystemListener = UnixListener; 11 12 /// Alias to enable platform independent code. 13 pub type SystemStream = UnixStream; 14 15 cfg_if::cfg_if! { 16 if #[cfg(feature = "device")] { 17 use crate::{connection::socket::Endpoint as SocketEndpoint, message::SlaveReq}; 18 use crate::message::MasterReq; 19 20 pub(crate) type SlaveFsCacheReqSocket = SocketEndpoint<SlaveReq>; 21 pub(crate) type MasterReqEndpoint = SocketEndpoint<MasterReq>; 22 } 23 } 24 25 /// Collection of platform-specific methods that SystemListener provides. 26 pub(crate) trait SystemListenerExt { 27 /// Accept a connection. accept(&self) -> Result<SystemStream>28 fn accept(&self) -> Result<SystemStream>; 29 } 30 31 impl SystemListenerExt for SystemListener { accept(&self) -> Result<SystemStream>32 fn accept(&self) -> Result<SystemStream> { 33 self.accept().map(|(socket, _address)| socket) 34 } 35 } 36