@@ -7,12 +7,16 @@ use std::ops::{Deref, DerefMut};
7
7
impl AsyncAccept for AddrIncoming {
8
8
type Connection = AddrStream ;
9
9
type Error = std:: io:: Error ;
10
+ type Address = std:: net:: SocketAddr ;
10
11
11
12
fn poll_accept (
12
13
self : Pin < & mut Self > ,
13
14
cx : & mut Context < ' _ > ,
14
- ) -> Poll < Option < Result < Self :: Connection , Self :: Error > > > {
15
- <AddrIncoming as HyperAccept >:: poll_accept ( self , cx)
15
+ ) -> Poll < Option < Result < ( Self :: Connection , Self :: Address ) , Self :: Error > > > {
16
+ <AddrIncoming as HyperAccept >:: poll_accept ( self , cx) . map_ok ( |conn| {
17
+ let peer_addr = conn. remote_addr ( ) ;
18
+ ( conn, peer_addr)
19
+ } )
16
20
}
17
21
}
18
22
@@ -22,6 +26,11 @@ pin_project! {
22
26
/// Unfortunately, it isn't possible to use a blanket impl, due to coherence rules.
23
27
/// At least until [RFC 1210](https://rust-lang.github.io/rfcs/1210-impl-specialization.html)
24
28
/// (specialization) is stabilized.
29
+ ///
30
+ /// Note that, because `hyper::server::accept::Accept` does not expose the
31
+ /// remote address, the implementation of `AsyncAccept` for `WrappedAccept`
32
+ /// doesn't expose it either. That is, [`AsyncAccept::Address`] is `()` in
33
+ /// this case.
25
34
//#[cfg_attr(docsrs, doc(cfg(any(feature = "hyper-h1", feature = "hyper-h2"))))]
26
35
pub struct WrappedAccept <A > {
27
36
// sadly, pin-project-lite doesn't suport tuple structs :(
@@ -43,15 +52,20 @@ pub fn wrap<A: HyperAccept>(acceptor: A) -> WrappedAccept<A> {
43
52
impl < A : HyperAccept > AsyncAccept for WrappedAccept < A >
44
53
where
45
54
A :: Conn : AsyncRead + AsyncWrite ,
55
+ A :: Error : std:: error:: Error ,
46
56
{
47
57
type Connection = A :: Conn ;
48
58
type Error = A :: Error ;
59
+ type Address = ( ) ;
49
60
50
61
fn poll_accept (
51
62
self : Pin < & mut Self > ,
52
63
cx : & mut Context < ' _ > ,
53
- ) -> Poll < Option < Result < Self :: Connection , Self :: Error > > > {
54
- self . project ( ) . inner . poll_accept ( cx)
64
+ ) -> Poll < Option < Result < ( Self :: Connection , ( ) ) , Self :: Error > > > {
65
+ self . project ( )
66
+ . inner
67
+ . poll_accept ( cx)
68
+ . map_ok ( |conn| ( conn, ( ) ) )
55
69
}
56
70
}
57
71
@@ -78,6 +92,7 @@ impl<A: HyperAccept> WrappedAccept<A> {
78
92
impl < A : HyperAccept , T > TlsListener < WrappedAccept < A > , T >
79
93
where
80
94
A :: Conn : AsyncWrite + AsyncRead ,
95
+ A :: Error : std:: error:: Error ,
81
96
T : AsyncTls < A :: Conn > ,
82
97
{
83
98
/// Create a `TlsListener` from a hyper [`Accept`](::hyper::server::accept::Accept) and tls
@@ -95,12 +110,12 @@ where
95
110
T : AsyncTls < A :: Connection > ,
96
111
{
97
112
type Conn = T :: Stream ;
98
- type Error = Error < A :: Error , T :: Error > ;
113
+ type Error = Error < A :: Error , T :: Error , A :: Address > ;
99
114
100
115
fn poll_accept (
101
116
self : Pin < & mut Self > ,
102
117
cx : & mut Context < ' _ > ,
103
118
) -> Poll < Option < Result < Self :: Conn , Self :: Error > > > {
104
- self . poll_next ( cx)
119
+ self . poll_next ( cx) . map_ok ( | ( conn , _ ) | conn )
105
120
}
106
121
}
0 commit comments