use self::pool::NonBlockingStream;
pub use super::event::{GenericSource, IONotifier, IOSource};
use async_trait::async_trait;
use bytes::Bytes;
use std::io;
use std::net::Shutdown;
use std::net::SocketAddr;
pub mod pool;
pub mod stream;
#[cfg(not(target_arch = "wasm32"))] mod tcp;
#[cfg(not(target_arch = "wasm32"))] mod udp;
#[cfg(target_arch = "wasm32")] mod web;
#[cfg(not(target_arch = "wasm32"))] mod websocket;
#[cfg(not(target_arch = "wasm32"))]
mod arch {
use super::*;
pub use tcp::Factory as TcpFactory;
pub use udp::Factory as UdpFactory;
pub use websocket::Factory as WSFactory;
}
#[cfg(target_arch = "wasm32")]
mod arch {
use super::*;
pub use web::websocket::Factory as WSFactory;
}
pub use arch::*;
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum Address {
IP(SocketAddr),
WSUrl(String),
PhoneNumber,
}
#[derive(Debug)]
pub enum TransportError {
BothTerminated,
HalfTerminated,
NotReady,
}
#[async_trait]
pub trait Transport: Send {
fn try_send(&mut self, data: Option<Bytes>) -> Result<bool, TransportError>;
fn try_recv(&mut self) -> Result<Bytes, TransportError>;
fn source(&mut self) -> IOSource;
fn shutdown(&mut self, how: Shutdown) -> io::Result<()>;
async fn renew(
self: Box<Self>, closer: super::endpoint::TransportCloser,
) -> (Box<dyn Transport>, Result<Vec<Bytes>, TransportError>);
fn take_stream(self: Box<Self>) -> Result<Box<dyn NonBlockingStream>, TransportError>;
}