pub struct TCPServer<State: Clone + Send + Sync + 'static = ()> { /* private fields */ }clients or servers) and crate feature servers only.Expand description
An implementation of a TCP server.
This is the “base” TCP Server class that any of the servers that cat-dev will be built on. It has extensions for handling any potential type of server that we will ever need to support.
This server accepts lots of parameters so look at the modules documentation for general info about how processing works.
Implementations§
Source§impl TCPServer<()>
 
impl TCPServer<()>
Sourcepub async fn new<AddrTy, ServiceTy>(
    service_name: &'static str,
    bind_addr: AddrTy,
    initial_service: ServiceTy,
    nagle_hooks: (Option<&'static dyn PreNagleFnTy>, Option<&'static dyn PostNagleFnTy>),
    guard: impl Into<NagleGuard>,
    trace_io_during_debug: bool,
) -> Result<Self, CommonNetAPIError>where
    AddrTy: ToSocketAddrs,
    ServiceTy: Clone + Send + Service<Request<()>, Response = Response, Error = Infallible> + 'static,
    ServiceTy::Future: Send + 'static,
 
pub async fn new<AddrTy, ServiceTy>(
    service_name: &'static str,
    bind_addr: AddrTy,
    initial_service: ServiceTy,
    nagle_hooks: (Option<&'static dyn PreNagleFnTy>, Option<&'static dyn PostNagleFnTy>),
    guard: impl Into<NagleGuard>,
    trace_io_during_debug: bool,
) -> Result<Self, CommonNetAPIError>where
    AddrTy: ToSocketAddrs,
    ServiceTy: Clone + Send + Service<Request<()>, Response = Response, Error = Infallible> + 'static,
    ServiceTy::Future: Send + 'static,
Create a new TCP Server without having to specify any particular state.
§Errors
If we cannot look up one specific address to bind too.
Source§impl<State: Clone + Send + Sync + 'static> TCPServer<State>
 
impl<State: Clone + Send + Sync + 'static> TCPServer<State>
Sourcepub async fn out_of_bound_send(
    server_id: u64,
    stream_id: u64,
    message: ResponseStreamMessage,
) -> Result<(), CatBridgeError>
 
pub async fn out_of_bound_send( server_id: u64, stream_id: u64, message: ResponseStreamMessage, ) -> Result<(), CatBridgeError>
Send a message completely out of band to a particular open stream.
§Errors
- If the stream is not actively open.
- If we could not actively queue a packet to go out.
Sourcepub async fn out_of_bound_broadcast(
    server_id: u64,
    message: ResponseStreamMessage,
) -> Vec<Result<(), CatBridgeError>>
 
pub async fn out_of_bound_broadcast( server_id: u64, message: ResponseStreamMessage, ) -> Vec<Result<(), CatBridgeError>>
Send a message completely out of band to all open stream.
Sourcepub async fn new_with_state<AddrTy, ServiceTy>(
    service_name: &'static str,
    bind_addr: AddrTy,
    initial_service: ServiceTy,
    nagle_hooks: (Option<&'static dyn PreNagleFnTy>, Option<&'static dyn PostNagleFnTy>),
    guard: impl Into<NagleGuard>,
    state: State,
    trace_io_during_debug: bool,
) -> Result<Self, CommonNetAPIError>where
    AddrTy: ToSocketAddrs,
    ServiceTy: Clone + Send + Service<Request<State>, Response = Response, Error = Infallible> + 'static,
    ServiceTy::Future: Send + 'static,
 
pub async fn new_with_state<AddrTy, ServiceTy>(
    service_name: &'static str,
    bind_addr: AddrTy,
    initial_service: ServiceTy,
    nagle_hooks: (Option<&'static dyn PreNagleFnTy>, Option<&'static dyn PostNagleFnTy>),
    guard: impl Into<NagleGuard>,
    state: State,
    trace_io_during_debug: bool,
) -> Result<Self, CommonNetAPIError>where
    AddrTy: ToSocketAddrs,
    ServiceTy: Clone + Send + Service<Request<State>, Response = Response, Error = Infallible> + 'static,
    ServiceTy::Future: Send + 'static,
