-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
308 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
## [0.1.0] - 2018-12-09 | ||
|
||
* Move codec to separate crate | ||
* Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Changes | ||
|
||
## [0.1.0] - 2018-12-09 | ||
|
||
* Move server to separate crate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
[package] | ||
name = "actix-server" | ||
version = "0.1.0" | ||
authors = ["Nikolay Kim <[email protected]>"] | ||
description = "Actix server - General purpose tcp server" | ||
readme = "README.md" | ||
keywords = ["network", "framework", "async", "futures"] | ||
homepage = "https://actix.rs" | ||
repository = "https://github.com/actix/actix-net.git" | ||
documentation = "https://docs.rs/actix-server/" | ||
categories = ["network-programming", "asynchronous"] | ||
license = "MIT/Apache-2.0" | ||
exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"] | ||
edition = "2018" | ||
workspace = "../" | ||
|
||
[package.metadata.docs.rs] | ||
features = ["ssl", "tls", "rust-tls"] | ||
|
||
[lib] | ||
name = "actix_server" | ||
path = "src/lib.rs" | ||
|
||
[features] | ||
default = [] | ||
|
||
# tls | ||
tls = ["native-tls"] | ||
|
||
# openssl | ||
ssl = ["openssl", "tokio-openssl"] | ||
|
||
# rustls | ||
rust-tls = ["rustls", "tokio-rustls", "webpki", "webpki-roots"] | ||
|
||
[dependencies] | ||
actix-service = "0.1.1" | ||
actix-rt = { path = "../actix-rt" } | ||
|
||
log = "0.4" | ||
num_cpus = "1.0" | ||
|
||
# io | ||
mio = "^0.6.13" | ||
net2 = "0.2" | ||
bytes = "0.4" | ||
futures = "0.1" | ||
slab = "0.4" | ||
tokio-io = "0.1" | ||
tokio-tcp = "0.1" | ||
tokio-timer = "0.2" | ||
tokio-reactor = "0.1" | ||
tokio-signal = "0.2" | ||
|
||
# native-tls | ||
native-tls = { version="0.2", optional = true } | ||
|
||
# openssl | ||
openssl = { version="0.10", optional = true } | ||
tokio-openssl = { version="0.3", optional = true } | ||
|
||
#rustls | ||
rustls = { version = "^0.14", optional = true } | ||
tokio-rustls = { version = "^0.8", optional = true } | ||
webpki = { version = "0.18", optional = true } | ||
webpki-roots = { version = "0.15", optional = true } | ||
|
||
[dev-dependencies] | ||
env_logger = "0.5" | ||
|
||
[profile.release] | ||
lto = true | ||
opt-level = 3 | ||
codegen-units = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use std::cell::Cell; | ||
use std::rc::Rc; | ||
|
||
use futures::task::AtomicTask; | ||
|
||
#[derive(Clone)] | ||
/// Simple counter with ability to notify task on reaching specific number | ||
/// | ||
/// Counter could be cloned, total ncount is shared across all clones. | ||
pub struct Counter(Rc<CounterInner>); | ||
|
||
struct CounterInner { | ||
count: Cell<usize>, | ||
capacity: usize, | ||
task: AtomicTask, | ||
} | ||
|
||
impl Counter { | ||
/// Create `Counter` instance and set max value. | ||
pub fn new(capacity: usize) -> Self { | ||
Counter(Rc::new(CounterInner { | ||
capacity, | ||
count: Cell::new(0), | ||
task: AtomicTask::new(), | ||
})) | ||
} | ||
|
||
pub fn get(&self) -> CounterGuard { | ||
CounterGuard::new(self.0.clone()) | ||
} | ||
|
||
/// Check if counter is not at capacity | ||
pub fn available(&self) -> bool { | ||
self.0.available() | ||
} | ||
|
||
/// Get total number of acquired counts | ||
pub fn total(&self) -> usize { | ||
self.0.count.get() | ||
} | ||
} | ||
|
||
pub struct CounterGuard(Rc<CounterInner>); | ||
|
||
impl CounterGuard { | ||
fn new(inner: Rc<CounterInner>) -> Self { | ||
inner.inc(); | ||
CounterGuard(inner) | ||
} | ||
} | ||
|
||
impl Drop for CounterGuard { | ||
fn drop(&mut self) { | ||
self.0.dec(); | ||
} | ||
} | ||
|
||
impl CounterInner { | ||
fn inc(&self) { | ||
let num = self.count.get() + 1; | ||
self.count.set(num); | ||
if num == self.capacity { | ||
self.task.register(); | ||
} | ||
} | ||
|
||
fn dec(&self) { | ||
let num = self.count.get(); | ||
self.count.set(num - 1); | ||
if num == self.capacity { | ||
self.task.notify(); | ||
} | ||
} | ||
|
||
fn available(&self) -> bool { | ||
self.count.get() < self.capacity | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//! SSL Services | ||
use std::sync::atomic::{AtomicUsize, Ordering}; | ||
|
||
use crate::counter::Counter; | ||
|
||
#[cfg(feature = "ssl")] | ||
mod openssl; | ||
#[cfg(feature = "ssl")] | ||
pub use self::openssl::OpensslAcceptor; | ||
|
||
#[cfg(feature = "tls")] | ||
mod nativetls; | ||
#[cfg(feature = "tls")] | ||
pub use self::nativetls::{NativeTlsAcceptor, TlsStream}; | ||
|
||
#[cfg(feature = "rust-tls")] | ||
mod rustls; | ||
#[cfg(feature = "rust-tls")] | ||
pub use self::rustls::RustlsAcceptor; | ||
|
||
/// Sets the maximum per-worker concurrent ssl connection establish process. | ||
/// | ||
/// All listeners will stop accepting connections when this limit is | ||
/// reached. It can be used to limit the global SSL CPU usage. | ||
/// | ||
/// By default max connections is set to a 256. | ||
pub fn max_concurrent_ssl_connect(num: usize) { | ||
MAX_CONN.store(num, Ordering::Relaxed); | ||
} | ||
|
||
pub(crate) static MAX_CONN: AtomicUsize = AtomicUsize::new(256); | ||
|
||
thread_local! { | ||
static MAX_CONN_COUNTER: Counter = Counter::new(MAX_CONN.load(Ordering::Relaxed)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.