sansio_bootstrap/bootstrap_tcp/
bootstrap_tcp_client.rs

1use super::*;
2
3/// A Bootstrap that makes it easy to bootstrap a pipeline to use for TCP clients.
4pub struct BootstrapTcpClient<W> {
5    bootstrap_tcp: BootstrapTcp<W>,
6}
7
8impl<W: 'static> Default for BootstrapTcpClient<W> {
9    fn default() -> Self {
10        Self::new()
11    }
12}
13
14impl<W: 'static> BootstrapTcpClient<W> {
15    /// Creates a new BootstrapTcpClient
16    pub fn new() -> Self {
17        Self {
18            bootstrap_tcp: BootstrapTcp::new(),
19        }
20    }
21
22    /// Sets max payload size, default is 2048 bytes
23    pub fn max_payload_size(&mut self, max_payload_size: usize) -> &mut Self {
24        self.bootstrap_tcp.max_payload_size(max_payload_size);
25        self
26    }
27
28    /// Creates pipeline instances from when calling [BootstrapTcpClient::connect].
29    pub fn pipeline(
30        &mut self,
31        pipeline_factory_fn: PipelineFactoryFn<TaggedBytesMut, W>,
32    ) -> &mut Self {
33        self.bootstrap_tcp.pipeline(pipeline_factory_fn);
34        self
35    }
36
37    /// Connects to the remote peer
38    pub async fn connect<A: ToSocketAddrs>(
39        &mut self,
40        addr: A,
41    ) -> Result<Rc<dyn RcOutboundPipeline<W>>, Error> {
42        self.bootstrap_tcp.connect(addr).await
43    }
44
45    /// Stops the client
46    pub async fn stop(&self) {
47        self.bootstrap_tcp.stop().await
48    }
49
50    /// Waits for stop of the client
51    pub async fn wait_for_stop(&self) {
52        self.bootstrap_tcp.wait_for_stop().await
53    }
54
55    /// Gracefully stop the client
56    pub async fn graceful_stop(&self) {
57        self.bootstrap_tcp.graceful_stop().await
58    }
59}