Compare commits

...

5 Commits

Author SHA1 Message Date
ngrondin 3913fac9fc
Merge 616aed669e into c85e058f5d 2025-09-01 11:14:14 +09:00
dependabot[bot] c85e058f5d
build(deps): bump rui314/setup-mold from 7344740a9418dcdcb481c7df83d9fbd1d5072d7d to 725a8794d15fc7563f59595bd9556495c0564878 (#3752)
build(deps): bump rui314/setup-mold

Bumps [rui314/setup-mold](https://github.com/rui314/setup-mold) from 7344740a9418dcdcb481c7df83d9fbd1d5072d7d to 725a8794d15fc7563f59595bd9556495c0564878.
- [Commits](7344740a94...725a8794d1)

---
updated-dependencies:
- dependency-name: rui314/setup-mold
  dependency-version: 725a8794d15fc7563f59595bd9556495c0564878
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-01 01:54:18 +00:00
Rob Ede 616aed669e
Merge branch 'master' into master 2025-08-29 04:02:11 +01:00
Nicolas 9320df6339 Fix formatting 2025-06-01 18:37:55 +10:00
Nicolas ee7e37c62f Added max_buffer_size as a configuration item on the httpservice 2025-06-01 15:48:21 +10:00
7 changed files with 62 additions and 6 deletions

View File

@ -77,7 +77,7 @@ jobs:
run: ./scripts/free-disk-space.sh run: ./scripts/free-disk-space.sh
- name: Setup mold linker - name: Setup mold linker
uses: rui314/setup-mold@7344740a9418dcdcb481c7df83d9fbd1d5072d7d # v1 uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1
- name: Install Rust - name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@ab6845274e2ff01cd4462007e1a9d9df1ab49f42 # v1.14.0 uses: actions-rust-lang/setup-rust-toolchain@ab6845274e2ff01cd4462007e1a9d9df1ab49f42 # v1.14.0

View File

@ -56,7 +56,7 @@ jobs:
- name: Setup mold linker - name: Setup mold linker
if: matrix.target.os == 'ubuntu-latest' if: matrix.target.os == 'ubuntu-latest'
uses: rui314/setup-mold@7344740a9418dcdcb481c7df83d9fbd1d5072d7d # v1 uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1
- name: Install Rust (${{ matrix.version.name }}) - name: Install Rust (${{ matrix.version.name }})
uses: actions-rust-lang/setup-rust-toolchain@ab6845274e2ff01cd4462007e1a9d9df1ab49f42 # v1.14.0 uses: actions-rust-lang/setup-rust-toolchain@ab6845274e2ff01cd4462007e1a9d9df1ab49f42 # v1.14.0

View File

@ -17,6 +17,7 @@ pub struct HttpServiceBuilder<T, S, X = ExpectHandler, U = UpgradeHandler> {
keep_alive: KeepAlive, keep_alive: KeepAlive,
client_request_timeout: Duration, client_request_timeout: Duration,
client_disconnect_timeout: Duration, client_disconnect_timeout: Duration,
max_buffer_size: Option<usize>,
secure: bool, secure: bool,
local_addr: Option<net::SocketAddr>, local_addr: Option<net::SocketAddr>,
expect: X, expect: X,
@ -38,6 +39,7 @@ where
keep_alive: KeepAlive::default(), keep_alive: KeepAlive::default(),
client_request_timeout: Duration::from_secs(5), client_request_timeout: Duration::from_secs(5),
client_disconnect_timeout: Duration::ZERO, client_disconnect_timeout: Duration::ZERO,
max_buffer_size: None,
secure: false, secure: false,
local_addr: None, local_addr: None,
@ -124,6 +126,15 @@ where
self.client_disconnect_timeout(dur) self.client_disconnect_timeout(dur)
} }
/// Set maximum buffer size.
///
/// Defines the maximum size of the buffer. When the size is reached, the dispatcher
/// will flush the data to the IO streams
pub fn max_buffer_size(mut self, size: usize) -> Self {
self.max_buffer_size = Some(size);
self
}
/// Provide service for `EXPECT: 100-Continue` support. /// Provide service for `EXPECT: 100-Continue` support.
/// ///
/// Service get called with request that contains `EXPECT` header. /// Service get called with request that contains `EXPECT` header.
@ -140,6 +151,7 @@ where
keep_alive: self.keep_alive, keep_alive: self.keep_alive,
client_request_timeout: self.client_request_timeout, client_request_timeout: self.client_request_timeout,
client_disconnect_timeout: self.client_disconnect_timeout, client_disconnect_timeout: self.client_disconnect_timeout,
max_buffer_size: self.max_buffer_size,
secure: self.secure, secure: self.secure,
local_addr: self.local_addr, local_addr: self.local_addr,
expect: expect.into_factory(), expect: expect.into_factory(),
@ -164,6 +176,7 @@ where
keep_alive: self.keep_alive, keep_alive: self.keep_alive,
client_request_timeout: self.client_request_timeout, client_request_timeout: self.client_request_timeout,
client_disconnect_timeout: self.client_disconnect_timeout, client_disconnect_timeout: self.client_disconnect_timeout,
max_buffer_size: self.max_buffer_size,
secure: self.secure, secure: self.secure,
local_addr: self.local_addr, local_addr: self.local_addr,
expect: self.expect, expect: self.expect,
@ -199,6 +212,7 @@ where
self.keep_alive, self.keep_alive,
self.client_request_timeout, self.client_request_timeout,
self.client_disconnect_timeout, self.client_disconnect_timeout,
self.max_buffer_size,
self.secure, self.secure,
self.local_addr, self.local_addr,
); );
@ -224,6 +238,7 @@ where
self.keep_alive, self.keep_alive,
self.client_request_timeout, self.client_request_timeout,
self.client_disconnect_timeout, self.client_disconnect_timeout,
self.max_buffer_size,
self.secure, self.secure,
self.local_addr, self.local_addr,
); );
@ -246,6 +261,7 @@ where
self.keep_alive, self.keep_alive,
self.client_request_timeout, self.client_request_timeout,
self.client_disconnect_timeout, self.client_disconnect_timeout,
self.max_buffer_size,
self.secure, self.secure,
self.local_addr, self.local_addr,
); );

