pub struct StreamEchoServer<P: StreamProtocol> { /* private fields */ }Expand description
Generic stream-based echo server that works with any stream protocol
This server can work with any protocol that implements StreamProtocol,
such as TCP, Unix streams, etc.
§Examples
Basic server setup and running:
use echosrv::stream::{StreamConfig, StreamEchoServer};
use echosrv::common::EchoServerTrait;
use echosrv::tcp::TcpProtocol;
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = StreamConfig {
bind_addr: "127.0.0.1:8080".parse()?,
max_connections: 100,
buffer_size: 1024,
read_timeout: Duration::from_secs(30),
write_timeout: Duration::from_secs(30),
};
let server: StreamEchoServer<TcpProtocol> = StreamEchoServer::new(config);
server.run().await?;
Ok(())
}Implementations§
Source§impl<P: StreamProtocol> StreamEchoServer<P>
impl<P: StreamProtocol> StreamEchoServer<P>
Sourcepub fn new(config: StreamConfig) -> Self
pub fn new(config: StreamConfig) -> Self
Creates a new stream-based echo server with the given configuration
Trait Implementations§
Source§impl<P: StreamProtocol + Sync> EchoServerTrait for StreamEchoServer<P>
impl<P: StreamProtocol + Sync> EchoServerTrait for StreamEchoServer<P>
Source§fn run<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn run<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Starts the stream-based echo server and listens for connections
Source§fn shutdown_signal(&self) -> Sender<()>
fn shutdown_signal(&self) -> Sender<()>
Returns a shutdown signal sender that can be used to gracefully shutdown the server
Auto Trait Implementations§
impl<P> !RefUnwindSafe for StreamEchoServer<P>
impl<P> !UnwindSafe for StreamEchoServer<P>
impl<P> Freeze for StreamEchoServer<P>
impl<P> Send for StreamEchoServer<P>where
P: Send,
impl<P> Sync for StreamEchoServer<P>where
P: Sync,
impl<P> Unpin for StreamEchoServer<P>where
P: Unpin,
impl<P> UnsafeUnpin for StreamEchoServer<P>
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
Mutably borrows from an owned value. Read more