diff --git a/Cargo.lock b/Cargo.lock index b81e9f1..a3e50be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -482,6 +482,12 @@ dependencies = [ "syn", ] +[[package]] +name = "service-binding" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f8418a60a094aaaf2bd38ed3ee4fea0b188bf5903a9655c144085f1464c221b" + [[package]] name = "slab" version = "0.4.9" @@ -513,6 +519,7 @@ dependencies = [ "log", "openssl", "serde", + "service-binding", "tokio", "tokio-util", ] diff --git a/Cargo.toml b/Cargo.toml index 005766b..96963d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ futures = { version = "0.3.30", optional = true } log = { version = "0.4.6", optional = true } tokio = { version = "1", optional = true, features = ["rt", "net"] } tokio-util = { version = "0.7.1", optional = true, features = ["codec"] } +service-binding = "1.1.0" [features] default = ["agent"] diff --git a/src/agent.rs b/src/agent.rs index 64fc149..86d18ee 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -132,6 +132,16 @@ pub trait Agent: 'static + Sync + Send + Sized { } } } + async fn bind(mut self, listener: service_binding::Listener) -> Result<(), AgentError> { + match listener { + service_binding::Listener::Unix(listener) => { + self.listen(UnixListener::from_std(listener)?).await + } + service_binding::Listener::Tcp(listener) => { + self.listen(TcpListener::from_std(listener)?).await + } + } + } } impl Agent for T