-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transport): add unix socket support in server (#861)
- Loading branch information
Showing
5 changed files
with
120 additions
and
79 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
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(), | ||
} | ||
} | ||
} |