vector_core/
tcp.rs

1use socket2::SockRef;
2use tokio::net::TcpStream;
3use vector_config::configurable_component;
4
5/// TCP keepalive settings for socket-based components.
6#[configurable_component]
7#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8#[serde(deny_unknown_fields)]
9#[configurable(metadata(docs::human_name = "Wait Time"))]
10pub struct TcpKeepaliveConfig {
11    /// The time to wait before starting to send TCP keepalive probes on an idle connection.
12    #[configurable(metadata(docs::type_unit = "seconds"))]
13    pub time_secs: Option<u64>,
14}
15
16// This function will be obsolete after tokio/mio internally use `socket2` and expose the methods to
17// apply options to a socket.
18pub(crate) fn set_keepalive(
19    socket: &TcpStream,
20    params: &socket2::TcpKeepalive,
21) -> std::io::Result<()> {
22    SockRef::from(socket).set_tcp_keepalive(params)
23}
24
25// This function will be obsolete after tokio/mio internally use `socket2` and expose the methods to
26// apply options to a socket.
27pub(crate) fn set_receive_buffer_size(socket: &TcpStream, size: usize) -> std::io::Result<()> {
28    SockRef::from(socket).set_recv_buffer_size(size)
29}
30
31// This function will be obsolete after tokio/mio internally use `socket2` and expose the methods to
32// apply options to a socket.
33pub(crate) fn set_send_buffer_size(socket: &TcpStream, size: usize) -> std::io::Result<()> {
34    SockRef::from(socket).set_send_buffer_size(size)
35}