Skip to content

Commit 8ceb157

Browse files
committed
acceptor: linearize AsyncRead and AsyncWrite implementations
1 parent 84b7a7d commit 8ceb157

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

src/acceptor.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,19 @@ impl AsyncRead for TlsStream {
8686
buf: &mut ReadBuf,
8787
) -> Poll<io::Result<()>> {
8888
let pin = self.get_mut();
89-
match pin.state {
90-
State::Handshaking(ref mut accept) => match ready!(Pin::new(accept).poll(cx)) {
91-
Ok(mut stream) => {
92-
let result = Pin::new(&mut stream).poll_read(cx, buf);
93-
pin.state = State::Streaming(stream);
94-
result
95-
}
96-
Err(err) => Poll::Ready(Err(err)),
97-
},
98-
State::Streaming(ref mut stream) => Pin::new(stream).poll_read(cx, buf),
99-
}
89+
let accept = match &mut pin.state {
90+
State::Handshaking(accept) => accept,
91+
State::Streaming(stream) => return Pin::new(stream).poll_read(cx, buf),
92+
};
93+
94+
let mut stream = match ready!(Pin::new(accept).poll(cx)) {
95+
Ok(stream) => stream,
96+
Err(err) => return Poll::Ready(Err(err)),
97+
};
98+
99+
let result = Pin::new(&mut stream).poll_read(cx, buf);
100+
pin.state = State::Streaming(stream);
101+
result
100102
}
101103
}
102104

@@ -107,17 +109,19 @@ impl AsyncWrite for TlsStream {
107109
buf: &[u8],
108110
) -> Poll<io::Result<usize>> {
109111
let pin = self.get_mut();
110-
match pin.state {
111-
State::Handshaking(ref mut accept) => match ready!(Pin::new(accept).poll(cx)) {
112-
Ok(mut stream) => {
113-
let result = Pin::new(&mut stream).poll_write(cx, buf);
114-
pin.state = State::Streaming(stream);
115-
result
116-
}
117-
Err(err) => Poll::Ready(Err(err)),
118-
},
119-
State::Streaming(ref mut stream) => Pin::new(stream).poll_write(cx, buf),
120-
}
112+
let accept = match &mut pin.state {
113+
State::Handshaking(accept) => accept,
114+
State::Streaming(stream) => return Pin::new(stream).poll_write(cx, buf),
115+
};
116+
117+
let mut stream = match ready!(Pin::new(accept).poll(cx)) {
118+
Ok(stream) => stream,
119+
Err(err) => return Poll::Ready(Err(err)),
120+
};
121+
122+
let result = Pin::new(&mut stream).poll_write(cx, buf);
123+
pin.state = State::Streaming(stream);
124+
result
121125
}
122126

123127
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {

0 commit comments

Comments
 (0)