mirror of https://github.com/fafhrd91/actix-net
Merge branch 'std-future-server-config' into std-future-server-ssl
This commit is contained in:
commit
f2502c8a6c
|
@ -14,10 +14,10 @@ name = "actix_server_config"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
features = ["ssl", "rust-tls", "uds"]
|
features = ["ssl", "rust-tls"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["ssl", "rustls" ]
|
default = []
|
||||||
|
|
||||||
# openssl
|
# openssl
|
||||||
ssl = ["tokio-openssl"]
|
ssl = ["tokio-openssl"]
|
||||||
|
@ -25,15 +25,13 @@ ssl = ["tokio-openssl"]
|
||||||
# rustls
|
# rustls
|
||||||
rust-tls = ["rustls", "tokio-rustls"]
|
rust-tls = ["rustls", "tokio-rustls"]
|
||||||
|
|
||||||
# unix domain sockets
|
|
||||||
# TODO: FIXME
|
|
||||||
uds = [] # ["tokio-uds"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures = { package = "futures-preview", version = "0.3.0-alpha.18" }
|
futures = "0.3.1"
|
||||||
tokio = "0.2.0-alpha.4"
|
tokio = "0.2.0-alpha.6"
|
||||||
|
|
||||||
tokio-openssl = { version="0.4.0-alpha.4", optional = true }
|
# openssl
|
||||||
|
tokio-openssl = { version = "0.4.0-alpha.6", optional = true }
|
||||||
|
|
||||||
|
# rustls
|
||||||
rustls = { version = "0.16.0", optional = true }
|
rustls = { version = "0.16.0", optional = true }
|
||||||
tokio-rustls = { version = "0.12.0-alpha.2", optional = true }
|
tokio-rustls = { version = "0.12.0-alpha.8", optional = true }
|
||||||
#tokio-uds = { version="0.3.0-alpha.1", optional = true }
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
|
//! Actix server config utils.
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::{fmt, io, net, time};
|
use std::{fmt, io, net, ops, time};
|
||||||
|
|
||||||
use tokio::io::{AsyncRead, AsyncWrite};
|
use tokio::io::{AsyncRead, AsyncWrite};
|
||||||
use tokio::net::tcp::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ServerConfig {
|
pub struct ServerConfig {
|
||||||
|
@ -13,6 +15,7 @@ pub struct ServerConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServerConfig {
|
impl ServerConfig {
|
||||||
|
#[inline]
|
||||||
pub fn new(addr: SocketAddr) -> Self {
|
pub fn new(addr: SocketAddr) -> Self {
|
||||||
ServerConfig {
|
ServerConfig {
|
||||||
addr,
|
addr,
|
||||||
|
@ -21,16 +24,19 @@ impl ServerConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the address of the local half of this TCP server socket
|
/// Returns the address of the local half of this TCP server socket
|
||||||
|
#[inline]
|
||||||
pub fn local_addr(&self) -> SocketAddr {
|
pub fn local_addr(&self) -> SocketAddr {
|
||||||
self.addr
|
self.addr
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if connection is secure (tls enabled)
|
/// Returns true if connection is secure (tls enabled)
|
||||||
|
#[inline]
|
||||||
pub fn secure(&self) -> bool {
|
pub fn secure(&self) -> bool {
|
||||||
self.secure.as_ref().get()
|
self.secure.as_ref().get()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set secure flag
|
/// Set secure flag
|
||||||
|
#[inline]
|
||||||
pub fn set_secure(&self) {
|
pub fn set_secure(&self) {
|
||||||
self.secure.as_ref().set(true)
|
self.secure.as_ref().set(true)
|
||||||
}
|
}
|
||||||
|
@ -114,7 +120,7 @@ impl<T, P> Io<T, P> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, P> std::ops::Deref for Io<T, P> {
|
impl<T, P> ops::Deref for Io<T, P> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
|
|
||||||
fn deref(&self) -> &T {
|
fn deref(&self) -> &T {
|
||||||
|
@ -122,14 +128,14 @@ impl<T, P> std::ops::Deref for Io<T, P> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, P> std::ops::DerefMut for Io<T, P> {
|
impl<T, P> ops::DerefMut for Io<T, P> {
|
||||||
fn deref_mut(&mut self) -> &mut T {
|
fn deref_mut(&mut self) -> &mut T {
|
||||||
&mut self.io
|
&mut self.io
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: fmt::Debug, P> fmt::Debug for Io<T, P> {
|
impl<T: fmt::Debug, P> fmt::Debug for Io<T, P> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "Io {{{:?}}}", self.io)
|
write!(f, "Io {{{:?}}}", self.io)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,7 +177,7 @@ impl IoStream for TcpStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "ssl"))]
|
#[cfg(feature = "ssl")]
|
||||||
impl<T: IoStream + Unpin> IoStream for tokio_openssl::SslStream<T> {
|
impl<T: IoStream + Unpin> IoStream for tokio_openssl::SslStream<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn peer_addr(&self) -> Option<net::SocketAddr> {
|
fn peer_addr(&self) -> Option<net::SocketAddr> {
|
||||||
|
@ -194,8 +200,8 @@ impl<T: IoStream + Unpin> IoStream for tokio_openssl::SslStream<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "rust-tls"))]
|
#[cfg(feature = "rust-tls")]
|
||||||
impl<T: IoStream> IoStream for tokio_rustls::server::TlsStream<T> {
|
impl<T: IoStream + Unpin> IoStream for tokio_rustls::server::TlsStream<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn peer_addr(&self) -> Option<net::SocketAddr> {
|
fn peer_addr(&self) -> Option<net::SocketAddr> {
|
||||||
self.get_ref().0.peer_addr()
|
self.get_ref().0.peer_addr()
|
||||||
|
@ -217,8 +223,8 @@ impl<T: IoStream> IoStream for tokio_rustls::server::TlsStream<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "uds"))]
|
#[cfg(unix)]
|
||||||
impl IoStream for t::UnixStream {
|
impl IoStream for tokio::net::UnixStream {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn peer_addr(&self) -> Option<net::SocketAddr> {
|
fn peer_addr(&self) -> Option<net::SocketAddr> {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Reference in New Issue