Create a new TCP Server along with the state for this server.
§Errors
If we cannot look up one specific address to bind too.
Sourcepub const fn set_cat_dev_slowdown(&mut self, slowdown: Option<Duration>)
 
pub const fn set_cat_dev_slowdown(&mut self, slowdown: Option<Duration>)
Set the slowdown to before sending bytes from this server.
pub const fn chunk_output_at_size(&self) -> Option<usize>
pub const fn set_chunk_output_at_size(&mut self, new_size: Option<usize>)
pub const fn slowloris_timeout(&self) -> Duration
pub const fn set_slowloris_timeout(&mut self, slowloris_timeout: Duration)
pub const fn on_stream_begin( &self, ) -> Option<&UnderlyingOnStreamBeginService<State>>
Sourcepub fn set_raw_on_stream_begin(
    &mut self,
    on_start: Option<UnderlyingOnStreamBeginService<State>>,
) -> Result<(), CommonNetAPIError>
 
pub fn set_raw_on_stream_begin( &mut self, on_start: Option<UnderlyingOnStreamBeginService<State>>, ) -> Result<(), CommonNetAPIError>
Set a hook to run when a stream has been created.
This is what happens when a new machine connects. So it may also be
refered to as “on connect”. This assumes you’re assigning a service
that already exists and is in the raw storage type, you may want to
look into Self::set_on_stream_begin, or
Self::set_on_stream_begin_service.
§Errors
If the stream beginning hook has already been registered. If you’re looking to perform multiple actions at once, look into layer-ing.
Sourcepub fn set_on_stream_begin<HandlerTy, HandlerParamsTy>(
    &mut self,
    handler: HandlerTy,
) -> Result<(), CommonNetAPIError>where
    HandlerParamsTy: Send + 'static,
    HandlerTy: OnResponseStreamBeginHandler<HandlerParamsTy, State> + Clone + Send + 'static,
 
pub fn set_on_stream_begin<HandlerTy, HandlerParamsTy>(
    &mut self,
    handler: HandlerTy,
) -> Result<(), CommonNetAPIError>where
    HandlerParamsTy: Send + 'static,
    HandlerTy: OnResponseStreamBeginHandler<HandlerParamsTy, State> + Clone + Send + 'static,
Set a function hook to run when a stream has been created.
This is what happens when a new machine connects. So it may also be
refered to as “on connect”. This assumes you’re assigning a function
to on stream begin otherwise use Self::set_raw_on_stream_begin,
or Self::set_on_stream_begin_service.
§Errors
If the stream beginning hook has already been registered. If you’re looking to perform multiple actions at once, look into layer-ing.
Sourcepub fn set_on_stream_begin_service<ServiceTy>(
    &mut self,
    service_ty: ServiceTy,
) -> Result<(), CommonNetAPIError>where
    ServiceTy: Clone + Send + Service<ResponseStreamEvent<State>, Response = bool, Error = CatBridgeError> + 'static,
    ServiceTy::Future: Send + 'static,
 
pub fn set_on_stream_begin_service<ServiceTy>(
    &mut self,
    service_ty: ServiceTy,
) -> Result<(), CommonNetAPIError>where
    ServiceTy: Clone + Send + Service<ResponseStreamEvent<State>, Response = bool, Error = CatBridgeError> + 'static,
    ServiceTy::Future: Send + 'static,
