Skip to content

Commit

Permalink
Use updated Service trait for ntex
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Nov 4, 2024
1 parent 5f6600c commit ce1bf97
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 9 deletions.
13 changes: 10 additions & 3 deletions ntex-io/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ bitflags::bitflags! {
const KA_ENABLED = 0b00100;
const KA_TIMEOUT = 0b01000;
const READ_TIMEOUT = 0b10000;
const READY = 0b100000;
}
}

Expand Down Expand Up @@ -471,13 +472,19 @@ where

fn poll_service(&mut self, cx: &mut Context<'_>) -> Poll<PollService<U>> {
// check service readiness
if self.shared.service.poll_not_ready(cx).is_pending() {
return Poll::Ready(self.check_error());
if self.flags.contains(Flags::READY) {
if self.shared.service.poll_not_ready(cx).is_pending() {
return Poll::Ready(self.check_error());
}
self.flags.remove(Flags::READY);
}

// wait until service becomes ready
match self.shared.service.poll_ready(cx) {
Poll::Ready(Ok(_)) => Poll::Ready(self.check_error()),
Poll::Ready(Ok(_)) => {
self.flags.insert(Flags::READY);
Poll::Ready(self.check_error())
}
// pause io read task
Poll::Pending => {
log::trace!(
Expand Down
4 changes: 4 additions & 0 deletions ntex/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## [2.8.0] - 2024-11-04

* Use updated Service trait

## [2.7.0] - 2024-10-16

* Better handling for h2 remote payload
Expand Down
4 changes: 2 additions & 2 deletions ntex/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex"
version = "2.7.0"
version = "2.8.0"
authors = ["ntex contributors <[email protected]>"]
description = "Framework for composable network services"
readme = "README.md"
Expand Down Expand Up @@ -73,7 +73,7 @@ ntex-h2 = "1.2"
ntex-rt = "0.4.19"
ntex-io = "2.8"
ntex-net = "2.4"
ntex-tls = "2.1"
ntex-tls = "2.3"

base64 = "0.22"
bitflags = "2"
Expand Down
12 changes: 11 additions & 1 deletion ntex/src/http/client/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ntex_h2::{self as h2};
use crate::connect::{Connect as TcpConnect, Connector as TcpConnector};
use crate::service::{apply_fn, boxed, Service, ServiceCtx};
use crate::time::{Millis, Seconds};
use crate::util::{join, timeout::TimeoutError, timeout::TimeoutService};
use crate::util::{join, select, timeout::TimeoutError, timeout::TimeoutService};
use crate::{http::Uri, io::IoBoxed};

use super::{connection::Connection, error::ConnectError, pool::ConnectionPool, Connect};
Expand Down Expand Up @@ -273,6 +273,7 @@ where
type Response = <ConnectionPool<T> as Service<Connect>>::Response;
type Error = ConnectError;

#[inline]
async fn ready(&self, ctx: ServiceCtx<'_, Self>) -> Result<(), Self::Error> {
if let Some(ref ssl_pool) = self.ssl_pool {
let (r1, r2) = join(ctx.ready(&self.tcp_pool), ctx.ready(ssl_pool)).await;
Expand All @@ -283,6 +284,15 @@ where
}
}

#[inline]
async fn not_ready(&self) {
if let Some(ref ssl_pool) = self.ssl_pool {
select(self.tcp_pool.not_ready(), ssl_pool.not_ready()).await;
} else {
self.tcp_pool.not_ready().await
}
}

async fn shutdown(&self) {
self.tcp_pool.shutdown().await;
if let Some(ref ssl_pool) = self.ssl_pool {
Expand Down
6 changes: 6 additions & 0 deletions ntex/src/http/client/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,16 @@ where
type Response = Connection;
type Error = ConnectError;

#[inline]
async fn ready(&self, _: ServiceCtx<'_, Self>) -> Result<(), Self::Error> {
self.connector.ready().await
}

#[inline]
async fn not_ready(&self) {
self.connector.not_ready().await
}

async fn shutdown(&self) {
self.connector.shutdown().await
}
Expand Down
8 changes: 7 additions & 1 deletion ntex/src/http/h1/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::http::error::{DispatchError, ResponseError};
use crate::http::{request::Request, response::Response};
use crate::io::{types, Filter, Io, IoRef};
use crate::service::{IntoServiceFactory, Service, ServiceCtx, ServiceFactory};
use crate::{channel::oneshot, util::join, util::HashSet};
use crate::{channel::oneshot, util::join, util::select, util::HashSet};

use super::control::{Control, ControlAck};
use super::default::DefaultControlService;
Expand Down Expand Up @@ -230,6 +230,12 @@ where
})
}

#[inline]
async fn not_ready(&self) {
let cfg = self.config.as_ref();
select(cfg.control.not_ready(), cfg.service.not_ready()).await;
}

async fn shutdown(&self) {
self.config.shutdown();

Expand Down
5 changes: 5 additions & 0 deletions ntex/src/http/h2/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ where
})
}

#[inline]
async fn not_ready(&self) {
self.config.service.not_ready().await;
}

#[inline]
async fn shutdown(&self) {
self.config.shutdown();
Expand Down
8 changes: 7 additions & 1 deletion ntex/src/http/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{cell::Cell, cell::RefCell, error, fmt, marker, rc::Rc};

use crate::io::{types, Filter, Io, IoRef};
use crate::service::{IntoServiceFactory, Service, ServiceCtx, ServiceFactory};
use crate::{channel::oneshot, util::join, util::HashSet};
use crate::{channel::oneshot, util::join, util::select, util::HashSet};

use super::body::MessageBody;
use super::builder::HttpServiceBuilder;
Expand Down Expand Up @@ -311,6 +311,12 @@ where
})
}

