mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-03 00:00:05 +02:00
Remove deprecated code.
This commit removes code that was deprecated in tokio-core master.
This commit is contained in:
committed by
Alex Crichton
parent
36aaaa1520
commit
b23a997cb8
+2
-1
@@ -1,10 +1,11 @@
|
|||||||
#![allow(deprecated)]
|
|
||||||
#![feature(test)]
|
#![feature(test)]
|
||||||
|
|
||||||
extern crate test;
|
extern crate test;
|
||||||
extern crate futures;
|
extern crate futures;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate tokio;
|
extern crate tokio;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate tokio_io;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
extern crate futures;
|
extern crate futures;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate tokio;
|
extern crate tokio;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate tokio_io;
|
||||||
|
|
||||||
use std::{env, io};
|
use std::{env, io};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|||||||
-255
@@ -1,255 +0,0 @@
|
|||||||
//! I/O conveniences when working with primitives in `tokio-core`
|
|
||||||
//!
|
|
||||||
//! Contains various combinators to work with I/O objects and type definitions
|
|
||||||
//! as well.
|
|
||||||
//!
|
|
||||||
//! A description of the high-level I/O combinators can be [found online] in
|
|
||||||
//! addition to a description of the [low level details].
|
|
||||||
//!
|
|
||||||
//! [found online]: https://tokio.rs/docs/getting-started/core/
|
|
||||||
//! [low level details]: https://tokio.rs/docs/going-deeper-tokio/core-low-level/
|
|
||||||
|
|
||||||
#![deprecated(note = "moved to the `tokio-io` crate")]
|
|
||||||
#![allow(deprecated)]
|
|
||||||
|
|
||||||
use std::io;
|
|
||||||
|
|
||||||
use futures::{Async, Poll};
|
|
||||||
use futures::future::BoxFuture;
|
|
||||||
use futures::stream::BoxStream;
|
|
||||||
use iovec::IoVec;
|
|
||||||
|
|
||||||
/// A convenience typedef around a `Future` whose error component is `io::Error`
|
|
||||||
pub type IoFuture<T> = BoxFuture<T, io::Error>;
|
|
||||||
|
|
||||||
/// A convenience typedef around a `Stream` whose error component is `io::Error`
|
|
||||||
pub type IoStream<T> = BoxStream<T, io::Error>;
|
|
||||||
|
|
||||||
/// A convenience macro for working with `io::Result<T>` from the `Read` and
|
|
||||||
/// `Write` traits.
|
|
||||||
///
|
|
||||||
/// This macro takes `io::Result<T>` as input, and returns `T` as the output. If
|
|
||||||
/// the input type is of the `Err` variant, then `Poll::NotReady` is returned if
|
|
||||||
/// it indicates `WouldBlock` or otherwise `Err` is returned.
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! try_nb {
|
|
||||||
($e:expr) => (match $e {
|
|
||||||
Ok(t) => t,
|
|
||||||
Err(ref e) if e.kind() == ::std::io::ErrorKind::WouldBlock => {
|
|
||||||
return Ok(::futures::Async::NotReady)
|
|
||||||
}
|
|
||||||
Err(e) => return Err(e.into()),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
mod copy;
|
|
||||||
mod frame;
|
|
||||||
mod flush;
|
|
||||||
mod read_exact;
|
|
||||||
mod read_to_end;
|
|
||||||
mod read;
|
|
||||||
mod read_until;
|
|
||||||
mod split;
|
|
||||||
mod window;
|
|
||||||
mod write_all;
|
|
||||||
pub use self::copy::{copy, Copy};
|
|
||||||
pub use self::frame::{EasyBuf, EasyBufMut, Framed, Codec};
|
|
||||||
pub use self::flush::{flush, Flush};
|
|
||||||
pub use self::read_exact::{read_exact, ReadExact};
|
|
||||||
pub use self::read_to_end::{read_to_end, ReadToEnd};
|
|
||||||
pub use self::read::{read, Read};
|
|
||||||
pub use self::read_until::{read_until, ReadUntil};
|
|
||||||
pub use self::split::{ReadHalf, WriteHalf};
|
|
||||||
pub use self::window::Window;
|
|
||||||
pub use self::write_all::{write_all, WriteAll};
|
|
||||||
|
|
||||||
/// A trait for read/write I/O objects
|
|
||||||
///
|
|
||||||
/// This trait represents I/O objects which are readable and writable.
|
|
||||||
/// Additionally, they're associated with the ability to test whether they're
|
|
||||||
/// readable or writable.
|
|
||||||
///
|
|
||||||
/// Importantly, the methods of this trait are intended to be used in conjunction
|
|
||||||
/// with the current task of a future. Namely whenever any of them return a
|
|
||||||
/// value that indicates "would block" the current future's task is arranged to
|
|
||||||
/// receive a notification when the method would otherwise not indicate that it
|
|
||||||
/// would block.
|
|
||||||
pub trait Io: io::Read + io::Write {
|
|
||||||
/// Tests to see if this I/O object may be readable.
|
|
||||||
///
|
|
||||||
/// This method returns an `Async<()>` indicating whether the object
|
|
||||||
/// **might** be readable. It is possible that even if this method returns
|
|
||||||
/// `Async::Ready` that a call to `read` would return a `WouldBlock` error.
|
|
||||||
///
|
|
||||||
/// There is a default implementation for this function which always
|
|
||||||
/// indicates that an I/O object is readable, but objects which can
|
|
||||||
/// implement a finer grained version of this are recommended to do so.
|
|
||||||
///
|
|
||||||
/// If this function returns `Async::NotReady` then the current future's
|
|
||||||
/// task is arranged to receive a notification when it might not return
|
|
||||||
/// `NotReady`.
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// This method is likely to panic if called from outside the context of a
|
|
||||||
/// future's task.
|
|
||||||
fn poll_read(&mut self) -> Async<()> {
|
|
||||||
Async::Ready(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Tests to see if this I/O object may be writable.
|
|
||||||
///
|
|
||||||
/// This method returns an `Async<()>` indicating whether the object
|
|
||||||
/// **might** be writable. It is possible that even if this method returns
|
|
||||||
/// `Async::Ready` that a call to `write` would return a `WouldBlock` error.
|
|
||||||
///
|
|
||||||
/// There is a default implementation for this function which always
|
|
||||||
/// indicates that an I/O object is writable, but objects which can
|
|
||||||
/// implement a finer grained version of this are recommended to do so.
|
|
||||||
///
|
|
||||||
/// If this function returns `Async::NotReady` then the current future's
|
|
||||||
/// task is arranged to receive a notification when it might not return
|
|
||||||
/// `NotReady`.
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// This method is likely to panic if called from outside the context of a
|
|
||||||
/// future's task.
|
|
||||||
fn poll_write(&mut self) -> Async<()> {
|
|
||||||
Async::Ready(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Read in a list of buffers all at once.
|
|
||||||
///
|
|
||||||
/// This operation will attempt to read bytes from this socket and place
|
|
||||||
/// them into the list of buffers provided. Note that each buffer is an
|
|
||||||
/// `IoVec` which can be created from a byte slice.
|
|
||||||
///
|
|
||||||
/// The buffers provided will be filled in sequentially. A buffer will be
|
|
||||||
/// entirely filled up before the next is written to.
|
|
||||||
///
|
|
||||||
/// The number of bytes read is returned, if successful, or an error is
|
|
||||||
/// returned otherwise. If no bytes are available to be read yet then
|
|
||||||
/// a "would block" error is returned. This operation should not block.
|
|
||||||
///
|
|
||||||
/// There is a default implementation for this function which treats this
|
|
||||||
/// as a single read using the first buffer in the list, but objects which
|
|
||||||
/// can implement this as an atomic read using all the buffers are
|
|
||||||
/// recommended to do so. For example, `TcpStream` can implement this
|
|
||||||
/// using the `readv` syscall.
|
|
||||||
fn read_vec(&mut self, bufs: &mut [&mut IoVec]) -> io::Result<usize> {
|
|
||||||
if bufs.is_empty() {
|
|
||||||
Ok(0)
|
|
||||||
} else {
|
|
||||||
self.read(&mut bufs[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Write a list of buffers all at once.
|
|
||||||
///
|
|
||||||
/// This operation will attempt to write a list of byte buffers to this
|
|
||||||
/// socket. Note that each buffer is an `IoVec` which can be created from a
|
|
||||||
/// byte slice.
|
|
||||||
///
|
|
||||||
/// The buffers provided will be written sequentially. A buffer will be
|
|
||||||
/// entirely written before the next is written.
|
|
||||||
///
|
|
||||||
/// The number of bytes written is returned, if successful, or an error is
|
|
||||||
/// returned otherwise. If the socket is not currently writable then a
|
|
||||||
/// "would block" error is returned. This operation should not block.
|
|
||||||
///
|
|
||||||
/// There is a default implementation for this function which writes the
|
|
||||||
/// first buffer only, but objects which can implement this as an atomic
|
|
||||||
/// write using all the buffers are recommended to do so. For example,
|
|
||||||
/// `TcpStream` can implement this using the `writev` syscall.
|
|
||||||
fn write_vec(&mut self, bufs: &[&IoVec]) -> io::Result<usize> {
|
|
||||||
if bufs.is_empty() {
|
|
||||||
Ok(0)
|
|
||||||
} else {
|
|
||||||
self.write(&bufs[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Provides a `Stream` and `Sink` interface for reading and writing to this
|
|
||||||
/// `Io` object, using `Decode` and `Encode` to read and write the raw data.
|
|
||||||
///
|
|
||||||
/// Raw I/O objects work with byte sequences, but higher-level code usually
|
|
||||||
/// wants to batch these into meaningful chunks, called "frames". This
|
|
||||||
/// method layers framing on top of an I/O object, by using the `Codec`
|
|
||||||
/// traits to handle encoding and decoding of messages frames. Note that
|
|
||||||
/// the incoming and outgoing frame types may be distinct.
|
|
||||||
///
|
|
||||||
/// This function returns a *single* object that is both `Stream` and
|
|
||||||
/// `Sink`; grouping this into a single object is often useful for layering
|
|
||||||
/// things like gzip or TLS, which require both read and write access to the
|
|
||||||
/// underlying object.
|
|
||||||
///
|
|
||||||
/// If you want to work more directly with the streams and sink, consider
|
|
||||||
/// calling `split` on the `Framed` returned by this method, which will
|
|
||||||
/// break them into separate objects, allowing them to interact more easily.
|
|
||||||
fn framed<C: Codec>(self, codec: C) -> Framed<Self, C>
|
|
||||||
where Self: Sized,
|
|
||||||
{
|
|
||||||
frame::framed(self, codec)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper method for splitting this read/write object into two halves.
|
|
||||||
///
|
|
||||||
/// The two halves returned implement the `Read` and `Write` traits,
|
|
||||||
/// respectively.
|
|
||||||
fn split(self) -> (ReadHalf<Self>, WriteHalf<Self>)
|
|
||||||
where Self: Sized
|
|
||||||
{
|
|
||||||
split::split(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A trait for framed reading and writing.
|
|
||||||
///
|
|
||||||
/// Most implementations of `FramedIo` are for doing protocol level
|
|
||||||
/// serialization and deserialization.
|
|
||||||
///
|
|
||||||
/// Importantly, the methods of this trait are intended to be used in conjunction
|
|
||||||
/// with the current task of a future. Namely whenever any of them return a
|
|
||||||
/// value that indicates "would block" the current future's task is arranged to
|
|
||||||
/// receive a notification when the method would otherwise not indicate that it
|
|
||||||
/// would block.
|
|
||||||
//
|
|
||||||
/// For a sample implementation of `FramedIo` you can take a look at the
|
|
||||||
/// `Framed` type in the `frame` module of this crate.
|
|
||||||
#[doc(hidden)]
|
|
||||||
#[deprecated(since = "0.1.1", note = "replaced by Sink + Stream")]
|
|
||||||
pub trait FramedIo {
|
|
||||||
/// Messages written
|
|
||||||
type In;
|
|
||||||
|
|
||||||
/// Messages read
|
|
||||||
type Out;
|
|
||||||
|
|
||||||
/// Tests to see if this `FramedIo` may be readable.
|
|
||||||
fn poll_read(&mut self) -> Async<()>;
|
|
||||||
|
|
||||||
/// Read a message frame from the `FramedIo`
|
|
||||||
fn read(&mut self) -> Poll<Self::Out, io::Error>;
|
|
||||||
|
|
||||||
/// Tests to see if this `FramedIo` may be writable.
|
|
||||||
///
|
|
||||||
/// Unlike most other calls to poll readiness, it is important that when
|
|
||||||
/// `FramedIo::poll_write` returns `Async::Ready` that a write will
|
|
||||||
/// succeed.
|
|
||||||
fn poll_write(&mut self) -> Async<()>;
|
|
||||||
|
|
||||||
/// Write a message frame to the `FramedIo`
|
|
||||||
fn write(&mut self, req: Self::In) -> Poll<(), io::Error>;
|
|
||||||
|
|
||||||
/// Flush pending writes or do any other work not driven by reading /
|
|
||||||
/// writing.
|
|
||||||
///
|
|
||||||
/// Since the backing source is non-blocking, there is no guarantee that a
|
|
||||||
/// call to `FramedIo::write` is able to write the full message to the
|
|
||||||
/// backing source immediately. In this case, the `FramedIo` will need to
|
|
||||||
/// buffer the remaining data to write. Calls to `FramedIo:flush` attempt
|
|
||||||
/// to write any remaining data in the write buffer to the underlying
|
|
||||||
/// source.
|
|
||||||
fn flush(&mut self) -> Poll<(), io::Error>;
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
use std::io::{self, Read, Write};
|
|
||||||
|
|
||||||
use futures::Async;
|
|
||||||
use futures::sync::BiLock;
|
|
||||||
|
|
||||||
use io::Io;
|
|
||||||
|
|
||||||
/// The readable half of an object returned from `Io::split`.
|
|
||||||
pub struct ReadHalf<T> {
|
|
||||||
handle: BiLock<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The writable half of an object returned from `Io::split`.
|
|
||||||
pub struct WriteHalf<T> {
|
|
||||||
handle: BiLock<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn split<T: Io>(t: T) -> (ReadHalf<T>, WriteHalf<T>) {
|
|
||||||
let (a, b) = BiLock::new(t);
|
|
||||||
(ReadHalf { handle: a }, WriteHalf { handle: b })
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Io> ReadHalf<T> {
|
|
||||||
/// Calls the underlying `poll_read` function on this handling, testing to
|
|
||||||
/// see if it's ready to be read from.
|
|
||||||
pub fn poll_read(&mut self) -> Async<()> {
|
|
||||||
match self.handle.poll_lock() {
|
|
||||||
Async::Ready(mut l) => l.poll_read(),
|
|
||||||
Async::NotReady => Async::NotReady,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Io> WriteHalf<T> {
|
|
||||||
/// Calls the underlying `poll_write` function on this handling, testing to
|
|
||||||
/// see if it's ready to be written to.
|
|
||||||
pub fn poll_write(&mut self) -> Async<()> {
|
|
||||||
match self.handle.poll_lock() {
|
|
||||||
Async::Ready(mut l) => l.poll_write(),
|
|
||||||
Async::NotReady => Async::NotReady,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Read> Read for ReadHalf<T> {
|
|
||||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
|
||||||
match self.handle.poll_lock() {
|
|
||||||
Async::Ready(mut l) => l.read(buf),
|
|
||||||
Async::NotReady => Err(io::ErrorKind::WouldBlock.into()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Write> Write for WriteHalf<T> {
|
|
||||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
|
||||||
match self.handle.poll_lock() {
|
|
||||||
Async::Ready(mut l) => l.write(buf),
|
|
||||||
Async::NotReady => Err(io::ErrorKind::WouldBlock.into()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn flush(&mut self) -> io::Result<()> {
|
|
||||||
match self.handle.poll_lock() {
|
|
||||||
Async::Ready(mut l) => l.flush(),
|
|
||||||
Async::NotReady => Err(io::ErrorKind::WouldBlock.into()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
use std::ops;
|
|
||||||
|
|
||||||
/// A owned window around an underlying buffer.
|
|
||||||
///
|
|
||||||
/// Normally slices work great for considering sub-portions of a buffer, but
|
|
||||||
/// unfortunately a slice is a *borrowed* type in Rust which has an associated
|
|
||||||
/// lifetime. When working with future and async I/O these lifetimes are not
|
|
||||||
/// always appropriate, and are sometimes difficult to store in tasks. This
|
|
||||||
/// type strives to fill this gap by providing an "owned slice" around an
|
|
||||||
/// underlying buffer of bytes.
|
|
||||||
///
|
|
||||||
/// A `Window<T>` wraps an underlying buffer, `T`, and has configurable
|
|
||||||
/// start/end indexes to alter the behavior of the `AsRef<[u8]>` implementation
|
|
||||||
/// that this type carries.
|
|
||||||
///
|
|
||||||
/// This type can be particularly useful when working with the `write_all`
|
|
||||||
/// combinator in this crate. Data can be sliced via `Window`, consumed by
|
|
||||||
/// `write_all`, and then earned back once the write operation finishes through
|
|
||||||
/// the `into_inner` method on this type.
|
|
||||||
pub struct Window<T> {
|
|
||||||
inner: T,
|
|
||||||
range: ops::Range<usize>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: AsRef<[u8]>> Window<T> {
|
|
||||||
/// Creates a new window around the buffer `t` defaulting to the entire
|
|
||||||
/// slice.
|
|
||||||
///
|
|
||||||
/// Further methods can be called on the returned `Window<T>` to alter the
|
|
||||||
/// window into the data provided.
|
|
||||||
pub fn new(t: T) -> Window<T> {
|
|
||||||
Window {
|
|
||||||
range: 0..t.as_ref().len(),
|
|
||||||
inner: t,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets a shared reference to the underlying buffer inside of this
|
|
||||||
/// `Window`.
|
|
||||||
pub fn get_ref(&self) -> &T {
|
|
||||||
&self.inner
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets a mutable reference to the underlying buffer inside of this
|
|
||||||
/// `Window`.
|
|
||||||
pub fn get_mut(&mut self) -> &mut T {
|
|
||||||
&mut self.inner
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Consumes this `Window`, returning the underlying buffer.
|
|
||||||
pub fn into_inner(self) -> T {
|
|
||||||
self.inner
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the starting index of this window into the underlying buffer
|
|
||||||
/// `T`.
|
|
||||||
pub fn start(&self) -> usize {
|
|
||||||
self.range.start
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the end index of this window into the underlying buffer
|
|
||||||
/// `T`.
|
|
||||||
pub fn end(&self) -> usize {
|
|
||||||
self.range.end
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Changes the starting index of this window to the index specified.
|
|
||||||
///
|
|
||||||
/// Returns the windows back to chain multiple calls to this method.
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// This method will panic if `start` is out of bounds for the underlying
|
|
||||||
/// slice or if it comes after the `end` configured in this window.
|
|
||||||
pub fn set_start(&mut self, start: usize) -> &mut Window<T> {
|
|
||||||
assert!(start <= self.inner.as_ref().len());
|
|
||||||
assert!(start <= self.range.end);
|
|
||||||
self.range.start = start;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Changes the end index of this window to the index specified.
|
|
||||||
///
|
|
||||||
/// Returns the windows back to chain multiple calls to this method.
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// This method will panic if `end` is out of bounds for the underlying
|
|
||||||
/// slice or if it comes before the `start` configured in this window.
|
|
||||||
pub fn set_end(&mut self, end: usize) -> &mut Window<T> {
|
|
||||||
assert!(end <= self.inner.as_ref().len());
|
|
||||||
assert!(self.range.start <= end);
|
|
||||||
self.range.end = end;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: how about a generic set() method along the lines of:
|
|
||||||
//
|
|
||||||
// buffer.set(..3)
|
|
||||||
// .set(0..2)
|
|
||||||
// .set(4..)
|
|
||||||
//
|
|
||||||
// etc.
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: AsRef<[u8]>> AsRef<[u8]> for Window<T> {
|
|
||||||
fn as_ref(&self) -> &[u8] {
|
|
||||||
&self.inner.as_ref()[self.range.start..self.range.end]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: AsMut<[u8]>> AsMut<[u8]> for Window<T> {
|
|
||||||
fn as_mut(&mut self) -> &mut [u8] {
|
|
||||||
&mut self.inner.as_mut()[self.range.start..self.range.end]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-6
@@ -100,6 +100,7 @@ extern crate futures;
|
|||||||
extern crate iovec;
|
extern crate iovec;
|
||||||
extern crate mio;
|
extern crate mio;
|
||||||
extern crate slab;
|
extern crate slab;
|
||||||
|
#[macro_use]
|
||||||
extern crate tokio_io;
|
extern crate tokio_io;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@@ -108,12 +109,6 @@ extern crate scoped_tls;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub mod io;
|
|
||||||
|
|
||||||
mod heap;
|
mod heap;
|
||||||
#[doc(hidden)]
|
|
||||||
pub mod channel;
|
|
||||||
pub mod net;
|
pub mod net;
|
||||||
pub mod reactor;
|
pub mod reactor;
|
||||||
|
|||||||
@@ -481,20 +481,6 @@ impl TcpStream {
|
|||||||
pub fn linger(&self) -> io::Result<Option<Duration>> {
|
pub fn linger(&self) -> io::Result<Option<Duration>> {
|
||||||
self.io.get_ref().linger()
|
self.io.get_ref().linger()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deprecated(since = "0.1.8", note = "use set_keepalive")]
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub fn set_keepalive_ms(&self, keepalive: Option<u32>) -> io::Result<()> {
|
|
||||||
#[allow(deprecated)]
|
|
||||||
self.io.get_ref().set_keepalive_ms(keepalive)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deprecated(since = "0.1.8", note = "use keepalive")]
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub fn keepalive_ms(&self) -> io::Result<Option<u32>> {
|
|
||||||
#[allow(deprecated)]
|
|
||||||
self.io.get_ref().keepalive_ms()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Read for TcpStream {
|
impl Read for TcpStream {
|
||||||
@@ -532,46 +518,6 @@ impl AsyncWrite for TcpStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl ::io::Io for TcpStream {
|
|
||||||
fn poll_read(&mut self) -> Async<()> {
|
|
||||||
<TcpStream>::poll_read(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn poll_write(&mut self) -> Async<()> {
|
|
||||||
<TcpStream>::poll_write(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_vec(&mut self, bufs: &mut [&mut IoVec]) -> io::Result<usize> {
|
|
||||||
if let Async::NotReady = <TcpStream>::poll_read(self) {
|
|
||||||
return Err(io::ErrorKind::WouldBlock.into())
|
|
||||||
}
|
|
||||||
let r = self.io.get_ref().read_bufs(bufs);
|
|
||||||
if is_wouldblock(&r) {
|
|
||||||
self.io.need_read();
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
fn write_vec(&mut self, bufs: &[&IoVec]) -> io::Result<usize> {
|
|
||||||
if let Async::NotReady = <TcpStream>::poll_write(self) {
|
|
||||||
return Err(io::ErrorKind::WouldBlock.into())
|
|
||||||
}
|
|
||||||
let r = self.io.get_ref().write_bufs(bufs);
|
|
||||||
if is_wouldblock(&r) {
|
|
||||||
self.io.need_write();
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_wouldblock<T>(r: &io::Result<T>) -> bool {
|
|
||||||
match *r {
|
|
||||||
Ok(_) => false,
|
|
||||||
Err(ref e) => e.kind() == io::ErrorKind::WouldBlock,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Read for &'a TcpStream {
|
impl<'a> Read for &'a TcpStream {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||||
(&self.io).read(buf)
|
(&self.io).read(buf)
|
||||||
@@ -679,17 +625,6 @@ impl<'a> AsyncWrite for &'a TcpStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl<'a> ::io::Io for &'a TcpStream {
|
|
||||||
fn poll_read(&mut self) -> Async<()> {
|
|
||||||
<TcpStream>::poll_read(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn poll_write(&mut self) -> Async<()> {
|
|
||||||
<TcpStream>::poll_write(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for TcpStream {
|
impl fmt::Debug for TcpStream {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
self.io.get_ref().fmt(f)
|
self.io.get_ref().fmt(f)
|
||||||
|
|||||||
@@ -317,17 +317,6 @@ impl<E: Write> AsyncWrite for PollEvented<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl<E: Read + Write> ::io::Io for PollEvented<E> {
|
|
||||||
fn poll_read(&mut self) -> Async<()> {
|
|
||||||
<PollEvented<E>>::poll_read(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn poll_write(&mut self) -> Async<()> {
|
|
||||||
<PollEvented<E>>::poll_write(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, E> Read for &'a PollEvented<E>
|
impl<'a, E> Read for &'a PollEvented<E>
|
||||||
where &'a E: Read,
|
where &'a E: Read,
|
||||||
{
|
{
|
||||||
@@ -382,19 +371,6 @@ impl<'a, E> AsyncWrite for &'a PollEvented<E>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl<'a, E> ::io::Io for &'a PollEvented<E>
|
|
||||||
where &'a E: Read + Write,
|
|
||||||
{
|
|
||||||
fn poll_read(&mut self) -> Async<()> {
|
|
||||||
<PollEvented<E>>::poll_read(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn poll_write(&mut self) -> Async<()> {
|
|
||||||
<PollEvented<E>>::poll_write(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_wouldblock<T>(r: &io::Result<T>) -> bool {
|
fn is_wouldblock<T>(r: &io::Result<T>) -> bool {
|
||||||
match *r {
|
match *r {
|
||||||
Ok(_) => false,
|
Ok(_) => false,
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
extern crate futures;
|
extern crate futures;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate tokio;
|
extern crate tokio;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate tokio_io;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|||||||
Reference in New Issue
Block a user