Browse Source

ntex: upgrade to latest version (#6998)

* upgrade to letest ntex

* Update ntex-db.dockerfile
Nikolay Kim 3 years ago
parent
commit
3b3ec75b48

+ 1 - 1
frameworks/Rust/ntex/Cargo.toml

@@ -16,7 +16,7 @@ name = "ntex-raw"
 path = "src/main_raw.rs"
 
 [dependencies]
-ntex = "=0.5.0-b.1"
+ntex = "0.5.0-b.4"
 mimalloc = { version = "0.1.25", default-features = false }
 snmalloc-rs = { version = "0.2.26", features = ["1mib", "native-cpu"] }
 yarte = { version = "0.15", features = ["bytes-buf", "json"] }

+ 1 - 1
frameworks/Rust/ntex/ntex-db.dockerfile

@@ -1,4 +1,4 @@
-FROM rust:1.54.0
+FROM rust:1.57.0
 
 # Disable simd at jsonescape
 # ENV CARGO_CFG_JSONESCAPE_DISABLE_AUTO_SIMD=

+ 1 - 1
frameworks/Rust/ntex/ntex-raw.dockerfile

@@ -1,4 +1,4 @@
-FROM rust:1.54.0
+FROM rust:1.57.0
 
 # Disable simd at jsonescape
 # ENV CARGO_CFG_JSONESCAPE_DISABLE_AUTO_SIMD=

+ 1 - 1
frameworks/Rust/ntex/ntex.dockerfile

@@ -1,4 +1,4 @@
-FROM rust:1.54.0
+FROM rust:1.57.0
 
 # Disable simd at jsonescape
 # ENV CARGO_CFG_JSONESCAPE_DISABLE_AUTO_SIMD=

+ 2 - 5
frameworks/Rust/ntex/src/main_db.rs

@@ -18,8 +18,7 @@ mod utils;
 
 struct App(db::PgConnection);
 
-impl Service for App {
-    type Request = Request;
+impl Service<Request> for App {
     type Response = Response;
     type Error = Error;
     type Future = Pin<Box<dyn Future<Output = Result<Response, Error>>>>;
@@ -77,9 +76,7 @@ impl Service for App {
 
 struct AppFactory;
 
-impl ServiceFactory for AppFactory {
-    type Config = ();
-    type Request = Request;
+impl ServiceFactory<Request> for AppFactory {
     type Response = Response;
     type Error = Error;
     type Service = App;

+ 37 - 31
frameworks/Rust/ntex/src/main_raw.rs

@@ -2,7 +2,7 @@
 static GLOBAL: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
 use std::{future::Future, io, pin::Pin, task::Context, task::Poll};
 
-use ntex::{fn_service, http::h1, io::Io, util::ready, util::BufMut, util::PoolId};
+use ntex::{fn_service, http::h1, io::Io, io::RecvError, util::ready, util::BufMut, util::PoolId};
 mod utils;
 
 #[cfg(target_os = "macos")]
@@ -32,38 +32,44 @@ impl Future for App {
     fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
         let this = self.as_mut().get_mut();
         loop {
-            if let Some(Ok((req, _))) = ready!(this.io.poll_read_next(&this.codec, cx)) {
-                let _ = this.io.with_write_buf(|buf| {
-                    // make sure we've got room
-                    let remaining = buf.remaining_mut();
-                    if remaining < 1024 {
-                        buf.reserve(65535 - remaining);
-                    }
-
-                    match req.path() {
-                        "/json" => {
-                            buf.extend_from_slice(JSON);
-                            this.codec.set_date_header(buf);
-                            let _ = simd_json::to_writer(
-                                crate::utils::Writer(buf),
-                                &Message {
-                                    message: "Hello, World!",
-                                },
-                            );
-                        }
-                        "/plaintext" => {
-                            buf.extend_from_slice(PLAIN);
-                            this.codec.set_date_header(buf);
-                            buf.extend_from_slice(BODY);
+            match ready!(this.io.poll_recv(&this.codec, cx)) {
+                Ok((req, _)) => {
+                    let _ = this.io.with_write_buf(|buf| {
+                        // make sure we've got room
+                        let remaining = buf.remaining_mut();
+                        if remaining < 1024 {
+                            buf.reserve(65535 - remaining);
                         }
-                        _ => {
-                            buf.extend_from_slice(HTTPNFOUND);
-                            buf.extend_from_slice(HDR_SERVER);
+
+                        match req.path() {
+                            "/json" => {
+                                buf.extend_from_slice(JSON);
+                                this.codec.set_date_header(buf);
+                                let _ = simd_json::to_writer(
+                                    crate::utils::Writer(buf),
+                                    &Message {
+                                        message: "Hello, World!",
+                                    },
+                                );
+                            }
+                            "/plaintext" => {
+                                buf.extend_from_slice(PLAIN);
+                                this.codec.set_date_header(buf);
+                                buf.extend_from_slice(BODY);
+                            }
+                            _ => {
+                                buf.extend_from_slice(HTTPNFOUND);
+                                buf.extend_from_slice(HDR_SERVER);
+                            }
                         }
-                    }
-                });
-            } else {
-                return Poll::Ready(Ok(()));
+                    });
+                }
+                Err(RecvError::WriteBackpressure) => {
+                    let _ = ready!(this.io.poll_flush(cx, false));
+                }
+                Err(_) => {
+                    return Poll::Ready(Ok(()));
+                }
             }
         }
     }