summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2019-11-20 11:29:32 -0800
committerGitHub <noreply@github.com>2019-11-20 11:29:32 -0800
commit15dce2d11ad849e25f0336f09fdb1cca7e405a9e (patch)
treee93302cde6de6e7778fa2d842ffddebbd199ac70
parentd4fec2c5d628b180226f6ab3005aa3e5845f1929 (diff)
net: flatten `split` mod (#1797)
The misc `split` types (`ReadHalf`, `WriteHalf`, `SendHalf`, `RecvHalf`) are moved up a module and the `*::split` module is removed.
-rw-r--r--examples/connect.rs15
-rw-r--r--tokio/src/net/tcp/mod.rs9
-rw-r--r--tokio/src/net/udp/mod.rs5
-rw-r--r--tokio/src/net/udp/socket.rs4
-rw-r--r--tokio/src/net/udp/split.rs24
-rw-r--r--tokio/src/net/unix/mod.rs13
6 files changed, 37 insertions, 33 deletions
diff --git a/examples/connect.rs b/examples/connect.rs
index cb003d9d..34b3488d 100644
--- a/examples/connect.rs
+++ b/examples/connect.rs
@@ -115,12 +115,13 @@ mod tcp {
}
mod udp {
+ use tokio::net::udp::{RecvHalf, SendHalf};
+ use tokio::net::UdpSocket;
+
use futures::{future, Sink, SinkExt, Stream, StreamExt};
- use std::{error::Error, io, net::SocketAddr};
- use tokio::net::udp::{
- split::{UdpSocketRecvHalf, UdpSocketSendHalf},
- UdpSocket,
- };
+ use std::error::Error;
+ use std::io;
+ use std::net::SocketAddr;
pub async fn connect(
addr: &SocketAddr,
@@ -146,7 +147,7 @@ mod udp {
async fn send(
mut stdin: impl Stream<Item = Result<Vec<u8>, io::Error>> + Unpin,
- writer: &mut UdpSocketSendHalf,
+ writer: &mut SendHalf,
) -> Result<(), io::Error> {
while let Some(item) = stdin.next().await {
let buf = item?;
@@ -158,7 +159,7 @@ mod udp {
async fn recv(
mut stdout: impl Sink<Vec<u8>, Error = io::Error> + Unpin,
- reader: &mut UdpSocketRecvHalf,
+ reader: &mut RecvHalf,
) -> Result<(), io::Error> {
loop {
let mut buf = vec![0; 1024];
diff --git a/tokio/src/net/tcp/mod.rs b/tokio/src/net/tcp/mod.rs
index e3acf542..9ad88424 100644
--- a/tokio/src/net/tcp/mod.rs
+++ b/tokio/src/net/tcp/mod.rs
@@ -16,12 +16,13 @@
//! [`TcpListener`]: struct.TcpListener.html
mod listener;
-pub use self::listener::TcpListener;
+pub use listener::TcpListener;
mod incoming;
-pub use self::incoming::Incoming;
+pub use incoming::Incoming;
-pub mod split;
+mod split;
+pub use split::{ReadHalf, WriteHalf};
mod stream;
-pub use self::stream::TcpStream;
+pub use stream::TcpStream;
diff --git a/tokio/src/net/udp/mod.rs b/tokio/src/net/udp/mod.rs
index 45656773..b4d3ea46 100644
--- a/tokio/src/net/udp/mod.rs
+++ b/tokio/src/net/udp/mod.rs
@@ -8,6 +8,7 @@
//! [`UdpSocket`]: struct.UdpSocket
mod socket;
-pub mod split;
+pub use socket::UdpSocket;
-pub use self::socket::UdpSocket;
+mod split;
+pub use split::{RecvHalf, SendHalf, ReuniteError};
diff --git a/tokio/src/net/udp/socket.rs b/tokio/src/net/udp/socket.rs
index 08509014..41768f1f 100644
--- a/tokio/src/net/udp/socket.rs
+++ b/tokio/src/net/udp/socket.rs
@@ -1,6 +1,6 @@
use crate::future::poll_fn;
use crate::io::PollEvented;
-use crate::net::udp::split::{split, UdpSocketRecvHalf, UdpSocketSendHalf};
+use crate::net::udp::split::{split, RecvHalf, SendHalf};
use crate::net::ToSocketAddrs;
use std::convert::TryFrom;
@@ -67,7 +67,7 @@ impl UdpSocket {
///
/// See the module level documenation of [`split`](super::split) for more
/// details.
- pub fn split(self) -> (UdpSocketRecvHalf, UdpSocketSendHalf) {
+ pub fn split(self) -> (RecvHalf, SendHalf) {
split(self)
}
diff --git a/tokio/src/net/udp/split.rs b/tokio/src/net/udp/split.rs
index 55ca082d..55542cb6 100644
--- a/tokio/src/net/udp/split.rs
+++ b/tokio/src/net/udp/split.rs
@@ -26,26 +26,26 @@ use std::sync::Arc;
/// Use [`send_to`](#method.send_to) or [`send`](#method.send) to send
/// datagrams.
#[derive(Debug)]
-pub struct UdpSocketSendHalf(Arc<UdpSocket>);
+pub struct SendHalf(Arc<UdpSocket>);
/// The recv half after [`split`](super::UdpSocket::split).
///
/// Use [`recv_from`](#method.recv_from) or [`recv`](#method.recv) to receive
/// datagrams.
#[derive(Debug)]
-pub struct UdpSocketRecvHalf(Arc<UdpSocket>);
+pub struct RecvHalf(Arc<UdpSocket>);
-pub(crate) fn split(socket: UdpSocket) -> (UdpSocketRecvHalf, UdpSocketSendHalf) {
+pub(crate) fn split(socket: UdpSocket) -> (RecvHalf, SendHalf) {
let shared = Arc::new(socket);
let send = shared.clone();
let recv = shared;
- (UdpSocketRecvHalf(recv), UdpSocketSendHalf(send))
+ (RecvHalf(recv), SendHalf(send))
}
/// Error indicating two halves were not from the same socket, and thus could
/// not be `reunite`d.
#[derive(Debug)]
-pub struct ReuniteError(pub UdpSocketSendHalf, pub UdpSocketRecvHalf);
+pub struct ReuniteError(pub SendHalf, pub RecvHalf);
impl fmt::Display for ReuniteError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -58,7 +58,7 @@ impl fmt::Display for ReuniteError {
impl Error for ReuniteError {}
-fn reunite(s: UdpSocketSendHalf, r: UdpSocketRecvHalf) -> Result<UdpSocket, ReuniteError> {
+fn reunite(s: SendHalf, r: RecvHalf) -> Result<UdpSocket, ReuniteError> {
if Arc::ptr_eq(&s.0, &r.0) {
drop(r);
// Only two instances of the `Arc` are ever created, one for the
@@ -71,11 +71,11 @@ fn reunite(s: UdpSocketSendHalf, r: UdpSocketRecvHalf) -> Result<UdpSocket, Reun
}
}
-impl UdpSocketRecvHalf {
+impl RecvHalf {
/// Attempts to put the two "halves" of a `UdpSocket` back together and
/// recover the original socket. Succeeds only if the two "halves"
/// originated from the same call to `UdpSocket::split`.
- pub fn reunite(self, other: UdpSocketSendHalf) -> Result<UdpSocket, ReuniteError> {
+ pub fn reunite(self, other: SendHalf) -> Result<UdpSocket, ReuniteError> {
reunite(other, self)
}
@@ -106,11 +106,11 @@ impl UdpSocketRecvHalf {
}
}
-impl UdpSocketSendHalf {
+impl SendHalf {
/// Attempts to put the two "halves" of a `UdpSocket` back together and
/// recover the original socket. Succeeds only if the two "halves"
/// originated from the same call to `UdpSocket::split`.
- pub fn reunite(self, other: UdpSocketRecvHalf) -> Result<UdpSocket, ReuniteError> {
+ pub fn reunite(self, other: RecvHalf) -> Result<UdpSocket, ReuniteError> {
reunite(self, other)
}
@@ -135,13 +135,13 @@ impl UdpSocketSendHalf {
}
}
-impl AsRef<UdpSocket> for UdpSocketSendHalf {
+impl AsRef<UdpSocket> for SendHalf {
fn as_ref(&self) -> &UdpSocket {
&self.0
}
}
-impl AsRef<UdpSocket> for UdpSocketRecvHalf {
+impl AsRef<UdpSocket> for RecvHalf {
fn as_ref(&self) -> &UdpSocket {
&self.0
}
diff --git a/tokio/src/net/unix/mod.rs b/tokio/src/net/unix/mod.rs
index 977e3a0f..1ec6fa8e 100644
--- a/tokio/src/net/unix/mod.rs
+++ b/tokio/src/net/unix/mod.rs
@@ -3,18 +3,19 @@
//! This crate provides APIs for using Unix Domain Sockets with Tokio.
mod datagram;
-pub use self::datagram::UnixDatagram;
+pub use datagram::UnixDatagram;
mod incoming;
-pub use self::incoming::Incoming;
+pub use incoming::Incoming;
mod listener;
-pub use self::listener::UnixListener;
+pub use listener::UnixListener;
-pub mod split;
+mod split;
+pub use split::{ReadHalf, WriteHalf};
mod stream;
-pub use self::stream::UnixStream;
+pub use stream::UnixStream;
mod ucred;
-pub use self::ucred::UCred;
+pub use ucred::UCred;