Skip to content

Commit 77a5d12

Browse files
authored
Use ntex_dispatcher::Dispatcher instead of ntex-io (#78)
1 parent 83daeda commit 77a5d12

File tree

12 files changed

+68
-62
lines changed

12 files changed

+68
-62
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105
strategy:
106106
matrix:
107107
rust:
108-
- 1.86 # never go past ntex's msrv
108+
- 1.88 # never go past ntex's msrv
109109

110110
os:
111111
- ubuntu-latest

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes
22

3+
## [3.5.0] - 2026-01-29
4+
5+
* Use ntex_dispatcher::Dispatcher instead of ntex-io
6+
37
## [3.4.0] - 2026-01-17
48

59
* Update bytes and codec apis

Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ntex-h2"
3-
version = "3.4.0"
3+
version = "3.5.0"
44
license = "MIT OR Apache-2.0"
55
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
66
description = "An HTTP/2 client and server"
@@ -11,7 +11,7 @@ keywords = ["http", "async", "non-blocking"]
1111
categories = ["asynchronous", "web-programming", "network-programming"]
1212
exclude = ["fixtures/**", "util/**", "fuzz/**"]
1313
edition = "2024"
14-
rust-version = "1.86"
14+
rust-version = "1.88"
1515

1616
[features]
1717
default = []
@@ -23,10 +23,11 @@ unstable = []
2323
features = []
2424

2525
[dependencies]
26-
ntex-bytes = "1.3"
26+
ntex-bytes = "1.4"
2727
ntex-codec = "1.1"
28+
ntex-dispatcher = "3"
2829
ntex-http = "1"
29-
ntex-io = "3.4"
30+
ntex-io = "3.5"
3031
ntex-net = "3"
3132
ntex-service = "4"
3233
ntex-util = "3"
@@ -49,7 +50,7 @@ walkdir = "2.3.2"
4950
serde = "1"
5051
serde_json = "1"
5152

52-
ntex = { version = "3.0.0-pre.11", features = ["openssl"] }
53+
ntex = { version = "3.0.0-pre.14", features = ["openssl"] }
5354
ntex-tls = { version = "3", features = ["openssl"] }
5455
openssl = "0.10"
5556

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ HTTP/2 client & server implementation for Rust.
55
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
66
[![Crates.io](https://img.shields.io/crates/v/ntex-h2.svg)](https://crates.io/crates/ntex-h2)
77
[![Documentation](https://img.shields.io/docsrs/ntex-h2/latest)](https://docs.rs/ntex-h2)
8-
[![Version](https://img.shields.io/badge/rustc-1.86+-lightgray.svg)](https://releases.rs/docs/1.85.0/)
8+
[![Version](https://img.shields.io/badge/rustc-1.88+-lightgray.svg)](https://releases.rs/docs/1.88.0/)
99
[![CI](https://github.com/ntex-rs/ntex-h2/actions/workflows/CI.yml/badge.svg)](https://github.com/ntex-rs/ntex-h2/actions/workflows/CI.yml)
1010
[![codecov](https://codecov.io/gh/ntex-rs/ntex-h2/branch/main/graph/badge.svg)](https://codecov.io/gh/ntex-rs/ntex-h2)
1111

src/client/simple.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use std::{fmt, future::Future, pin::Pin, rc::Rc, task::Context, task::Poll};
22

33
use nanorand::Rng;
44
use ntex_bytes::ByteString;
5+
use ntex_dispatcher::Dispatcher as IoDispatcher;
56
use ntex_http::{HeaderMap, Method, uri::Scheme};
6-
use ntex_io::{Dispatcher as IoDispatcher, IoBoxed, IoRef, OnDisconnect};
7+
use ntex_io::{IoBoxed, IoRef, OnDisconnect};
78
use ntex_service::cfg::Cfg;
89
use ntex_util::{channel::pool, time::Millis, time::Sleep};
910

@@ -266,11 +267,11 @@ impl Future for ClientDisconnect {
266267

267268
if Pin::new(&mut this.disconnect).poll(cx).is_ready() {
268269
return Poll::Ready(this.client.0.con.check_error_with_disconnect());
269-
} else if let Some(ref mut sleep) = this.timeout {
270-
if sleep.poll_elapsed(cx).is_ready() {
271-
this.client.0.con.close();
272-
return Poll::Ready(Err(OperationError::Disconnected));
273-
}
270+
} else if let Some(ref mut sleep) = this.timeout
271+
&& sleep.poll_elapsed(cx).is_ready()
272+
{
273+
this.client.0.con.close();
274+
return Poll::Ready(Err(OperationError::Disconnected));
274275
}
275276
Poll::Pending
276277
}

src/connection.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,13 @@ impl Connection {
403403
} else {
404404
let local = self.0.active_local_streams.get();
405405
self.0.active_local_streams.set(local - 1);
406-
if let Some(max) = self.0.local_max_concurrent_streams.get() {
407-
if local == max {
408-
while let Some(tx) = self.0.readiness.borrow_mut().pop_front() {
409-
if !tx.is_canceled() {
410-
let _ = tx.send(());
411-
break;
412-
}
406+
if let Some(max) = self.0.local_max_concurrent_streams.get()
407+
&& local == max
408+
{
409+
while let Some(tx) = self.0.readiness.borrow_mut().pop_front() {
410+
if !tx.is_canceled() {
411+
let _ = tx.send(());
412+
break;
413413
}
414414
}
415415
}
@@ -539,18 +539,18 @@ impl RecvHalfConnection {
539539
}
540540

541541
// Max concurrent streams check
542-
if let Some(max) = self.0.local_config.remote_max_concurrent_streams {
543-
if self.0.active_remote_streams.get() >= max {
544-
// check if client opened more streams than allowed
545-
// in that case close connection
546-
return if self.flags().contains(ConnectionFlags::STREAM_REFUSED) {
547-
Err(Either::Left(ConnectionError::ConcurrencyOverflow))
548-
} else {
549-
self.encode(frame::Reset::new(id, frame::Reason::REFUSED_STREAM));
550-
self.set_flags(ConnectionFlags::STREAM_REFUSED);
551-
Ok(None)
552-
};
553-
}
542+
if let Some(max) = self.0.local_config.remote_max_concurrent_streams
543+
&& self.0.active_remote_streams.get() >= max
544+
{
545+
// check if client opened more streams than allowed
546+
// in that case close connection
547+
return if self.flags().contains(ConnectionFlags::STREAM_REFUSED) {
548+
Err(Either::Left(ConnectionError::ConcurrencyOverflow))
549+
} else {
550+
self.encode(frame::Reset::new(id, frame::Reason::REFUSED_STREAM));
551+
self.set_flags(ConnectionFlags::STREAM_REFUSED);
552+
Ok(None)
553+
};
554554
}
555555

556556
// Pseudo-headers validation

src/dispatcher.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::{fmt, future::Future, future::poll_fn, rc::Rc, task::Context, task::Poll};
22

3-
use ntex_io::DispatchItem;
3+
use ntex_dispatcher::{DispatchItem, Reason as DispReason};
44
use ntex_service::{Pipeline, Service, ServiceCtx};
5-
use ntex_util::future::{Either, join};
6-
use ntex_util::{HashMap, spawn};
5+
use ntex_util::{HashMap, future::Either, future::join, spawn};
76

87
use crate::connection::{Connection, RecvHalfConnection};
98
use crate::control::{Control, ControlAck};
@@ -247,19 +246,19 @@ where
247246
Ok(None)
248247
}
249248
},
250-
DispatchItem::EncoderError(err) => {
249+
DispatchItem::Stop(DispReason::Encoder(err)) => {
251250
let err = ConnectionError::from(err);
252251
let streams = self.connection.proto_error(&err);
253252
self.handle_connection_error(streams, err.into());
254253
control(Control::proto_error(err), &self.inner, ctx).await
255254
}
256-
DispatchItem::DecoderError(err) => {
255+
DispatchItem::Stop(DispReason::Decoder(err)) => {
257256
let err = ConnectionError::from(err);
258257
let streams = self.connection.proto_error(&err);
259258
self.handle_connection_error(streams, err.into());
260259
control(Control::proto_error(err), &self.inner, ctx).await
261260
}
262-
DispatchItem::KeepAliveTimeout => {
261+
DispatchItem::Stop(DispReason::KeepAliveTimeout) => {
263262
log::warn!(
264263
"{}: did not receive pong response in time, closing connection",
265264
self.connection.tag(),
@@ -273,7 +272,7 @@ where
273272
)
274273
.await
275274
}
276-
DispatchItem::ReadTimeout => {
275+
DispatchItem::Stop(DispReason::ReadTimeout) => {
277276
log::warn!(
278277
"{}: did not receive complete frame in time, closing connection",
279278
self.connection.tag(),
@@ -287,12 +286,12 @@ where
287286
)
288287
.await
289288
}
290-
DispatchItem::Disconnect(err) => {
289+
DispatchItem::Stop(DispReason::Io(err)) => {
291290
let streams = self.connection.disconnect();
292291
self.handle_connection_error(streams, OperationError::Disconnected);
293292
control(Control::peer_gone(err), &self.inner, ctx).await
294293
}
295-
DispatchItem::WBackPressureEnabled | DispatchItem::WBackPressureDisabled => Ok(None),
294+
DispatchItem::Control(_) => Ok(None),
296295
}
297296
}
298297
}
@@ -346,10 +345,10 @@ where
346345
{
347346
match ctx.call(inner.control.get_ref(), pkt).await {
348347
Ok(res) => {
349-
if let Some(Frame::Reset(ref rst)) = res.frame {
350-
if !rst.stream_id().is_zero() {
351-
inner.connection.rst_stream(rst.stream_id(), rst.reason());
352-
}
348+
if let Some(Frame::Reset(ref rst)) = res.frame
349+
&& !rst.stream_id().is_zero()
350+
{
351+
inner.connection.rst_stream(rst.stream_id(), rst.reason());
353352
}
354353
if let Some(frm) = res.frame {
355354
inner.connection.encode(frm);

src/frame/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl Settings {
148148
}
149149

150150
// Ensure the payload length is correct, each setting is 6 bytes long.
151-
if payload.len() % 6 != 0 {
151+
if !payload.len().is_multiple_of(6) {
152152
log::debug!("invalid settings payload length; len={:?}", payload.len());
153153
return Err(FrameError::InvalidPayloadAckSettings);
154154
}

src/frame/stream_id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ impl StreamId {
4343
/// was initiated by the client.
4444
pub const fn is_client_initiated(&self) -> bool {
4545
let id = self.0;
46-
id != 0 && id % 2 == 1
46+
id != 0 && !id.is_multiple_of(2)
4747
}
4848

4949
/// Returns true if this stream ID corresponds to a stream that
5050
/// was initiated by the server.
5151
pub const fn is_server_initiated(&self) -> bool {
5252
let id = self.0;
53-
id != 0 && id % 2 == 0
53+
id != 0 && id.is_multiple_of(2)
5454
}
5555

5656
/// Return a new `StreamId` for stream 0.

src/hpack/table.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,11 @@ impl Table {
469469
let mut first_ideal = 0;
470470

471471
for (i, pos) in self.indices.iter().enumerate() {
472-
if let Some(pos) = *pos {
473-
if 0 == probe_distance(self.mask, pos.hash, i) {
474-
first_ideal = i;
475-
break;
476-
}
472+
if let Some(pos) = *pos
473+
&& 0 == probe_distance(self.mask, pos.hash, i)
474+
{
475+
first_ideal = i;
476+
break;
477477
}
478478
}
479479

0 commit comments

Comments
 (0)