Partially moved from tokio_core to tokio, removed handle args:

Migrated `conn` and `client` modules to `tokio` types;

Removed `handle` arguments and fields in `reactor`, `conn` and `client` modules;

Removed unused imports of `Handle`, updated doctest.
This commit is contained in:
Ratys 2018-06-08 17:18:59 +03:00
parent efd13d5a13
commit b5a575966f
3 changed files with 15 additions and 18 deletions

View file

@ -7,8 +7,7 @@ use encoding::EncoderTrap;
use encoding::label::encoding_from_whatwg_label;
use futures::{Async, Poll, Future, Sink, StartSend, Stream};
use native_tls::{Certificate, TlsConnector, Pkcs12};
use tokio_core::reactor::Handle;
use tokio_core::net::{TcpStream, TcpStreamNew};
use tokio::net::{ConnectFuture, TcpStream};
use tokio_io::AsyncRead;
use tokio_mockstream::MockStream;
use tokio_tls::{TlsConnectorExt, TlsStream};
@ -48,7 +47,7 @@ type TlsFuture = Box<Future<Error = error::IrcError, Item = TlsStream<TcpStream>
/// A future representing an eventual `Connection`.
pub enum ConnectionFuture<'a> {
#[doc(hidden)]
Unsecured(&'a Config, TcpStreamNew),
Unsecured(&'a Config, ConnectFuture),
#[doc(hidden)]
Secured(&'a Config, TlsFuture),
#[doc(hidden)]
@ -120,7 +119,7 @@ impl<'a> Future for ConnectionFuture<'a> {
impl Connection {
/// Creates a new `Connection` using the specified `Config` and `Handle`.
pub fn new<'a>(config: &'a Config, handle: &Handle) -> error::Result<ConnectionFuture<'a>> {
pub fn new<'a>(config: &'a Config) -> error::Result<ConnectionFuture<'a>> {
if config.use_mock_connection() {
Ok(ConnectionFuture::Mock(config))
} else if config.use_ssl() {
@ -145,7 +144,7 @@ impl Connection {
info!("Using {} for client certificate authentication.", client_cert_path);
}
let connector = builder.build()?;
let stream = Box::new(TcpStream::connect(&config.socket_addr()?, handle).map_err(|e| {
let stream = Box::new(TcpStream::connect(&config.socket_addr()?).map_err(|e| {
let res: error::IrcError = e.into();
res
}).and_then(move |socket| {
@ -158,7 +157,7 @@ impl Connection {
info!("Connecting to {}.", config.server()?);
Ok(ConnectionFuture::Unsecured(
config,
TcpStream::connect(&config.socket_addr()?, handle),
TcpStream::connect(&config.socket_addr()?),
))
}
}

View file

@ -59,7 +59,7 @@ use futures::stream::SplitStream;
use futures::sync::mpsc;
use futures::sync::oneshot;
use futures::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use tokio_core::reactor::{Core, Handle};
use tokio_core::reactor::Core;
use error;
use client::conn::{Connection, ConnectionFuture};
@ -754,8 +754,7 @@ impl IrcClient {
// will instead panic.
let _ = thread::spawn(move || {
let mut reactor = Core::new().unwrap();
let handle = reactor.handle();
let conn = reactor.run(Connection::new(&cfg, &handle).unwrap()).unwrap();
let conn = reactor.run(Connection::new(&cfg).unwrap()).unwrap();
tx_view.send(conn.log_view()).unwrap();
let (sink, stream) = conn.split();
@ -779,9 +778,9 @@ impl IrcClient {
})
}
/// Creates a `Future` of an `IrcClient` from the specified configuration and on the event loop
/// corresponding to the given handle. This can be used to set up a number of `IrcClients` on a
/// single, shared event loop. It can also be used to take more control over execution and error
/// Creates a `Future` of an `IrcClient` from the specified configuration.
/// This can be used to set up a number of `IrcClients` on a single,
/// shared event loop. It can also be used to take more control over execution and error
/// handling. Connection will not occur until the event loop is run.
///
/// Proper usage requires familiarity with `tokio` and `futures`. You can find more information
@ -807,7 +806,7 @@ impl IrcClient {
/// # .. Default::default()
/// # };
/// let mut reactor = Core::new().unwrap();
/// let future = IrcClient::new_future(reactor.handle(), &config).unwrap();
/// let future = IrcClient::new_future(&config).unwrap();
/// // immediate connection errors (like no internet) will turn up here...
/// let PackedIrcClient(client, future) = reactor.run(future).unwrap();
/// // runtime errors (like disconnections and so forth) will turn up here...
@ -818,12 +817,12 @@ impl IrcClient {
/// # }
/// # fn process_msg(server: &IrcClient, message: Message) -> error::Result<()> { Ok(()) }
/// ```
pub fn new_future(handle: Handle, config: &Config) -> error::Result<IrcClientFuture> {
pub fn new_future(config: &Config) -> error::Result<IrcClientFuture> {
let (tx_outgoing, rx_outgoing) = mpsc::unbounded();
Ok(IrcClientFuture {
conn: Connection::new(config, &handle)?,
_handle: handle, config,
conn: Connection::new(config)?,
config,
tx_outgoing: Some(tx_outgoing),
rx_outgoing: Some(rx_outgoing),
})
@ -855,7 +854,6 @@ impl IrcClient {
#[derive(Debug)]
pub struct IrcClientFuture<'a> {
conn: ConnectionFuture<'a>,
_handle: Handle,
config: &'a Config,
tx_outgoing: Option<UnboundedSender<Message>>,
rx_outgoing: Option<UnboundedReceiver<Message>>,

View file

@ -70,7 +70,7 @@ impl IrcReactor {
/// # }
/// ```
pub fn prepare_client<'a>(&mut self, config: &'a Config) -> error::Result<IrcClientFuture<'a>> {
IrcClient::new_future(self.inner_handle(), config)
IrcClient::new_future(config)
}
/// Runs an [`IrcClientFuture`](../struct.IrcClientFuture.html), such as one from