diff options
author | Florian Klink <flokli@flokli.de> | 2023-10-07T11·33+0200 |
---|---|---|
committer | flokli <flokli@flokli.de> | 2023-10-08T07·44+0000 |
commit | 09328c79d556c22f9b36cef8f7010bfff3f093a8 (patch) | |
tree | d6fb36e5149f5432209a1209061c1da7be7b98b4 /tvix | |
parent | 3b620e6d0c19136241effa48b6fe637c577fc564 (diff) |
feat(tvix/store/listener): implement connect_info() r/6726
For Unix and TCP streams, we can actually give more info than just (). Change-Id: I80ca261b9e7a880389ec2029ea5893180314f0b2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9561 Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI Reviewed-by: Connor Brewster <cbrewster@hey.com>
Diffstat (limited to 'tvix')
-rw-r--r-- | tvix/store/src/listener/mod.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/tvix/store/src/listener/mod.rs b/tvix/store/src/listener/mod.rs index 3a44a0511cb8..ed1220803562 100644 --- a/tvix/store/src/listener/mod.rs +++ b/tvix/store/src/listener/mod.rs @@ -9,7 +9,7 @@ use futures::Stream; use pin_project_lite::pin_project; use tokio::io::{AsyncRead, AsyncWrite}; use tokio_listener::{Listener, ListenerAddress}; -use tonic::transport::server::Connected; +use tonic::transport::server::{Connected, TcpConnectInfo, UdsConnectInfo}; /// A wrapper around a [Listener] which implements the [Stream] trait. /// Mainly used to bridge [tokio_listener] with [tonic]. @@ -72,11 +72,27 @@ impl DerefMut for Connection { } } +#[derive(Clone)] +pub enum ListenerConnectInfo { + TCP(TcpConnectInfo), + Unix(UdsConnectInfo), + Stdio, + Other, +} + impl Connected for Connection { - type ConnectInfo = (); + type ConnectInfo = ListenerConnectInfo; fn connect_info(&self) -> Self::ConnectInfo { - () + if let Some(tcp_stream) = self.try_borrow_tcp() { + ListenerConnectInfo::TCP(tcp_stream.connect_info()) + } else if let Some(unix_stream) = self.try_borrow_unix() { + ListenerConnectInfo::Unix(unix_stream.connect_info()) + } else if let Some(_) = self.try_borrow_stdio() { + ListenerConnectInfo::Stdio + } else { + ListenerConnectInfo::Other + } } } |