Use updated Service trait for ntex

This commit is contained in:
Nikolay Kim 2024-11-04 13:15:31 +05:00
parent 5f6600c814
commit ce1bf97068
10 changed files with 63 additions and 9 deletions

View file

@ -131,6 +131,7 @@ bitflags::bitflags! {
const KA_ENABLED = 0b00100;
const KA_TIMEOUT = 0b01000;
const READ_TIMEOUT = 0b10000;
const READY = 0b100000;
}
}
@ -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!(

View file

@ -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

View file

@ -1,6 +1,6 @@
[package]
name = "ntex"
version = "2.7.0"
version = "2.8.0"
authors = ["ntex contributors <team@ntex.rs>"]
description = "Framework for composable network services"
readme = "README.md"
@ -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"

View file

@ -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};
@ -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;
@ -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 {

View file

@ -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
}

View file

@ -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;
@ -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();

View file

@ -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();

View file

@ -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;
@ -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();

View file

@ -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;
@ -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>,

View file

@ -494,6 +494,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>,