Skip to content

Commit 4933210

Browse files
committed
fixup! tonic: implement the server Connected trait for tokio UnixStream
1 parent 288a9a7 commit 4933210

File tree

3 files changed

+41
-38
lines changed

3 files changed

+41
-38
lines changed

tonic/src/transport/server/conn.rs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use tokio::net::TcpStream;
44

55
#[cfg(feature = "tls")]
66
use crate::transport::Certificate;
7-
#[cfg(any(unix, feature = "tls"))]
7+
#[cfg(feature = "tls")]
88
use std::sync::Arc;
99
#[cfg(feature = "tls")]
1010
use tokio_rustls::{rustls::Session, server::TlsStream};
@@ -98,42 +98,6 @@ impl Connected for TcpStream {
9898
}
9999
}
100100

101-
/// Connection info for Unix domain socket streams.
102-
///
103-
/// This type will be accessible through [request extensions][ext] if you're using
104-
/// a unix stream.
105-
///
106-
/// See [`Connected`] for more details.
107-
///
108-
/// [ext]: crate::Request::extensions
109-
#[cfg(unix)]
110-
#[cfg_attr(docsrs, doc(cfg(unix)))]
111-
#[derive(Clone, Debug)]
112-
pub struct UdsConnectInfo {
113-
/// Peer address. This will be "unnamed" for client unix sockets.
114-
pub peer_addr: Option<Arc<tokio::net::unix::SocketAddr>>,
115-
/// Process credentials for the unix socket.
116-
pub peer_cred: Option<tokio::net::unix::UCred>,
117-
}
118-
119-
#[cfg(unix)]
120-
impl Connected for tokio::net::UnixStream {
121-
type ConnectInfo = UdsConnectInfo;
122-
123-
fn connect_info(&self) -> Self::ConnectInfo {
124-
UdsConnectInfo {
125-
peer_addr: self.peer_addr().ok().map(Arc::new),
126-
peer_cred: self.peer_cred().ok(),
127-
}
128-
}
129-
}
130-
131-
impl Connected for tokio::io::DuplexStream {
132-
type ConnectInfo = ();
133-
134-
fn connect_info(&self) -> Self::ConnectInfo {}
135-
}
136-
137101
#[cfg(feature = "tls")]
138102
impl<T> Connected for TlsStream<T>
139103
where

tonic/src/transport/server/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ mod recover_error;
66
#[cfg(feature = "tls")]
77
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
88
mod tls;
9+
#[cfg(unix)]
10+
mod unix;
911

1012
pub use conn::{Connected, TcpConnectInfo};
1113
#[cfg(feature = "tls")]
@@ -18,7 +20,7 @@ pub use conn::TlsConnectInfo;
1820
use super::service::TlsAcceptor;
1921

2022
#[cfg(unix)]
21-
pub use conn::UdsConnectInfo;
23+
pub use unix::UdsConnectInfo;
2224

2325
use incoming::TcpIncoming;
2426

tonic/src/transport/server/unix.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use super::Connected;
2+
use std::sync::Arc;
3+
4+
/// Connection info for Unix domain socket streams.
5+
///
6+
/// This type will be accessible through [request extensions][ext] if you're using
7+
/// a unix stream.
8+
///
9+
/// See [Connected] for more details.
10+
///
11+
/// [ext]: crate::Request::extensions
12+
/// [Connected]: crate::transport::server::Connected
13+
#[cfg_attr(docsrs, doc(cfg(unix)))]
14+
#[derive(Clone, Debug)]
15+
pub struct UdsConnectInfo {
16+
/// Peer address. This will be "unnamed" for client unix sockets.
17+
pub peer_addr: Option<Arc<tokio::net::unix::SocketAddr>>,
18+
/// Process credentials for the unix socket.
19+
pub peer_cred: Option<tokio::net::unix::UCred>,
20+
}
21+
22+
impl Connected for tokio::net::UnixStream {
23+
type ConnectInfo = UdsConnectInfo;
24+
25+
fn connect_info(&self) -> Self::ConnectInfo {
26+
UdsConnectInfo {
27+
peer_addr: self.peer_addr().ok().map(Arc::new),
28+
peer_cred: self.peer_cred().ok(),
29+
}
30+
}
31+
}
32+
33+
impl Connected for tokio::io::DuplexStream {
34+
type ConnectInfo = ();
35+
36+
fn connect_info(&self) -> Self::ConnectInfo {}
37+
}

0 commit comments

Comments
 (0)