mirror of
https://github.com/fafhrd91/actix-net
synced 2025-08-14 21:30:32 +02:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
298727dcbd | ||
|
c62567f85f | ||
|
410204a41e |
22
CHANGES.md
22
CHANGES.md
@@ -1,5 +1,27 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.2.5] - 2018-12-12
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fix back-pressure for concurrent ssl handshakes
|
||||||
|
|
||||||
|
* Drop completed future for .then and .and_then combinators
|
||||||
|
|
||||||
|
|
||||||
|
## [0.2.4] - 2018-11-21
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* Allow to skip name resolution stage in Connector
|
||||||
|
|
||||||
|
|
||||||
|
## [0.2.3] - 2018-11-17
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* Framed::is_write_buf_empty() checks if write buffer is flushed
|
||||||
|
|
||||||
## [0.2.2] - 2018-11-14
|
## [0.2.2] - 2018-11-14
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-net"
|
name = "actix-net"
|
||||||
version = "0.2.2"
|
version = "0.2.5"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix net - framework for the compisible network services for Rust (experimental)"
|
description = "Actix net - framework for the compisible network services for Rust (experimental)"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@@ -135,6 +135,11 @@ impl<T, U> Framed<T, U> {
|
|||||||
&mut self.inner.get_mut().get_mut().0
|
&mut self.inner.get_mut().get_mut().0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if write buffer is empty.
|
||||||
|
pub fn is_write_buf_empty(&self) -> bool {
|
||||||
|
self.inner.get_ref().is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
/// Check if write buffer is full.
|
/// Check if write buffer is full.
|
||||||
pub fn is_write_buf_full(&self) -> bool {
|
pub fn is_write_buf_full(&self) -> bool {
|
||||||
self.inner.get_ref().is_full()
|
self.inner.get_ref().is_full()
|
||||||
|
@@ -77,6 +77,11 @@ impl<T, E> FramedWrite<T, E> {
|
|||||||
pub fn is_full(&self) -> bool {
|
pub fn is_full(&self) -> bool {
|
||||||
self.inner.is_full()
|
self.inner.is_full()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if write buffer is empty.
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.inner.is_empty()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> FramedWrite<T, E>
|
impl<T, E> FramedWrite<T, E>
|
||||||
@@ -194,6 +199,10 @@ impl<T> FramedWrite2<T> {
|
|||||||
pub fn is_full(&self) -> bool {
|
pub fn is_full(&self) -> bool {
|
||||||
self.buffer.len() >= self.high_watermark
|
self.buffer.len() >= self.high_watermark
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.buffer.is_empty()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> FramedWrite2<T>
|
impl<T> FramedWrite2<T>
|
||||||
|
@@ -4,10 +4,9 @@ use std::net::{IpAddr, SocketAddr};
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::{fmt, io};
|
use std::{fmt, io};
|
||||||
|
|
||||||
use futures::{
|
use futures::future::{ok, Either, FutureResult};
|
||||||
future::{ok, FutureResult},
|
use futures::{Async, Future, Poll};
|
||||||
Async, Future, Poll,
|
|
||||||
};
|
|
||||||
use tokio_tcp::{ConnectFuture, TcpStream};
|
use tokio_tcp::{ConnectFuture, TcpStream};
|
||||||
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
|
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
|
||||||
use trust_dns_resolver::system_conf::read_system_conf;
|
use trust_dns_resolver::system_conf::read_system_conf;
|
||||||
@@ -58,17 +57,24 @@ impl From<io::Error> for ConnectorError {
|
|||||||
/// Connect request
|
/// Connect request
|
||||||
#[derive(Eq, PartialEq, Debug, Hash)]
|
#[derive(Eq, PartialEq, Debug, Hash)]
|
||||||
pub struct Connect {
|
pub struct Connect {
|
||||||
pub host: String,
|
pub kind: ConnectKind,
|
||||||
pub port: u16,
|
|
||||||
pub timeout: Duration,
|
pub timeout: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Eq, PartialEq, Debug, Hash)]
|
||||||
|
pub enum ConnectKind {
|
||||||
|
Host { host: String, port: u16 },
|
||||||
|
Addr { host: String, addr: SocketAddr },
|
||||||
|
}
|
||||||
|
|
||||||
impl Connect {
|
impl Connect {
|
||||||
/// Create new `Connect` instance.
|
/// Create new `Connect` instance.
|
||||||
pub fn new<T: AsRef<str>>(host: T, port: u16) -> Connect {
|
pub fn new<T: AsRef<str>>(host: T, port: u16) -> Connect {
|
||||||
Connect {
|
Connect {
|
||||||
port,
|
kind: ConnectKind::Host {
|
||||||
host: host.as_ref().to_owned(),
|
host: host.as_ref().to_owned(),
|
||||||
|
port,
|
||||||
|
},
|
||||||
timeout: Duration::from_secs(1),
|
timeout: Duration::from_secs(1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,12 +88,25 @@ impl Connect {
|
|||||||
.parse::<u16>()
|
.parse::<u16>()
|
||||||
.map_err(|_| ConnectorError::InvalidInput)?;
|
.map_err(|_| ConnectorError::InvalidInput)?;
|
||||||
Ok(Connect {
|
Ok(Connect {
|
||||||
port,
|
kind: ConnectKind::Host {
|
||||||
host: host.to_owned(),
|
host: host.to_owned(),
|
||||||
|
port,
|
||||||
|
},
|
||||||
timeout: Duration::from_secs(1),
|
timeout: Duration::from_secs(1),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create new `Connect` instance from host and address. Connector skips name resolution stage for such connect messages.
|
||||||
|
pub fn with_address<T: Into<String>>(host: T, addr: SocketAddr) -> Connect {
|
||||||
|
Connect {
|
||||||
|
kind: ConnectKind::Addr {
|
||||||
|
addr,
|
||||||
|
host: host.into(),
|
||||||
|
},
|
||||||
|
timeout: Duration::from_secs(1),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Set connect timeout
|
/// Set connect timeout
|
||||||
///
|
///
|
||||||
/// By default timeout is set to a 1 second.
|
/// By default timeout is set to a 1 second.
|
||||||
@@ -99,19 +118,25 @@ impl Connect {
|
|||||||
|
|
||||||
impl RequestHost for Connect {
|
impl RequestHost for Connect {
|
||||||
fn host(&self) -> &str {
|
fn host(&self) -> &str {
|
||||||
&self.host
|
match self.kind {
|
||||||
|
ConnectKind::Host { ref host, port: _ } => host,
|
||||||
|
ConnectKind::Addr { ref host, addr: _ } => host,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequestPort for Connect {
|
impl RequestPort for Connect {
|
||||||
fn port(&self) -> u16 {
|
fn port(&self) -> u16 {
|
||||||
self.port
|
match self.kind {
|
||||||
|
ConnectKind::Host { host: _, port } => port,
|
||||||
|
ConnectKind::Addr { host: _, addr } => addr.port(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Connect {
|
impl fmt::Display for Connect {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{}:{}", self.host, self.port)
|
write!(f, "{}:{}", self.host(), self.port())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,16 +199,25 @@ impl Service for Connector {
|
|||||||
type Request = Connect;
|
type Request = Connect;
|
||||||
type Response = (Connect, TcpStream);
|
type Response = (Connect, TcpStream);
|
||||||
type Error = ConnectorError;
|
type Error = ConnectorError;
|
||||||
type Future = ConnectorFuture;
|
type Future = Either<ConnectorFuture, ConnectorTcpFuture>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
Ok(Async::Ready(()))
|
Ok(Async::Ready(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, req: Self::Request) -> Self::Future {
|
fn call(&mut self, req: Self::Request) -> Self::Future {
|
||||||
ConnectorFuture {
|
match req.kind {
|
||||||
fut: self.resolver.call(req),
|
ConnectKind::Host { host: _, port: _ } => Either::A(ConnectorFuture {
|
||||||
fut2: None,
|
fut: self.resolver.call(req),
|
||||||
|
fut2: None,
|
||||||
|
}),
|
||||||
|
ConnectKind::Addr { host: _, addr } => {
|
||||||
|
let mut addrs = VecDeque::new();
|
||||||
|
addrs.push_back(addr.ip());
|
||||||
|
Either::B(ConnectorTcpFuture {
|
||||||
|
fut: TcpConnectorResponse::new(req, addrs),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,6 +250,20 @@ impl Future for ConnectorFuture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub struct ConnectorTcpFuture {
|
||||||
|
fut: TcpConnectorResponse<Connect>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Future for ConnectorTcpFuture {
|
||||||
|
type Item = (Connect, TcpStream);
|
||||||
|
type Error = ConnectorError;
|
||||||
|
|
||||||
|
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||||
|
self.fut.poll().map_err(ConnectorError::IoError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Tcp stream connector service
|
/// Tcp stream connector service
|
||||||
pub struct TcpConnector<T: RequestPort>(PhantomData<T>);
|
pub struct TcpConnector<T: RequestPort>(PhantomData<T>);
|
||||||
|
|
||||||
@@ -325,7 +373,7 @@ impl Service for DefaultConnector {
|
|||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct DefaultConnectorFuture {
|
pub struct DefaultConnectorFuture {
|
||||||
fut: ConnectorFuture,
|
fut: Either<ConnectorFuture, ConnectorTcpFuture>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Future for DefaultConnectorFuture {
|
impl Future for DefaultConnectorFuture {
|
||||||
|
@@ -9,6 +9,7 @@ use futures::task::AtomicTask;
|
|||||||
/// Counter could be cloned, total ncount is shared across all clones.
|
/// Counter could be cloned, total ncount is shared across all clones.
|
||||||
pub struct Counter(Rc<CounterInner>);
|
pub struct Counter(Rc<CounterInner>);
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct CounterInner {
|
struct CounterInner {
|
||||||
count: Cell<usize>,
|
count: Cell<usize>,
|
||||||
capacity: usize,
|
capacity: usize,
|
||||||
@@ -40,6 +41,7 @@ impl Counter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct CounterGuard(Rc<CounterInner>);
|
pub struct CounterGuard(Rc<CounterInner>);
|
||||||
|
|
||||||
impl CounterGuard {
|
impl CounterGuard {
|
||||||
@@ -57,11 +59,7 @@ impl Drop for CounterGuard {
|
|||||||
|
|
||||||
impl CounterInner {
|
impl CounterInner {
|
||||||
fn inc(&self) {
|
fn inc(&self) {
|
||||||
let num = self.count.get() + 1;
|
self.count.set(self.count.get() + 1);
|
||||||
self.count.set(num);
|
|
||||||
if num == self.capacity {
|
|
||||||
self.task.register();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&self) {
|
fn dec(&self) {
|
||||||
@@ -73,6 +71,10 @@ impl CounterInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn available(&self) -> bool {
|
fn available(&self) -> bool {
|
||||||
self.count.get() < self.capacity
|
let avail = self.count.get() < self.capacity;
|
||||||
|
if !avail {
|
||||||
|
self.task.register();
|
||||||
|
}
|
||||||
|
avail
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -45,4 +45,4 @@ impl Token {
|
|||||||
self.0 += 1;
|
self.0 += 1;
|
||||||
token
|
token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -63,7 +63,7 @@ where
|
|||||||
{
|
{
|
||||||
b: Cell<B>,
|
b: Cell<B>,
|
||||||
fut_b: Option<B::Future>,
|
fut_b: Option<B::Future>,
|
||||||
fut_a: A::Future,
|
fut_a: Option<A::Future>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A, B> AndThenFuture<A, B>
|
impl<A, B> AndThenFuture<A, B>
|
||||||
@@ -71,10 +71,10 @@ where
|
|||||||
A: Service,
|
A: Service,
|
||||||
B: Service<Request = A::Response, Error = A::Error>,
|
B: Service<Request = A::Response, Error = A::Error>,
|
||||||
{
|
{
|
||||||
fn new(fut_a: A::Future, b: Cell<B>) -> Self {
|
fn new(a: A::Future, b: Cell<B>) -> Self {
|
||||||
AndThenFuture {
|
AndThenFuture {
|
||||||
b,
|
b,
|
||||||
fut_a,
|
fut_a: Some(a),
|
||||||
fut_b: None,
|
fut_b: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,8 +94,9 @@ where
|
|||||||
return fut.poll();
|
return fut.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.fut_a.poll() {
|
match self.fut_a.as_mut().expect("actix-net bug").poll() {
|
||||||
Ok(Async::Ready(resp)) => {
|
Ok(Async::Ready(resp)) => {
|
||||||
|
let _ = self.fut_a.take();
|
||||||
self.fut_b = Some(self.b.borrow_mut().call(resp));
|
self.fut_b = Some(self.b.borrow_mut().call(resp));
|
||||||
self.poll()
|
self.poll()
|
||||||
}
|
}
|
||||||
|
@@ -63,7 +63,7 @@ where
|
|||||||
{
|
{
|
||||||
b: Cell<B>,
|
b: Cell<B>,
|
||||||
fut_b: Option<B::Future>,
|
fut_b: Option<B::Future>,
|
||||||
fut_a: A::Future,
|
fut_a: Option<A::Future>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A, B> ThenFuture<A, B>
|
impl<A, B> ThenFuture<A, B>
|
||||||
@@ -71,10 +71,10 @@ where
|
|||||||
A: Service,
|
A: Service,
|
||||||
B: Service<Request = Result<A::Response, A::Error>>,
|
B: Service<Request = Result<A::Response, A::Error>>,
|
||||||
{
|
{
|
||||||
fn new(fut_a: A::Future, b: Cell<B>) -> Self {
|
fn new(a: A::Future, b: Cell<B>) -> Self {
|
||||||
ThenFuture {
|
ThenFuture {
|
||||||
b,
|
b,
|
||||||
fut_a,
|
fut_a: Some(a),
|
||||||
fut_b: None,
|
fut_b: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,12 +93,14 @@ where
|
|||||||
return fut.poll();
|
return fut.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.fut_a.poll() {
|
match self.fut_a.as_mut().expect("actix-net bug").poll() {
|
||||||
Ok(Async::Ready(resp)) => {
|
Ok(Async::Ready(resp)) => {
|
||||||
|
let _ = self.fut_a.take();
|
||||||
self.fut_b = Some(self.b.borrow_mut().call(Ok(resp)));
|
self.fut_b = Some(self.b.borrow_mut().call(Ok(resp)));
|
||||||
self.poll()
|
self.poll()
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
let _ = self.fut_a.take();
|
||||||
self.fut_b = Some(self.b.borrow_mut().call(Err(err)));
|
self.fut_b = Some(self.b.borrow_mut().call(Err(err)));
|
||||||
self.poll()
|
self.poll()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user