View File

@ -17,6 +17,7 @@ struct Inner {
keep_alive: KeepAlive, keep_alive: KeepAlive,
client_request_timeout: Duration, client_request_timeout: Duration,
client_disconnect_timeout: Duration, client_disconnect_timeout: Duration,
max_buffer_size: Option<usize>,
secure: bool, secure: bool,
local_addr: Option<std::net::SocketAddr>, local_addr: Option<std::net::SocketAddr>,
date_service: DateService, date_service: DateService,
@ -28,6 +29,7 @@ impl Default for ServiceConfig {
KeepAlive::default(), KeepAlive::default(),
Duration::from_secs(5), Duration::from_secs(5),
Duration::ZERO, Duration::ZERO,
None,
false, false,
None, None,
) )
@ -40,6 +42,7 @@ impl ServiceConfig {
keep_alive: KeepAlive, keep_alive: KeepAlive,
client_request_timeout: Duration, client_request_timeout: Duration,
client_disconnect_timeout: Duration, client_disconnect_timeout: Duration,
max_buffer_size: Option<usize>,
secure: bool, secure: bool,
local_addr: Option<net::SocketAddr>, local_addr: Option<net::SocketAddr>,
) -> ServiceConfig { ) -> ServiceConfig {
@ -47,6 +50,7 @@ impl ServiceConfig {
keep_alive: keep_alive.normalize(), keep_alive: keep_alive.normalize(),
client_request_timeout, client_request_timeout,
client_disconnect_timeout, client_disconnect_timeout,
max_buffer_size,
secure, secure,
local_addr, local_addr,
date_service: DateService::new(), date_service: DateService::new(),
@ -104,6 +108,10 @@ impl ServiceConfig {
self.0.date_service.now() self.0.date_service.now()
} }
pub fn max_buffer_size(&self) -> Option<usize> {
self.0.max_buffer_size
}
/// Writes date header to `dst` buffer. /// Writes date header to `dst` buffer.
/// ///
/// Low-level method that utilizes the built-in efficient date service, requiring fewer syscalls /// Low-level method that utilizes the built-in efficient date service, requiring fewer syscalls
@ -143,8 +151,14 @@ mod tests {
#[actix_rt::test] #[actix_rt::test]
async fn test_date_service_update() { async fn test_date_service_update() {
let settings = let settings = ServiceConfig::new(
ServiceConfig::new(KeepAlive::Os, Duration::ZERO, Duration::ZERO, false, None); KeepAlive::Os,
Duration::ZERO,
Duration::ZERO,
None,
false,
None,
);
yield_now().await; yield_now().await;

View File

@ -166,6 +166,7 @@ pin_project! {
pub(super) io: Option<T>, pub(super) io: Option<T>,
read_buf: BytesMut, read_buf: BytesMut,
write_buf: BytesMut, write_buf: BytesMut,
max_buffer_size: usize,
codec: Codec, codec: Codec,
} }
} }
@ -278,6 +279,7 @@ where
io: Some(io), io: Some(io),
read_buf: BytesMut::with_capacity(HW_BUFFER_SIZE), read_buf: BytesMut::with_capacity(HW_BUFFER_SIZE),
write_buf: BytesMut::with_capacity(HW_BUFFER_SIZE), write_buf: BytesMut::with_capacity(HW_BUFFER_SIZE),
max_buffer_size: config.max_buffer_size().unwrap_or(MAX_BUFFER_SIZE),
codec: Codec::new(config), codec: Codec::new(config),
}, },
}, },
@ -493,7 +495,7 @@ where
StateProj::SendPayload { mut body } => { StateProj::SendPayload { mut body } => {
// keep populate writer buffer until buffer size limit hit, // keep populate writer buffer until buffer size limit hit,
// get blocked or finished. // get blocked or finished.
while this.write_buf.len() < super::payload::MAX_BUFFER_SIZE { while this.write_buf.len() < *this.max_buffer_size {
match body.as_mut().poll_next(cx) { match body.as_mut().poll_next(cx) {
Poll::Ready(Some(Ok(item))) => { Poll::Ready(Some(Ok(item))) => {
this.codec this.codec
@ -532,7 +534,7 @@ where
// keep populate writer buffer until buffer size limit hit, // keep populate writer buffer until buffer size limit hit,
// get blocked or finished. // get blocked or finished.
while this.write_buf.len() < super::payload::MAX_BUFFER_SIZE { while this.write_buf.len() < *this.max_buffer_size {
match body.as_mut().poll_next(cx) { match body.as_mut().poll_next(cx) {
Poll::Ready(Some(Ok(item))) => { Poll::Ready(Some(Ok(item))) => {
this.codec this.codec

View File

@ -82,6 +82,7 @@ async fn late_request() {
KeepAlive::Disabled, KeepAlive::Disabled,
Duration::from_millis(100), Duration::from_millis(100),
Duration::ZERO, Duration::ZERO,
None,
false, false,
None, None,
); );
@ -149,6 +150,7 @@ async fn oneshot_connection() {
KeepAlive::Disabled, KeepAlive::Disabled,
Duration::from_millis(100), Duration::from_millis(100),
Duration::ZERO, Duration::ZERO,
None,
false, false,
None, None,
); );
@ -210,6 +212,7 @@ async fn keep_alive_timeout() {
KeepAlive::Timeout(Duration::from_millis(200)), KeepAlive::Timeout(Duration::from_millis(200)),
Duration::from_millis(100), Duration::from_millis(100),
Duration::ZERO, Duration::ZERO,
None,
false, false,
None, None,
); );
@ -289,6 +292,7 @@ async fn keep_alive_follow_up_req() {
KeepAlive::Timeout(Duration::from_millis(500)), KeepAlive::Timeout(Duration::from_millis(500)),
Duration::from_millis(100), Duration::from_millis(100),
Duration::ZERO, Duration::ZERO,
None,
false, false,
None, None,
); );
@ -453,6 +457,7 @@ async fn pipelining_ok_then_ok() {
KeepAlive::Disabled, KeepAlive::Disabled,
Duration::from_millis(1), Duration::from_millis(1),
Duration::from_millis(1), Duration::from_millis(1),
None,
false, false,
None, None,
); );
@ -523,6 +528,7 @@ async fn pipelining_ok_then_bad() {
KeepAlive::Disabled, KeepAlive::Disabled,
Duration::from_millis(1), Duration::from_millis(1),
Duration::from_millis(1), Duration::from_millis(1),
None,
false, false,
None, None,
); );
@ -586,6 +592,7 @@ async fn expect_handling() {
KeepAlive::Disabled, KeepAlive::Disabled,
Duration::ZERO, Duration::ZERO,
Duration::ZERO, Duration::ZERO,
None,
false, false,
None, None,
); );
@ -663,6 +670,7 @@ async fn expect_eager() {
KeepAlive::Disabled, KeepAlive::Disabled,
Duration::ZERO, Duration::ZERO,
Duration::ZERO, Duration::ZERO,
None,
false, false,
None, None,
); );
@ -746,6 +754,7 @@ async fn upgrade_handling() {
KeepAlive::Disabled, KeepAlive::Disabled,
Duration::ZERO, Duration::ZERO,
Duration::ZERO, Duration::ZERO,
None,
false, false,
None, None,
); );

View File

@ -31,6 +31,7 @@ struct Config {
keep_alive: KeepAlive, keep_alive: KeepAlive,
client_request_timeout: Duration, client_request_timeout: Duration,
client_disconnect_timeout: Duration, client_disconnect_timeout: Duration,
max_buffer_size: Option<usize>,
#[allow(dead_code)] // only dead when no TLS features are enabled #[allow(dead_code)] // only dead when no TLS features are enabled
tls_handshake_timeout: Option<Duration>, tls_handshake_timeout: Option<Duration>,
} }
@ -116,6 +117,7 @@ where
keep_alive: KeepAlive::default(), keep_alive: KeepAlive::default(),
client_request_timeout: Duration::from_secs(5), client_request_timeout: Duration::from_secs(5),
client_disconnect_timeout: Duration::from_secs(1), client_disconnect_timeout: Duration::from_secs(1),
max_buffer_size: None,
tls_handshake_timeout: None, tls_handshake_timeout: None,
})), })),
backlog: 1024, backlog: 1024,
@ -234,6 +236,15 @@ where
self self
} }
/// Set maximum buffer size.
///
/// Defines the maximum size of the write buffer. When the size is reached, the dispatcher
/// will flush the data to the IO streams
pub fn max_buffer_size(self, size: usize) -> Self {
self.config.lock().unwrap().max_buffer_size = Some(size);
self
}
/// Sets TLS handshake timeout. /// Sets TLS handshake timeout.
/// ///
/// Defines a timeout for TLS handshake. If the TLS handshake does not complete within this /// Defines a timeout for TLS handshake. If the TLS handshake does not complete within this
@ -560,6 +571,10 @@ where
.client_disconnect_timeout(cfg.client_disconnect_timeout) .client_disconnect_timeout(cfg.client_disconnect_timeout)
.local_addr(addr); .local_addr(addr);
if let Some(size) = cfg.max_buffer_size {
svc = svc.max_buffer_size(size);
};
if let Some(handler) = on_connect_fn.clone() { if let Some(handler) = on_connect_fn.clone() {
svc = svc =
svc.on_connect_ext(move |io: &_, ext: _| (handler)(io as &dyn Any, ext)) svc.on_connect_ext(move |io: &_, ext: _| (handler)(io as &dyn Any, ext))