diff --git a/frameworks/wtx-ws/Cargo.lock b/frameworks/wtx-ws/Cargo.lock index 8ca67756f..9cd3b2739 100644 --- a/frameworks/wtx-ws/Cargo.lock +++ b/frameworks/wtx-ws/Cargo.lock @@ -4,15 +4,15 @@ version = 4 [[package]] name = "bytes" -version = "1.11.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" +checksum = "8ae3f5d315924270530207e2a68396c3cc547f6dca3fbdca317cfb1a51edb593" [[package]] name = "cc" -version = "1.2.63" +version = "1.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556e016178bb5662a08681bbe0f00f8e17631781a4dfc8c45e466e4b185ec27f" +checksum = "e228eec9be7c17ccb640b59b36a5cd805ea2a564a4c5e162c2f659fea30d3b96" dependencies = [ "find-msvc-tools", "shlex", @@ -24,12 +24,29 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "core_affinity" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a034b3a7b624016c6e13f5df875747cc25f884156aad2abd12b6c46797971342" +dependencies = [ + "libc", + "num_cpus", + "winapi", +] + [[package]] name = "find-msvc-tools" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + [[package]] name = "getrandom" version = "0.2.17" @@ -41,6 +58,21 @@ dependencies = [ "wasi", ] +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hermit-abi" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" + [[package]] name = "httparena-wtx-ws" version = "0.1.0" @@ -63,9 +95,9 @@ checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" [[package]] name = "memchr" -version = "2.8.1" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8" +checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4" [[package]] name = "mio" @@ -78,6 +110,16 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "num_cpus" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "pin-project-lite" version = "0.2.17" @@ -95,9 +137,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.45" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368" dependencies = [ "proc-macro2", ] @@ -140,9 +182,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.117" +version = "2.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422" dependencies = [ "proc-macro2", "quote", @@ -193,6 +235,28 @@ version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-link" version = "0.2.1" @@ -284,9 +348,11 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "wtx" version = "0.47.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "058059db60e3186c453dc17c81dc1e359ccd4baa9f9fa6e84e95959ffccdb76a" +source = "git+https://github.com/c410-f3r/wtx?branch=misc#a7851d4f61c374eeee832df394a07279669efb8d" dependencies = [ + "core_affinity", + "foldhash", + "hashbrown", "httparse", "memchr", "ring", @@ -294,15 +360,21 @@ dependencies = [ "socket2", "tokio", "wtx-macros", + "zlib-rs", ] [[package]] name = "wtx-macros" version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5c1e7897187f23097a7d1aadf7a76b834051471e8ce6d226513943c137c3acb" +source = "git+https://github.com/c410-f3r/wtx?branch=misc#a7851d4f61c374eeee832df394a07279669efb8d" dependencies = [ "proc-macro2", "quote", "syn", ] + +[[package]] +name = "zlib-rs" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "977347db8caa080403f6b6b7c1cda9479a8e869316f7e13a59b19076a40f94e3" diff --git a/frameworks/wtx-ws/Cargo.toml b/frameworks/wtx-ws/Cargo.toml index 6b2ee06cf..91e4ed0f1 100644 --- a/frameworks/wtx-ws/Cargo.toml +++ b/frameworks/wtx-ws/Cargo.toml @@ -5,7 +5,7 @@ edition = "2024" [dependencies] tokio = { default-features = false, features = ["macros", "rt-multi-thread"], version = "1.0" } -wtx = { default-features = false, features = ["crypto-ring", "optimizations", "optioned-server", "tokio", "web-socket-handshake"], version = "0.47" } +wtx = { default-features = false, features = ["crypto-ring", "optimizations-std", "tokio", "web-socket-server-framework"], git = "https://github.com/c410-f3r/wtx", branch = "misc" } [profile.release] codegen-units = 1 diff --git a/frameworks/wtx-ws/Dockerfile b/frameworks/wtx-ws/Dockerfile index 911e6816e..30fc37fb3 100644 --- a/frameworks/wtx-ws/Dockerfile +++ b/frameworks/wtx-ws/Dockerfile @@ -1,5 +1,5 @@ FROM rust:1.95 AS build -RUN rustup default nightly-2026-05-07 +RUN rustup default nightly-2026-06-27 WORKDIR /app COPY Cargo.toml . RUN mkdir src && echo "fn main() {}" > src/main.rs && cargo build --release && rm -rf src/ target/release/httparena-wtx-ws* target/release/deps/httparena_wtx-ws* diff --git a/frameworks/wtx-ws/meta.json b/frameworks/wtx-ws/meta.json index 8ce983da5..95a3d0104 100644 --- a/frameworks/wtx-ws/meta.json +++ b/frameworks/wtx-ws/meta.json @@ -1,7 +1,7 @@ { "display_name": "wtx", "language": "Rust", - "type": "engine", + "type": "emerging", "engine": "wtx", "description": "WTX - WebSocket Server", "repo": "https://github.com/c410-f3r/wtx", diff --git a/frameworks/wtx-ws/src/main.rs b/frameworks/wtx-ws/src/main.rs index d6964fed8..ae62f2522 100644 --- a/frameworks/wtx-ws/src/main.rs +++ b/frameworks/wtx-ws/src/main.rs @@ -1,40 +1,24 @@ use tokio::net::TcpStream; use wtx::{ - collection::Vector, - http::OptionedServer, - rng::Xorshift64, - web_socket::{OpCode, WebSocket, WebSocketBuffer, WebSocketPayloadOrigin}, + collections::Vector, + executor::TokioExecutor, + http::WebSocketServerFramework, + tls::{TlsConfig, TlsModePlainText}, + web_socket::{OpCode, WebSocket, WebSocketPayloadOrigin}, }; -fn main() { - let threads = std::thread::available_parallelism().map(|el| el.get()).unwrap_or(1); - let mut handlers = Vector::new(); - for _ in 0..threads { - let handle = std::thread::spawn(move || { - tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async { - let cb = (|| Ok(()), |_, stream| async move { Ok(stream) }); - let _el = OptionedServer::web_socket_tokio("0.0.0.0:8080", || {}, |_| {}, handle, cb).await; - }); - }); - handlers.push(handle).unwrap(); - } - for handle in handlers { - handle.join().unwrap(); - } +type LocalWebSocket = WebSocket<(), TcpStream, TlsModePlainText, false>; + +fn main() -> wtx::Result<()> { + WebSocketServerFramework::new(TokioExecutor::default(), TlsConfig::empty().into())? + .run_in_threads("0.0.0.0:8080", (("/ws", ws),)) } -async fn handle( - path: String, - mut ws: WebSocket<(), Xorshift64, TcpStream, WebSocketBuffer, false>, -) -> wtx::Result<()> { - if path != "/ws" { - return Ok(()); - } +async fn ws(mut buffer: Vector, mut ws: LocalWebSocket) -> wtx::Result<()> { let (mut common, mut reader, mut writer) = ws.split_mut(); - let payload_origin = WebSocketPayloadOrigin::Adaptive; - let mut buffer = path.into_bytes().into(); loop { - let Ok(mut frame) = reader.read_frame(&mut buffer, &mut common, payload_origin).await else { + let origin = WebSocketPayloadOrigin::Adaptive; + let Ok(mut frame) = reader.read_frame(&mut buffer, &mut common, origin).await else { return Ok(()); }; match frame.op_code() {