#[inline]
async fn not_ready(&self) {
let cfg = self.config.as_ref();
select(cfg.control.not_ready(), cfg.service.not_ready()).await;
}

#[inline]
async fn shutdown(&self) {
self.config.shutdown();
Expand Down
7 changes: 6 additions & 1 deletion ntex/src/web/app_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::router::{Path, ResourceDef, Router};
use crate::service::boxed::{self, BoxService, BoxServiceFactory};
use crate::service::dev::ServiceChainFactory;
use crate::service::{fn_service, Middleware, Service, ServiceCtx, ServiceFactory};
use crate::util::{join, BoxFuture, Extensions};
use crate::util::{join, select, BoxFuture, Extensions};

use super::config::AppConfig;
use super::error::ErrorRenderer;
Expand Down Expand Up @@ -301,6 +301,11 @@ where
ready2
}

#[inline]
async fn not_ready(&self) {
select(self.filter.not_ready(), self.routing.not_ready()).await;
}

async fn call(
&self,
req: WebRequest<Err>,
Expand Down
5 changes: 5 additions & 0 deletions ntex/src/web/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,11 @@ where
ready2
}

#[inline]
async fn not_ready(&self) {
select(self.filter.not_ready(), self.routing.not_ready()).await;

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / Clippy

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / Clippy

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / nightly - aarch64-apple-darwin

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / Clippy

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / Clippy

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / stable - aarch64-apple-darwin

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / stable - aarch64-apple-darwin

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / nightly - aarch64-apple-darwin

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / stable - aarch64-apple-darwin

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-unknown-linux-gnu

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-unknown-linux-gnu

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / 1.75.0 - x86_64-unknown-linux-gnu

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / 1.75.0 - x86_64-unknown-linux-gnu

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / nightly - x86_64-unknown-linux-gnu

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / nightly - x86_64-unknown-linux-gnu

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / 1.75.0 - x86_64-unknown-linux-gnu

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / 1.75.0 - x86_64-unknown-linux-gnu

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / coverage

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / coverage

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / coverage

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / coverage

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-unknown-linux-gnu

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-unknown-linux-gnu

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / coverage

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / coverage

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / coverage

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / coverage

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / nightly - x86_64-unknown-linux-gnu

cannot find function `select` in this scope

Check failure on line 499 in ntex/src/web/scope.rs

View workflow job for this annotation

GitHub Actions / nightly - x86_64-unknown-linux-gnu

cannot find function `select` in this scope
}

async fn call(
&self,
req: WebRequest<Err>,
Expand Down

0 comments on commit ce1bf97

Please sign in to comment.