Skip to content

Commit 7b6ea1d

Browse files
authored
Merge pull request #7 from flokli/tonic-0.12
add tonic 0.12 support
2 parents 60bf55b + 3a3ee2c commit 7b6ea1d

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed

Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ serde = { version = "1.0.171", features = ["derive"] , optional = true}
2828
serde_with = { version = "3.0.0", optional = true}
2929
socket2 = {version="0.5.3", optional=true, features=["all"]}
3030
tokio = { version = "1.29.1", features = ["net", "io-std", "time", "sync"] }
31-
tonic = { package = "tonic", version = "0.11.0", optional = true }
31+
tonic_012 = { package = "tonic", version = "0.12.0", optional = true }
32+
tonic_011 = { package = "tonic", version = "0.11.0", optional = true }
3233
tonic_010 = { package = "tonic", version = "0.10.2", optional = true }
3334
tracing = "0.1.37"
3435
axum07 = { version="0.7", package="axum", optional=true }
@@ -73,7 +74,10 @@ socket_options = ["socket2"]
7374
tonic010 = ["dep:tonic_010"]
7475

7576
## Enable `tonic(v0.11)::transport::server::Connected` implementation for [`Connection`]
76-
tonic011 = ["dep:tonic"]
77+
tonic011 = ["dep:tonic_011"]
78+
79+
## Enable `tonic(v0.12)::transport::server::Connected` implementation for [`Connection`]
80+
tonic012 = ["dep:tonic_012"]
7781

7882
## Enable [`tokio_util::net::Listener`] implementation for [`Listener`].
7983
tokio-util = ["dep:tokio-util"]
@@ -90,7 +94,7 @@ hyper014 = { version = "0.14.27", features = ["server", "http1"], package="hyper
9094
tokio = { version = "1.29.1", features = ["macros", "rt", "io-util"] }
9195
tokio-test = "0.4.2"
9296
toml = "0.7.6"
93-
tonic-health = "0.11.0"
97+
tonic-health = "0.12.0"
9498
tracing-subscriber = "0.3.17"
9599

96100
[[example]]

examples/tonic.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/// A simple example of how to use tokio-listener with a tonic gRPC server.
2-
use tonic::transport::Server;
2+
/// Keep in mind tokio-listener supports different tonic versions, and
3+
/// version-suffixes them.
4+
/// In your code, the crate would probably just be called "tonic".
5+
use tonic_012::transport::Server;
36
use tonic_health::server::health_reporter;
47

58
#[tokio::main(flavor = "current_thread")]

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ mod tonic010;
118118
#[cfg_attr(docsrs_alt, doc(cfg(feature = "tonic011")))]
119119
mod tonic011;
120120

121+
#[cfg(feature = "tonic012")]
122+
#[cfg_attr(docsrs_alt, doc(cfg(feature = "tonic012")))]
123+
mod tonic012;
124+
121125
#[cfg(feature = "tokio-util")]
122126
#[cfg_attr(docsrs_alt, doc(cfg(feature = "tokio-util")))]
123127
mod tokioutil;

src/tonic011.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(all(feature = "unix", unix))]
2-
use tonic::transport::server::UdsConnectInfo;
3-
use tonic::transport::server::{Connected, TcpConnectInfo};
2+
use tonic_011::transport::server::UdsConnectInfo;
3+
use tonic_011::transport::server::{Connected, TcpConnectInfo};
44

55
use crate::Connection;
66

src/tonic012.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#[cfg(all(feature = "unix", unix))]
2+
use tonic_012::transport::server::UdsConnectInfo;
3+
use tonic_012::transport::server::{Connected, TcpConnectInfo};
4+
5+
use crate::Connection;
6+
7+
#[derive(Clone)]
8+
pub enum ListenerConnectInfo {
9+
Tcp(TcpConnectInfo),
10+
#[cfg(all(feature = "unix", unix))]
11+
#[cfg_attr(docsrs_alt, doc(cfg(all(feature = "unix", unix))))]
12+
Unix(UdsConnectInfo),
13+
#[cfg(feature = "inetd")]
14+
#[cfg_attr(docsrs_alt, doc(cfg(feature = "inetd")))]
15+
Stdio,
16+
Other,
17+
}
18+
19+
impl Connected for Connection {
20+
type ConnectInfo = ListenerConnectInfo;
21+
22+
fn connect_info(&self) -> Self::ConnectInfo {
23+
if let Some(tcp_stream) = self.try_borrow_tcp() {
24+
return ListenerConnectInfo::Tcp(tcp_stream.connect_info());
25+
}
26+
#[cfg(all(feature = "unix", unix))]
27+
if let Some(unix_stream) = self.try_borrow_unix() {
28+
return ListenerConnectInfo::Unix(unix_stream.connect_info());
29+
}
30+
#[cfg(feature = "inetd")]
31+
if self.try_borrow_stdio().is_some() {
32+
return ListenerConnectInfo::Stdio;
33+
}
34+
35+
ListenerConnectInfo::Other
36+
}
37+
}

0 commit comments

Comments
 (0)