Set a function hook to run when a stream has been created.
This is what happens when a new machine connects. So it may also be
refered to as “on connect”. This assumes you’re assigning a Service
to on stream begin otherwise use Self::set_raw_on_stream_begin,
or Self::set_on_stream_begin.
§Errors
If the stream beginning hook has already been registered. If you’re looking to perform multiple actions at once, look into layer-ing.
Sourcepub fn layer_on_stream_begin<LayerTy, ServiceTy>(
    &mut self,
    layer: LayerTy,
) -> Result<(), CommonNetAPIError>where
    LayerTy: Layer<UnderlyingOnStreamBeginService<State>, Service = ServiceTy>,
    ServiceTy: Service<ResponseStreamEvent<State>, Response = bool, Error = CatBridgeError> + Clone + Send + 'static,
    <LayerTy::Service as Service<ResponseStreamEvent<State>>>::Future: Send + 'static,
 
pub fn layer_on_stream_begin<LayerTy, ServiceTy>(
    &mut self,
    layer: LayerTy,
) -> Result<(), CommonNetAPIError>where
    LayerTy: Layer<UnderlyingOnStreamBeginService<State>, Service = ServiceTy>,
    ServiceTy: Service<ResponseStreamEvent<State>, Response = bool, Error = CatBridgeError> + Clone + Send + 'static,
    <LayerTy::Service as Service<ResponseStreamEvent<State>>>::Future: Send + 'static,
Add a layer to the service to process when a stream begins, or a new connection is created.
§Errors
If there is no on stream begin handler that is currently active.
pub const fn on_stream_end( &self, ) -> Option<&UnderlyingOnStreamEndService<State>>
Sourcepub fn set_raw_on_stream_end(
    &mut self,
    on_end: Option<UnderlyingOnStreamEndService<State>>,
) -> Result<(), CommonNetAPIError>
 
pub fn set_raw_on_stream_end( &mut self, on_end: Option<UnderlyingOnStreamEndService<State>>, ) -> Result<(), CommonNetAPIError>
Set a hook to run when a stream is being destroyed.
This is what happens when a machine disconnects. So it may also be
refered to as “on disconnect”. This assumes you’re assigning a service
that already exists and is in the raw storage type, you may want to
look into Self::set_on_stream_end, or
Self::set_on_stream_end_service.
§Errors
If the stream ending hook has already been registered. If you’re looking to perform multiple actions at once, look into layer-ing.
Sourcepub fn set_on_stream_end<HandlerTy, HandlerParamsTy>(
    &mut self,
    handler: HandlerTy,
) -> Result<(), CommonNetAPIError>where
    HandlerParamsTy: Send + 'static,
    HandlerTy: OnResponseStreamEndHandler<HandlerParamsTy, State> + Clone + Send + 'static,
 
pub fn set_on_stream_end<HandlerTy, HandlerParamsTy>(
    &mut self,
    handler: HandlerTy,
) -> Result<(), CommonNetAPIError>where
    HandlerParamsTy: Send + 'static,
    HandlerTy: OnResponseStreamEndHandler<HandlerParamsTy, State> + Clone + Send + 'static,
Set a function hook to run when a stream is being destroyed.
This is what happens when a machine disconnects. So it may also be
refered to as “on disconnect”. This assumes you’re assigning a function
to on stream end otherwise use Self::set_raw_on_stream_end,
or Self::set_on_stream_end_service.
§Errors
If the stream ending hook has already been registered. If you’re looking to perform multiple actions at once, look into layer-ing.
Sourcepub fn set_on_stream_end_service<ServiceTy>(
    &mut self,
    service_ty: ServiceTy,
) -> Result<(), CommonNetAPIError>where
    ServiceTy: Clone + Send + Service<ResponseStreamEvent<State>, Response = (), Error = CatBridgeError> + 'static,
    ServiceTy::Future: Send + 'static,
 
pub fn set_on_stream_end_service<ServiceTy>(
    &mut self,
    service_ty: ServiceTy,
) -> Result<(), CommonNetAPIError>where
    ServiceTy: Clone + Send + Service<ResponseStreamEvent<State>, Response = (), Error = CatBridgeError> + 'static,
    ServiceTy::Future: Send + 'static,
