Skip to content

Commit

Permalink
feat: Add tcp setting getters to endpoint (#1983)
Browse files Browse the repository at this point in the history
Add getters for tcp settings to Endpoints. The purpose for this is that
`connect_with_connector` doesn't set TCP settings on the socket, because
it's using a provided connector. In the cases where a library is creating
a custom TCP connection, we want to be able to respect user tcp
settings, in particular connection timeout. Adding these getters allows
this.
  • Loading branch information
Benjscho authored Oct 14, 2024
1 parent 5c9fa88 commit cb534a7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tonic/src/transport/channel/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,25 @@ impl Endpoint {
pub fn uri(&self) -> &Uri {
&self.uri
}

/// Get the value of `TCP_NODELAY` option for accepted connections.
pub fn get_tcp_nodelay(&self) -> bool {
self.tcp_nodelay
}

/// Get the connect timeout.
pub fn get_connect_timeout(&self) -> Option<Duration> {
self.connect_timeout
}

/// Get whether TCP keepalive messages are enabled on accepted connections.
///
/// If `None` is specified, keepalive is disabled, otherwise the duration
/// specified will be the time to remain idle before sending TCP keepalive
/// probes.
pub fn get_tcp_keepalive(&self) -> Option<Duration> {
self.tcp_keepalive
}
}

impl From<Uri> for Endpoint {
Expand Down

0 comments on commit cb534a7

Please sign in to comment.