bromine/protocol/
mod.rs

1pub mod tcp;
2
3#[cfg(feature = "encryption_layer")]
4pub mod encrypted;
5#[cfg(unix)]
6pub mod unix_socket;
7
8use crate::prelude::IPCResult;
9use async_trait::async_trait;
10use std::fmt::Debug;
11use tokio::io::{AsyncRead, AsyncWrite};
12
13#[async_trait]
14pub trait AsyncStreamProtocolListener: Sized + Send + Sync {
15    type AddressType: Clone + Debug + Send + Sync;
16    type RemoteAddressType: Debug + Send + Sync;
17    type Stream: 'static + AsyncProtocolStream<AddressType = Self::AddressType>;
18    type ListenerOptions: Clone + Default + Send + Sync;
19
20    async fn protocol_bind(
21        address: Self::AddressType,
22        options: Self::ListenerOptions,
23    ) -> IPCResult<Self>;
24
25    async fn protocol_accept(&self) -> IPCResult<(Self::Stream, Self::RemoteAddressType)>;
26}
27
28pub trait AsyncProtocolStreamSplit {
29    type OwnedSplitReadHalf: 'static + AsyncRead + Send + Sync + Unpin;
30    type OwnedSplitWriteHalf: 'static + AsyncWrite + Send + Sync + Unpin;
31
32    fn protocol_into_split(self) -> (Self::OwnedSplitReadHalf, Self::OwnedSplitWriteHalf);
33}
34
35#[async_trait]
36pub trait AsyncProtocolStream:
37    AsyncRead + AsyncWrite + Send + Sync + AsyncProtocolStreamSplit + Sized + Unpin
38{
39    type AddressType: Clone + Debug + Send + Sync;
40    type StreamOptions: Clone + Default + Send + Sync;
41
42    async fn protocol_connect(
43        address: Self::AddressType,
44        options: Self::StreamOptions,
45    ) -> IPCResult<Self>;
46}