Set a function hook to run when a stream is being destroyed.
This is what happens when a machine disconnects. So it may also be
refered to as “on disconnect”. This assumes you’re assigning a Service
to on stream end otherwise use Self::set_raw_on_stream_end,
or Self::set_on_stream_end.
§Errors
If the stream beginning hook has already been registered. If you’re looking to perform multiple actions at once, look into layer-ing.
Sourcepub fn layer_on_stream_end<LayerTy, ServiceTy>(
    &mut self,
    layer: LayerTy,
) -> Result<(), CommonNetAPIError>where
    LayerTy: Layer<UnderlyingOnStreamEndService<State>, Service = ServiceTy>,
    ServiceTy: Service<ResponseStreamEvent<State>, Response = (), Error = CatBridgeError> + Clone + Send + 'static,
    <LayerTy::Service as Service<ResponseStreamEvent<State>>>::Future: Send + 'static,
 
pub fn layer_on_stream_end<LayerTy, ServiceTy>(
    &mut self,
    layer: LayerTy,
) -> Result<(), CommonNetAPIError>where
    LayerTy: Layer<UnderlyingOnStreamEndService<State>, Service = ServiceTy>,
    ServiceTy: Service<ResponseStreamEvent<State>, Response = (), Error = CatBridgeError> + Clone + Send + 'static,
    <LayerTy::Service as Service<ResponseStreamEvent<State>>>::Future: Send + 'static,
Add a layer to the service to process when a stream ends, or a new connection is destroyed.
§Errors
If there is no on stream end handler that is currently active.
pub const fn initial_service( &self, ) -> &BoxCloneService<Request<State>, Response, Infallible>
pub fn layer_initial_service<LayerTy, ServiceTy>(&mut self, layer: LayerTy)
Sourcepub async fn connect(self) -> Result<(), CatBridgeError>
 
pub async fn connect(self) -> Result<(), CatBridgeError>
“Connect” to our remote client address, and start serving ourselves to whoever we connect too.
NOTE: this will NOT return until the service either runs into an error, or the task is cancelled.
§Errors
If we cannot connect to the remote source, fetch the local address, or handle the connection in some other way.
Sourcepub async fn bind(self) -> Result<(), CatBridgeError>
 
pub async fn bind(self) -> Result<(), CatBridgeError>
Bind this server, and start listening on the specified address.
NOTE: this will NOT return until the service either runs into an error, or gets cancelled.
§Errors
- If we cannot bind to the requested address, and port.
- If we run into an error accept’ing a TCP connection.
Trait Implementations§
Source§impl<State: Clone + Debug + Send + Sync + Valuable + 'static> Structable for TCPServer<State>
 
impl<State: Clone + Debug + Send + Sync + Valuable + 'static> Structable for TCPServer<State>
Source§fn definition(&self) -> StructDef<'_>
 
fn definition(&self) -> StructDef<'_>
Auto Trait Implementations§
impl<State> Freeze for TCPServer<State>where
    State: Freeze,
impl<State = ()> !RefUnwindSafe for TCPServer<State>
impl<State> Send for TCPServer<State>
impl<State = ()> !Sync for TCPServer<State>
impl<State> Unpin for TCPServer<State>where
    State: Unpin,
impl<State = ()> !UnwindSafe for TCPServer<State>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
 
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
 
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
 
fn in_current_span(self) -> Instrumented<Self>
Source§impl<D> OwoColorize for D
 
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
    C: Color,
 
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
    C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
    C: Color,
 
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
    C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
 
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
 
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
 
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
 
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
 
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
 
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
 
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
 
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
 
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
 
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
 
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
 
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
 
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
 
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
 
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
 
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
 
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
 
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
 
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
 
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
 
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
 
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
 
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
 
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
 
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
 
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
 
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
 
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
 
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
 
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
 
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
 
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
 
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
 
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
 
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
 
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
 
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
 
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
 
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
 
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
 
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
 
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
 
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
 
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
 
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
 
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
    Color: DynColor,
 
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
    Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
    Color: DynColor,
 
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
    Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more