Skip to content

Commit

Permalink
feat(client): HttpConnector: allow to set socket buffer sizes
Browse files Browse the repository at this point in the history
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
  • Loading branch information
maurerdietmar authored and seanmonstar committed Jul 1, 2019
1 parent 31ec07a commit 386109c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/client/connect/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub struct HttpConnector<R = GaiResolver> {
nodelay: bool,
resolver: R,
reuse_address: bool,
send_buf_size: Option<usize>,
recv_buf_size: Option<usize>,
}

/// Extra information about the transport when an HttpConnector is used.
Expand Down Expand Up @@ -124,6 +126,8 @@ impl<R> HttpConnector<R> {
nodelay: false,
resolver,
reuse_address: false,
send_buf_size: None,
recv_buf_size: None,
}
}

Expand Down Expand Up @@ -161,6 +165,18 @@ impl<R> HttpConnector<R> {
self.nodelay = nodelay;
}

/// Sets the value of the SO_SNDBUF option on the socket.
#[inline]
pub fn set_send_buf_size(&mut self, size: Option<usize>) {
self.send_buf_size = size;
}

/// Sets the value of the SO_RCVBUF option on the socket.
#[inline]
pub fn set_recv_buf_size(&mut self, size: Option<usize>) {
self.recv_buf_size = size;
}

/// Set that all sockets are bound to the configured address before connection.
///
/// If `None`, the sockets will not be bound.
Expand Down Expand Up @@ -248,6 +264,8 @@ where
nodelay: self.nodelay,
port,
reuse_address: self.reuse_address,
send_buf_size: self.send_buf_size,
recv_buf_size: self.recv_buf_size,
}
}
}
Expand All @@ -269,6 +287,8 @@ fn invalid_url<R: Resolve>(err: InvalidUrl, handle: &Option<Handle>) -> HttpConn
port: 0,
happy_eyeballs_timeout: None,
reuse_address: false,
send_buf_size: None,
recv_buf_size: None,
}
}

Expand Down Expand Up @@ -304,6 +324,8 @@ pub struct HttpConnecting<R: Resolve = GaiResolver> {
nodelay: bool,
port: u16,
reuse_address: bool,
send_buf_size: Option<usize>,
recv_buf_size: Option<usize>,
}

enum State<R: Resolve> {
Expand Down Expand Up @@ -353,6 +375,14 @@ impl<R: Resolve> Future for HttpConnecting<R> {
sock.set_keepalive(Some(dur))?;
}

if let Some(size) = self.send_buf_size {
sock.set_send_buffer_size(size)?;
}

if let Some(size) = self.recv_buf_size {
sock.set_recv_buffer_size(size)?;
}

sock.set_nodelay(self.nodelay)?;

let extra = HttpInfo {
Expand Down

0 comments on commit 386109c

Please sign in to comment.