forked from hyperium/tonic
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tonic: implement the server Connected trait for tokio UnixStream
This impl is needed in order to use a tokio UnixStream as the `incoming` argument in methods like `tonic::transport::server::Router::serve_with_incoming_shutdown` Fixes: hyperium#856 Signed-off-by: Anthony Green <agreen@starry.com>
- Loading branch information
Showing
3 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use super::Connected; | ||
use std::sync::Arc; | ||
|
||
/// Connection info for Unix domain socket streams. | ||
/// | ||
/// This type will be accessible through [request extensions][ext] if you're using | ||
/// a unix stream. | ||
/// | ||
/// See [Connected] for more details. | ||
/// | ||
/// [ext]: crate::Request::extensions | ||
/// [Connected]: crate::transport::server::Connected | ||
#[cfg_attr(docsrs, doc(cfg(unix)))] | ||
#[derive(Clone, Debug)] | ||
pub struct UdsConnectInfo { | ||
/// Peer address. This will be "unnamed" for client unix sockets. | ||
pub peer_addr: Option<Arc<tokio::net::unix::SocketAddr>>, | ||
/// Process credentials for the unix socket. | ||
pub peer_cred: Option<tokio::net::unix::UCred>, | ||
} | ||
|
||
impl Connected for tokio::net::UnixStream { | ||
type ConnectInfo = UdsConnectInfo; | ||
|
||
fn connect_info(&self) -> Self::ConnectInfo { | ||
UdsConnectInfo { | ||
peer_addr: self.peer_addr().ok().map(Arc::new), | ||
peer_cred: self.peer_cred().ok(), | ||
} | ||
} | ||
} |