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:
parent
efd13d5a13
commit
b5a575966f
3 changed files with 15 additions and 18 deletions
|
@ -7,8 +7,7 @@ use encoding::EncoderTrap;
|
||||||
use encoding::label::encoding_from_whatwg_label;
|
use encoding::label::encoding_from_whatwg_label;
|
||||||
use futures::{Async, Poll, Future, Sink, StartSend, Stream};
|
use futures::{Async, Poll, Future, Sink, StartSend, Stream};
|
||||||
use native_tls::{Certificate, TlsConnector, Pkcs12};
|
use native_tls::{Certificate, TlsConnector, Pkcs12};
|
||||||
use tokio_core::reactor::Handle;
|
use tokio::net::{ConnectFuture, TcpStream};
|
||||||
use tokio_core::net::{TcpStream, TcpStreamNew};
|
|
||||||
use tokio_io::AsyncRead;
|
use tokio_io::AsyncRead;
|
||||||
use tokio_mockstream::MockStream;
|
use tokio_mockstream::MockStream;
|
||||||
use tokio_tls::{TlsConnectorExt, TlsStream};
|
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`.
|
/// A future representing an eventual `Connection`.
|
||||||
pub enum ConnectionFuture<'a> {
|
pub enum ConnectionFuture<'a> {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
Unsecured(&'a Config, TcpStreamNew),
|
Unsecured(&'a Config, ConnectFuture),
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
Secured(&'a Config, TlsFuture),
|
Secured(&'a Config, TlsFuture),
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
@ -120,7 +119,7 @@ impl<'a> Future for ConnectionFuture<'a> {
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
/// Creates a new `Connection` using the specified `Config` and `Handle`.
|
/// 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() {
|
if config.use_mock_connection() {
|
||||||
Ok(ConnectionFuture::Mock(config))
|
Ok(ConnectionFuture::Mock(config))
|
||||||
} else if config.use_ssl() {
|
} else if config.use_ssl() {
|
||||||
|
@ -145,7 +144,7 @@ impl Connection {
|
||||||
info!("Using {} for client certificate authentication.", client_cert_path);
|
info!("Using {} for client certificate authentication.", client_cert_path);
|
||||||
}
|
}
|
||||||
let connector = builder.build()?;
|
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();
|
let res: error::IrcError = e.into();
|
||||||
res
|
res
|
||||||
}).and_then(move |socket| {
|
}).and_then(move |socket| {
|
||||||
|
@ -158,7 +157,7 @@ impl Connection {
|
||||||
info!("Connecting to {}.", config.server()?);
|
info!("Connecting to {}.", config.server()?);
|
||||||
Ok(ConnectionFuture::Unsecured(
|
Ok(ConnectionFuture::Unsecured(
|
||||||
config,
|
config,
|
||||||
TcpStream::connect(&config.socket_addr()?, handle),
|
TcpStream::connect(&config.socket_addr()?),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ use futures::stream::SplitStream;
|
||||||
use futures::sync::mpsc;
|
use futures::sync::mpsc;
|
||||||
use futures::sync::oneshot;
|
use futures::sync::oneshot;
|
||||||
use futures::sync::mpsc::{UnboundedReceiver, UnboundedSender};
|
use futures::sync::mpsc::{UnboundedReceiver, UnboundedSender};
|
||||||
use tokio_core::reactor::{Core, Handle};
|
use tokio_core::reactor::Core;
|
||||||
|
|
||||||
use error;
|
use error;
|
||||||
use client::conn::{Connection, ConnectionFuture};
|
use client::conn::{Connection, ConnectionFuture};
|
||||||
|
@ -754,8 +754,7 @@ impl IrcClient {
|
||||||
// will instead panic.
|
// will instead panic.
|
||||||
let _ = thread::spawn(move || {
|
let _ = thread::spawn(move || {
|
||||||
let mut reactor = Core::new().unwrap();
|
let mut reactor = Core::new().unwrap();
|
||||||
let handle = reactor.handle();
|
let conn = reactor.run(Connection::new(&cfg).unwrap()).unwrap();
|
||||||
let conn = reactor.run(Connection::new(&cfg, &handle).unwrap()).unwrap();
|
|
||||||
|
|
||||||
tx_view.send(conn.log_view()).unwrap();
|
tx_view.send(conn.log_view()).unwrap();
|
||||||
let (sink, stream) = conn.split();
|
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
|
/// Creates a `Future` of an `IrcClient` from the specified configuration.
|
||||||
/// corresponding to the given handle. This can be used to set up a number of `IrcClients` on a
|
/// This can be used to set up a number of `IrcClients` on a single,
|
||||||
/// single, shared event loop. It can also be used to take more control over execution and error
|
/// 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.
|
/// handling. Connection will not occur until the event loop is run.
|
||||||
///
|
///
|
||||||
/// Proper usage requires familiarity with `tokio` and `futures`. You can find more information
|
/// Proper usage requires familiarity with `tokio` and `futures`. You can find more information
|
||||||
|
@ -807,7 +806,7 @@ impl IrcClient {
|
||||||
/// # .. Default::default()
|
/// # .. Default::default()
|
||||||
/// # };
|
/// # };
|
||||||
/// let mut reactor = Core::new().unwrap();
|
/// 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...
|
/// // immediate connection errors (like no internet) will turn up here...
|
||||||
/// let PackedIrcClient(client, future) = reactor.run(future).unwrap();
|
/// let PackedIrcClient(client, future) = reactor.run(future).unwrap();
|
||||||
/// // runtime errors (like disconnections and so forth) will turn up here...
|
/// // 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(()) }
|
/// # 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();
|
let (tx_outgoing, rx_outgoing) = mpsc::unbounded();
|
||||||
|
|
||||||
Ok(IrcClientFuture {
|
Ok(IrcClientFuture {
|
||||||
conn: Connection::new(config, &handle)?,
|
conn: Connection::new(config)?,
|
||||||
_handle: handle, config,
|
config,
|
||||||
tx_outgoing: Some(tx_outgoing),
|
tx_outgoing: Some(tx_outgoing),
|
||||||
rx_outgoing: Some(rx_outgoing),
|
rx_outgoing: Some(rx_outgoing),
|
||||||
})
|
})
|
||||||
|
@ -855,7 +854,6 @@ impl IrcClient {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct IrcClientFuture<'a> {
|
pub struct IrcClientFuture<'a> {
|
||||||
conn: ConnectionFuture<'a>,
|
conn: ConnectionFuture<'a>,
|
||||||
_handle: Handle,
|
|
||||||
config: &'a Config,
|
config: &'a Config,
|
||||||
tx_outgoing: Option<UnboundedSender<Message>>,
|
tx_outgoing: Option<UnboundedSender<Message>>,
|
||||||
rx_outgoing: Option<UnboundedReceiver<Message>>,
|
rx_outgoing: Option<UnboundedReceiver<Message>>,
|
||||||
|
|
|
@ -70,7 +70,7 @@ impl IrcReactor {
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn prepare_client<'a>(&mut self, config: &'a Config) -> error::Result<IrcClientFuture<'a>> {
|
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
|
/// Runs an [`IrcClientFuture`](../struct.IrcClientFuture.html), such as one from
|
||||||
|
|
Loading…
Add table
Reference in a new issue