@@ -18,11 +18,8 @@ use std::{borrow::Cow, sync::Arc};
1818
1919use anyhow:: { Context , Result } ;
2020use ra_tls:: traits:: CertExt ;
21- #[ cfg( unix) ]
2221use rocket:: listener:: unix:: UnixStream ;
23- #[ cfg( unix) ]
2422use rocket:: listener:: { Connection , Listener } ;
25- #[ cfg( unix) ]
2623use rocket:: tokio:: io:: { AsyncRead , AsyncWrite , ReadBuf } ;
2724use rocket:: {
2825 data:: { ByteUnit , Data , Limits , ToByteUnit } ,
@@ -59,39 +56,33 @@ impl<'r> Responder<'r, 'static> for RpcResponse {
5956 }
6057}
6158
62- #[ cfg( unix) ]
6359#[ derive( Debug , Clone ) ]
6460struct UnixPeerEndpoint {
6561 path : PathBuf ,
6662 peer : Option < UnixPeerCred > ,
6763}
6864
69- #[ cfg( unix) ]
7065impl fmt:: Display for UnixPeerEndpoint {
7166 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
7267 write ! ( f, "unix:{}" , self . path. display( ) )
7368 }
7469}
7570
76- #[ cfg( unix) ]
7771pub struct UnixPeerCredListener < L > {
7872 inner : L ,
7973}
8074
81- #[ cfg( unix) ]
8275impl < L > UnixPeerCredListener < L > {
8376 pub fn new ( inner : L ) -> Self {
8477 Self { inner }
8578 }
8679}
8780
88- #[ cfg( unix) ]
8981pub struct UnixPeerCredConnection {
9082 stream : UnixStream ,
9183 endpoint : rocket:: listener:: Endpoint ,
9284}
9385
94- #[ cfg( unix) ]
9586impl AsyncRead for UnixPeerCredConnection {
9687 fn poll_read (
9788 mut self : Pin < & mut Self > ,
@@ -102,7 +93,6 @@ impl AsyncRead for UnixPeerCredConnection {
10293 }
10394}
10495
105- #[ cfg( unix) ]
10696impl AsyncWrite for UnixPeerCredConnection {
10797 fn poll_write (
10898 mut self : Pin < & mut Self > ,
@@ -133,14 +123,12 @@ impl AsyncWrite for UnixPeerCredConnection {
133123 }
134124}
135125
136- #[ cfg( unix) ]
137126impl Connection for UnixPeerCredConnection {
138127 fn endpoint ( & self ) -> io:: Result < rocket:: listener:: Endpoint > {
139128 Ok ( self . endpoint . clone ( ) )
140129 }
141130}
142131
143- #[ cfg( unix) ]
144132impl < L > Listener for UnixPeerCredListener < L >
145133where
146134 L : Listener < Accept = UnixStream , Connection = UnixStream > ,
@@ -183,7 +171,6 @@ where
183171 }
184172}
185173
186- #[ cfg( unix) ]
187174fn unix_peer_cred ( stream : & UnixStream ) -> Option < UnixPeerCred > {
188175 let cred = stream. peer_cred ( ) . ok ( ) ?;
189176 let pid = cred. pid ( ) ?;
@@ -412,7 +399,6 @@ impl From<Endpoint> for RemoteEndpoint {
412399 Endpoint :: Tcp ( addr) => RemoteEndpoint :: Tcp ( addr) ,
413400 Endpoint :: Quic ( addr) => RemoteEndpoint :: Quic ( addr) ,
414401 Endpoint :: Unix ( path) => RemoteEndpoint :: Unix { path, peer : None } ,
415- #[ cfg( unix) ]
416402 Endpoint :: Custom ( endpoint) => {
417403 if let Some ( endpoint) =
418404 ( endpoint. as_ref ( ) as & dyn std:: any:: Any ) . downcast_ref :: < UnixPeerEndpoint > ( )
@@ -447,7 +433,7 @@ impl From<Endpoint> for RemoteEndpoint {
447433 }
448434}
449435
450- #[ cfg( all ( test, unix ) ) ]
436+ #[ cfg( test) ]
451437mod tests {
452438 use super :: * ;
453439 use rocket:: listener:: unix:: UnixListener ;
0 commit comments