Skip to content

Commit 81421c2

Browse files
committed
rename maxconn => max_concurrent_connections
1 parent 305d0e9 commit 81421c2

File tree

4 files changed

+88
-66
lines changed

4 files changed

+88
-66
lines changed

Diff for: actix-server/CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased - 2021-xx-xx
44
* Rename `Server` to `ServerHandle`. [#???]
5+
* Rename `ServerBuilder::{maxconn => max_concurrent_connections}`. [#???]
56
* Minimum supported Rust version (MSRV) is now 1.52.
67

78
[#???]: https://github.com/actix/actix-net/pull/???

Diff for: actix-server/src/builder.rs

+85-64
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,21 @@ impl ServerBuilder {
125125

126126
/// Sets the maximum per-worker number of concurrent connections.
127127
///
128-
/// All socket listeners will stop accepting connections when this limit is
129-
/// reached for each worker.
128+
/// All socket listeners will stop accepting connections when this limit is reached for
129+
/// each worker.
130130
///
131-
/// By default max connections is set to a 25k per worker.
132-
pub fn maxconn(mut self, num: usize) -> Self {
131+
/// By default max connections is set to a 25,600 per worker.
132+
pub fn max_concurrent_connections(mut self, num: usize) -> Self {
133133
self.worker_config.max_concurrent_connections(num);
134134
self
135135
}
136136

137+
#[doc(hidden)]
138+
#[deprecated(since = "2.0.0", note = "Renamed to `max_concurrent_connections`.")]
139+
pub fn maxconn(self, num: usize) -> Self {
140+
self.max_concurrent_connections(num)
141+
}
142+
137143
/// Stop Actix system.
138144
pub fn system_exit(mut self) -> Self {
139145
self.exit = true;
@@ -158,7 +164,11 @@ impl ServerBuilder {
158164
self
159165
}
160166

161-
/// Add new service to the server.
167+
/// Bind server to socket addresses.
168+
///
169+
/// Binds to all network interface addresses that resolve from the `addr` argument.
170+
/// Eg. using `localhost` might bind to both IPv4 and IPv6 addresses. Bind to multiple distinct
171+
/// interfaces at the same time by passing a list of socket addresses.
162172
pub fn bind<F, U, N: AsRef<str>>(mut self, name: N, addr: U, factory: F) -> io::Result<Self>
163173
where
164174
F: ServiceFactory<TcpStream>,
@@ -180,56 +190,9 @@ impl ServerBuilder {
180190
Ok(self)
181191
}
182192

183-
/// Add new unix domain service to the server.
184-
#[cfg(unix)]
185-
pub fn bind_uds<F, U, N>(self, name: N, addr: U, factory: F) -> io::Result<Self>
186-
where
187-
F: ServiceFactory<actix_rt::net::UnixStream>,
188-
N: AsRef<str>,
189-
U: AsRef<std::path::Path>,
190-
{
191-
// The path must not exist when we try to bind.
192-
// Try to remove it to avoid bind error.
193-
if let Err(e) = std::fs::remove_file(addr.as_ref()) {
194-
// NotFound is expected and not an issue. Anything else is.
195-
if e.kind() != std::io::ErrorKind::NotFound {
196-
return Err(e);
197-
}
198-
}
199-
200-
let lst = crate::socket::StdUnixListener::bind(addr)?;
201-
self.listen_uds(name, lst, factory)
202-
}
203-
204-
/// Add new unix domain service to the server.
205-
/// Useful when running as a systemd service and
206-
/// a socket FD can be acquired using the systemd crate.
207-
#[cfg(unix)]
208-
pub fn listen_uds<F, N: AsRef<str>>(
209-
mut self,
210-
name: N,
211-
lst: crate::socket::StdUnixListener,
212-
factory: F,
213-
) -> io::Result<Self>
214-
where
215-
F: ServiceFactory<actix_rt::net::UnixStream>,
216-
{
217-
use std::net::{IpAddr, Ipv4Addr};
218-
lst.set_nonblocking(true)?;
219-
let token = self.next_token();
220-
let addr = StdSocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
221-
self.services.push(StreamNewService::create(
222-
name.as_ref().to_string(),
223-
token,
224-
factory,
225-
addr,
226-
));
227-
self.sockets
228-
.push((token, name.as_ref().to_string(), MioListener::from(lst)));
229-
Ok(self)
230-
}
231-
232-
/// Add new service to the server.
193+
/// Bind server to existing TCP listener.
194+
///
195+
/// Useful when running as a systemd service and a socket FD can be passed to the process.
233196
pub fn listen<F, N: AsRef<str>>(
234197
mut self,
235198
name: N,
@@ -240,9 +203,10 @@ impl ServerBuilder {
240203
F: ServiceFactory<TcpStream>,
241204
{
242205
lst.set_nonblocking(true)?;
243-
let addr = lst.local_addr()?;
244206

207+
let addr = lst.local_addr()?;
245208
let token = self.next_token();
209+
246210
self.services.push(StreamNewService::create(
247211
name.as_ref().to_string(),
248212
token,
@@ -434,6 +398,62 @@ impl ServerBuilder {
434398
}
435399
}
436400

401+
/// Unix Domain Socket (UDS) support.
402+
#[cfg(unix)]
403+
impl ServerBuilder {
404+
/// Add new unix domain service to the server.
405+
pub fn bind_uds<F, U, N>(self, name: N, addr: U, factory: F) -> io::Result<Self>
406+
where
407+
F: ServiceFactory<actix_rt::net::UnixStream>,
408+
N: AsRef<str>,
409+
U: AsRef<std::path::Path>,
410+
{
411+
// The path must not exist when we try to bind.
412+
// Try to remove it to avoid bind error.
413+
if let Err(e) = std::fs::remove_file(addr.as_ref()) {
414+
// NotFound is expected and not an issue. Anything else is.
415+
if e.kind() != std::io::ErrorKind::NotFound {
416+
return Err(e);
417+
}
418+
}
419+
420+
let lst = crate::socket::StdUnixListener::bind(addr)?;
421+
self.listen_uds(name, lst, factory)
422+
}
423+
424+
/// Add new unix domain service to the server.
425+
///
426+
/// Useful when running as a systemd service and a socket FD can be passed to the process.
427+
pub fn listen_uds<F, N: AsRef<str>>(
428+
mut self,
429+
name: N,
430+
lst: crate::socket::StdUnixListener,
431+
factory: F,
432+
) -> io::Result<Self>
433+
where
434+
F: ServiceFactory<actix_rt::net::UnixStream>,
435+
{
436+
use std::net::{IpAddr, Ipv4Addr};
437+
438+
lst.set_nonblocking(true)?;
439+
440+
let addr = StdSocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
441+
let token = self.next_token();
442+
443+
self.services.push(StreamNewService::create(
444+
name.as_ref().to_string(),
445+
token,
446+
factory,
447+
addr,
448+
));
449+
450+
self.sockets
451+
.push((token, name.as_ref().to_string(), MioListener::from(lst)));
452+
453+
Ok(self)
454+
}
455+
}
456+
437457
impl Future for ServerBuilder {
438458
type Output = ();
439459

@@ -452,29 +472,30 @@ pub(super) fn bind_addr<S: ToSocketAddrs>(
452472
backlog: u32,
453473
) -> io::Result<Vec<MioTcpListener>> {
454474
let mut err = None;
455-
let mut succ = false;
475+
let mut success = false;
456476
let mut sockets = Vec::new();
477+
457478
for addr in addr.to_socket_addrs()? {
458479
match create_tcp_listener(addr, backlog) {
459480
Ok(lst) => {
460-
succ = true;
481+
success = true;
461482
sockets.push(lst);
462483
}
463484
Err(e) => err = Some(e),
464485
}
465486
}
466487

467-
if !succ {
468-
if let Some(e) = err.take() {
469-
Err(e)
488+
if success {
489+
Ok(sockets)
490+
} else {
491+
if let Some(err) = err.take() {
492+
Err(err)
470493
} else {
471494
Err(io::Error::new(
472495
io::ErrorKind::Other,
473-
"Can not bind to address.",
496+
"Can not bind to socket address",
474497
))
475498
}
476-
} else {
477-
Ok(sockets)
478499
}
479500
}
480501

Diff for: actix-server/src/worker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl Default for ServerWorkerConfig {
247247
Self {
248248
shutdown_timeout: Duration::from_secs(30),
249249
max_blocking_threads,
250-
max_concurrent_connections: 25600,
250+
max_concurrent_connections: 25_600,
251251
}
252252
}
253253
}

Diff for: actix-server/tests/test_server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ async fn test_max_concurrent_connections() {
170170
// Set a relative higher backlog.
171171
.backlog(12)
172172
// max connection for a worker is 3.
173-
.maxconn(max_conn)
173+
.max_concurrent_connections(max_conn)
174174
.workers(1)
175175
.disable_signals()
176176
.bind("test", addr, move || {

0 commit comments

Comments
 (0)