mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-27 18:02:58 +01:00
add Debug impl for Io; update examples
This commit is contained in:
parent
9887aef6e8
commit
1bf0f1e1a5
@ -1,4 +1,5 @@
|
|||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
use std::fmt;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
@ -63,22 +64,27 @@ impl<T> Io<T, ()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T, P> Io<T, P> {
|
impl<T, P> Io<T, P> {
|
||||||
|
/// Reconstruct from a parts.
|
||||||
pub fn from_parts(io: T, params: P, proto: Protocol) -> Self {
|
pub fn from_parts(io: T, params: P, proto: Protocol) -> Self {
|
||||||
Self { io, params, proto }
|
Self { io, params, proto }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Deconstruct into a parts.
|
||||||
pub fn into_parts(self) -> (T, P, Protocol) {
|
pub fn into_parts(self) -> (T, P, Protocol) {
|
||||||
(self.io, self.params, self.proto)
|
(self.io, self.params, self.proto)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn io(&self) -> &T {
|
/// Returns a shared reference to the underlying stream.
|
||||||
|
pub fn get_ref(&self) -> &T {
|
||||||
&self.io
|
&self.io
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn io_mut(&mut self) -> &mut T {
|
/// Returns a mutable reference to the underlying stream.
|
||||||
|
pub fn get_mut(&mut self) -> &mut T {
|
||||||
&mut self.io
|
&mut self.io
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get selected protocol
|
||||||
pub fn protocol(&self) -> Protocol {
|
pub fn protocol(&self) -> Protocol {
|
||||||
self.proto
|
self.proto
|
||||||
}
|
}
|
||||||
@ -95,3 +101,9 @@ impl<T, P> Io<T, P> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: fmt::Debug, P> fmt::Debug for Io<T, P> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "Io {{{:?}}}", self.io)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -102,7 +102,7 @@ fn test_start() {
|
|||||||
let _ = srv.pause();
|
let _ = srv.pause();
|
||||||
thread::sleep(time::Duration::from_millis(100));
|
thread::sleep(time::Duration::from_millis(100));
|
||||||
assert!(net::TcpStream::connect_timeout(&addr, time::Duration::from_millis(100)).is_ok());
|
assert!(net::TcpStream::connect_timeout(&addr, time::Duration::from_millis(100)).is_ok());
|
||||||
thread::sleep(time::Duration::from_millis(100));
|
thread::sleep(time::Duration::from_millis(400));
|
||||||
assert!(net::TcpStream::connect_timeout(&addr, time::Duration::from_millis(100)).is_err());
|
assert!(net::TcpStream::connect_timeout(&addr, time::Duration::from_millis(100)).is_err());
|
||||||
|
|
||||||
// resume
|
// resume
|
||||||
|
@ -9,7 +9,7 @@ use std::{env, fmt, io};
|
|||||||
|
|
||||||
use actix_codec::{AsyncRead, AsyncWrite};
|
use actix_codec::{AsyncRead, AsyncWrite};
|
||||||
use actix_rt::System;
|
use actix_rt::System;
|
||||||
use actix_server::Server;
|
use actix_server::{Io, Server};
|
||||||
use actix_service::{fn_service, NewService};
|
use actix_service::{fn_service, NewService};
|
||||||
use futures::{future, Future};
|
use futures::{future, Future};
|
||||||
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
||||||
@ -54,8 +54,8 @@ fn main() -> io::Result<()> {
|
|||||||
let acceptor = acceptor.clone();
|
let acceptor = acceptor.clone();
|
||||||
|
|
||||||
// service for converting incoming TcpStream to a SslStream<TcpStream>
|
// service for converting incoming TcpStream to a SslStream<TcpStream>
|
||||||
fn_service(move |stream: tokio_tcp::TcpStream| {
|
fn_service(move |stream: Io<tokio_tcp::TcpStream>| {
|
||||||
SslAcceptorExt::accept_async(&acceptor, stream)
|
SslAcceptorExt::accept_async(&acceptor, stream.into_parts().0)
|
||||||
.map_err(|e| println!("Openssl error: {}", e))
|
.map_err(|e| println!("Openssl error: {}", e))
|
||||||
})
|
})
|
||||||
// .and_then() combinator uses other service to convert incoming `Request` to a
|
// .and_then() combinator uses other service to convert incoming `Request` to a
|
||||||
|
Loading…
Reference in New Issue
Block a user