File tree Expand file tree Collapse file tree 4 files changed +29
-2
lines changed Expand file tree Collapse file tree 4 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ impl axum::serve::Listener for Listener {
4747 }
4848 }
4949 fn local_addr ( & self ) -> io:: Result < Self :: Addr > {
50- self . 0 . listener ( ) . local_addr ( )
50+ self . 0 . local_addr ( )
5151 }
5252}
5353
Original file line number Diff line number Diff line change 9090 current : first_future,
9191 }
9292}
93+
94+ ///An AsyncListener that can also report its local address
95+ pub trait AsyncListener : AsyncAccept {
96+ /// The local address of the listener, if available.
97+ fn local_addr ( & self ) -> Result < Self :: Address , Self :: Error > ;
98+ }
Original file line number Diff line number Diff line change @@ -247,6 +247,11 @@ where
247247 pub fn listener ( & self ) -> & A {
248248 & self . listener
249249 }
250+
251+ /// Get the local address of the underlying listener
252+ pub fn local_addr ( & self ) -> Result < A :: Address , A :: Error > where A : AsyncListener {
253+ self . listener . local_addr ( )
254+ }
250255}
251256
252257impl < A , T > Stream for TlsListener < A , T >
Original file line number Diff line number Diff line change 1- use super :: AsyncAccept ;
1+ use super :: { AsyncAccept , AsyncListener } ;
22use std:: io;
33use std:: pin:: Pin ;
44use std:: task:: { Context , Poll } ;
@@ -24,6 +24,14 @@ impl AsyncAccept for TcpListener {
2424 }
2525}
2626
27+ #[ cfg_attr( docsrs, doc( cfg( feature = "tokio-net" ) ) ) ]
28+ impl AsyncListener for TcpListener {
29+ #[ inline]
30+ fn local_addr ( & self ) -> Result < Self :: Address , Self :: Error > {
31+ TcpListener :: local_addr ( self )
32+ }
33+ }
34+
2735#[ cfg( unix) ]
2836#[ cfg_attr( docsrs, doc( cfg( feature = "tokio-net" ) ) ) ]
2937impl AsyncAccept for UnixListener {
@@ -42,3 +50,11 @@ impl AsyncAccept for UnixListener {
4250 }
4351 }
4452}
53+
54+ #[ cfg_attr( docsrs, doc( cfg( feature = "tokio-net" ) ) ) ]
55+ impl AsyncListener for UnixListener {
56+ #[ inline]
57+ fn local_addr ( & self ) -> Result < Self :: Address , Self :: Error > {
58+ UnixListener :: local_addr ( self )
59+ }
60+ }
You can’t perform that action at this time.
0 commit comments