mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
Remove Framed::split
because it's now in futures
This commit is contained in:
parent
4994f762a9
commit
e27abd3841
@ -3,7 +3,6 @@ use std::ops::{Deref, DerefMut};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use futures::{Async, Poll, Stream, Sink, StartSend, AsyncSink};
|
use futures::{Async, Poll, Stream, Sink, StartSend, AsyncSink};
|
||||||
use futures::sync::BiLock;
|
|
||||||
|
|
||||||
use io::Io;
|
use io::Io;
|
||||||
|
|
||||||
@ -246,52 +245,6 @@ pub trait Codec {
|
|||||||
fn encode(&mut self, msg: Self::Out, buf: &mut Vec<u8>);
|
fn encode(&mut self, msg: Self::Out, buf: &mut Vec<u8>);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A `Stream` interface to an underlying `Io` object, using the `Decode` trait
|
|
||||||
/// to decode frames.
|
|
||||||
pub struct FramedRead<T, C> {
|
|
||||||
framed: BiLock<Framed<T, C>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Io, C: Codec> Stream for FramedRead<T, C> {
|
|
||||||
type Item = C::In;
|
|
||||||
type Error = io::Error;
|
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<Option<C::In>, io::Error> {
|
|
||||||
if let Async::Ready(mut guard) = self.framed.poll_lock() {
|
|
||||||
guard.poll()
|
|
||||||
} else {
|
|
||||||
Ok(Async::NotReady)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A `Sink` interface to an underlying `Io` object, using the `Encode` trait
|
|
||||||
/// to encode frames.
|
|
||||||
pub struct FramedWrite<T, C> {
|
|
||||||
framed: BiLock<Framed<T, C>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Io, C: Codec> Sink for FramedWrite<T, C> {
|
|
||||||
type SinkItem = C::Out;
|
|
||||||
type SinkError = io::Error;
|
|
||||||
|
|
||||||
fn start_send(&mut self, item: C::Out) -> StartSend<C::Out, io::Error> {
|
|
||||||
if let Async::Ready(mut guard) = self.framed.poll_lock() {
|
|
||||||
guard.start_send(item)
|
|
||||||
} else {
|
|
||||||
Ok(AsyncSink::NotReady(item))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn poll_complete(&mut self) -> Poll<(), io::Error> {
|
|
||||||
if let Async::Ready(mut guard) = self.framed.poll_lock() {
|
|
||||||
guard.poll_complete()
|
|
||||||
} else {
|
|
||||||
Ok(Async::NotReady)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A unified `Stream` and `Sink` interface to an underlying `Io` object, using
|
/// A unified `Stream` and `Sink` interface to an underlying `Io` object, using
|
||||||
/// the `Encode` and `Decode` traits to encode and decode frames.
|
/// the `Encode` and `Decode` traits to encode and decode frames.
|
||||||
///
|
///
|
||||||
@ -403,16 +356,6 @@ pub fn framed<T, C>(io: T, codec: C) -> Framed<T, C> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T, C> Framed<T, C> {
|
impl<T, C> Framed<T, C> {
|
||||||
/// Splits this `Stream + Sink` object into separate `Stream` and `Sink`
|
|
||||||
/// objects, which can be useful when you want to split ownership between
|
|
||||||
/// tasks, or allow direct interaction between the two objects (e.g. via
|
|
||||||
/// `Sink::send_all`).
|
|
||||||
pub fn split(self) -> (FramedRead<T, C>, FramedWrite<T, C>) {
|
|
||||||
let (a, b) = BiLock::new(self);
|
|
||||||
let read = FramedRead { framed: a };
|
|
||||||
let write = FramedWrite { framed: b };
|
|
||||||
(read, write)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a reference to the underlying I/O stream wrapped by `Framed`.
|
/// Returns a reference to the underlying I/O stream wrapped by `Framed`.
|
||||||
///
|
///
|
||||||
|
@ -42,7 +42,7 @@ mod split;
|
|||||||
mod window;
|
mod window;
|
||||||
mod write_all;
|
mod write_all;
|
||||||
pub use self::copy::{copy, Copy};
|
pub use self::copy::{copy, Copy};
|
||||||
pub use self::frame::{EasyBuf, EasyBufMut, FramedRead, FramedWrite, Framed, Codec};
|
pub use self::frame::{EasyBuf, EasyBufMut, Framed, Codec};
|
||||||
pub use self::flush::{flush, Flush};
|
pub use self::flush::{flush, Flush};
|
||||||
pub use self::read_exact::{read_exact, ReadExact};
|
pub use self::read_exact::{read_exact, ReadExact};
|
||||||
pub use self::read_to_end::{read_to_end, ReadToEnd};
|
pub use self::read_to_end::{read_to_end, ReadToEnd};
|
||||||
|
@ -43,7 +43,7 @@ fn echo() {
|
|||||||
let listener = TcpListener::bind(&"127.0.0.1:0".parse().unwrap(), &handle).unwrap();
|
let listener = TcpListener::bind(&"127.0.0.1:0".parse().unwrap(), &handle).unwrap();
|
||||||
let addr = listener.local_addr().unwrap();
|
let addr = listener.local_addr().unwrap();
|
||||||
let srv = listener.incoming().for_each(move |(socket, _)| {
|
let srv = listener.incoming().for_each(move |(socket, _)| {
|
||||||
let (stream, sink) = socket.framed(LineCodec).split();
|
let (sink, stream) = socket.framed(LineCodec).split();
|
||||||
handle.spawn(sink.send_all(stream).map(|_| ()).map_err(|_| ()));
|
handle.spawn(sink.send_all(stream).map(|_| ()).map_err(|_| ()));
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user