Skip to content

Commit 49a011c

Browse files
authored
Merge pull request #20 from tmccombs/net-refactor
Refactor tokio-net features into seperate mod
2 parents 8cf2162 + 21fc694 commit 49a011c

File tree

3 files changed

+46
-39
lines changed

3 files changed

+46
-39
lines changed

src/hyper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::ops::{Deref, DerefMut};
66
#[cfg_attr(docsrs, doc(cfg(any(feature = "hyper-h1", feature = "hyper-h2"))))]
77
impl AsyncAccept for AddrIncoming {
88
type Connection = AddrStream;
9-
type Error = io::Error;
9+
type Error = std::io::Error;
1010

1111
fn poll_accept(
1212
self: Pin<&mut Self>,

src/lib.rs

+4-38
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use pin_project_lite::pin_project;
2020
#[cfg(feature = "rt")]
2121
pub use spawning_handshake::SpawningHandshakes;
2222
use std::future::Future;
23-
use std::io;
2423
use std::pin::Pin;
2524
use std::task::{Context, Poll};
2625
use std::time::Duration;
@@ -35,6 +34,9 @@ mod spawning_handshake;
3534
#[cfg(any(feature = "hyper-h1", feature = "hyper-h2"))]
3635
pub mod hyper;
3736

37+
#[cfg(feature = "tokio-net")]
38+
mod net;
39+
3840
/// Default number of concurrent handshakes
3941
pub const DEFAULT_MAX_HANDSHAKES: usize = 64;
4042
/// Default timeout for the TLS handshake.
@@ -228,7 +230,7 @@ where
228230
#[cfg(feature = "rustls")]
229231
impl<C: AsyncRead + AsyncWrite + Unpin> AsyncTls<C> for tokio_rustls::TlsAcceptor {
230232
type Stream = tokio_rustls::server::TlsStream<C>;
231-
type Error = io::Error;
233+
type Error = std::io::Error;
232234
type AcceptFuture = tokio_rustls::Accept<C>;
233235

234236
fn accept(&self, conn: C) -> Self::AcceptFuture {
@@ -305,42 +307,6 @@ pub fn builder<T>(tls: T) -> Builder<T> {
305307
}
306308
}
307309

308-
#[cfg(feature = "tokio-net")]
309-
#[cfg_attr(docsrs, doc(cfg(feature = "tokio-net")))]
310-
impl AsyncAccept for tokio::net::TcpListener {
311-
type Connection = tokio::net::TcpStream;
312-
type Error = io::Error;
313-
314-
fn poll_accept(
315-
self: Pin<&mut Self>,
316-
cx: &mut Context<'_>,
317-
) -> Poll<Option<Result<Self::Connection, Self::Error>>> {
318-
match (*self).poll_accept(cx) {
319-
Poll::Ready(Ok((stream, _))) => Poll::Ready(Some(Ok(stream))),
320-
Poll::Ready(Err(e)) => Poll::Ready(Some(Err(e))),
321-
Poll::Pending => Poll::Pending,
322-
}
323-
}
324-
}
325-
326-
#[cfg(all(unix, feature = "tokio-net"))]
327-
#[cfg_attr(docsrs, doc(cfg(feature = "tokio-net")))]
328-
impl AsyncAccept for tokio::net::UnixListener {
329-
type Connection = tokio::net::UnixStream;
330-
type Error = io::Error;
331-
332-
fn poll_accept(
333-
self: Pin<&mut Self>,
334-
cx: &mut Context<'_>,
335-
) -> Poll<Option<Result<Self::Connection, Self::Error>>> {
336-
match (*self).poll_accept(cx) {
337-
Poll::Ready(Ok((stream, _))) => Poll::Ready(Some(Ok(stream))),
338-
Poll::Ready(Err(e)) => Poll::Ready(Some(Err(e))),
339-
Poll::Pending => Poll::Pending,
340-
}
341-
}
342-
}
343-
344310
pin_project! {
345311
/// See [`AsyncAccept::until`]
346312
pub struct Until<A, E> {

src/net.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use super::AsyncAccept;
2+
use std::io;
3+
use std::pin::Pin;
4+
use std::task::{Context, Poll};
5+
use tokio::net::{TcpListener, TcpStream, UnixListener, UnixStream};
6+
7+
#[cfg(feature = "tokio-net")]
8+
#[cfg_attr(docsrs, doc(cfg(feature = "tokio-net")))]
9+
impl AsyncAccept for TcpListener {
10+
type Connection = TcpStream;
11+
type Error = io::Error;
12+
13+
fn poll_accept(
14+
self: Pin<&mut Self>,
15+
cx: &mut Context<'_>,
16+
) -> Poll<Option<Result<Self::Connection, Self::Error>>> {
17+
match (*self).poll_accept(cx) {
18+
Poll::Ready(Ok((stream, _))) => Poll::Ready(Some(Ok(stream))),
19+
Poll::Ready(Err(e)) => Poll::Ready(Some(Err(e))),
20+
Poll::Pending => Poll::Pending,
21+
}
22+
}
23+
}
24+
25+
#[cfg(all(unix, feature = "tokio-net"))]
26+
#[cfg_attr(docsrs, doc(cfg(feature = "tokio-net")))]
27+
impl AsyncAccept for UnixListener {
28+
type Connection = UnixStream;
29+
type Error = io::Error;
30+
31+
fn poll_accept(
32+
self: Pin<&mut Self>,
33+
cx: &mut Context<'_>,
34+
) -> Poll<Option<Result<Self::Connection, Self::Error>>> {
35+
match (*self).poll_accept(cx) {
36+
Poll::Ready(Ok((stream, _))) => Poll::Ready(Some(Ok(stream))),
37+
Poll::Ready(Err(e)) => Poll::Ready(Some(Err(e))),
38+
Poll::Pending => Poll::Pending,
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)