From e28d34a9e78efb9fa05e314fe4e5f4cdb896442b Mon Sep 17 00:00:00 2001 From: tiye Date: Sun, 25 Feb 2024 17:43:56 +0800 Subject: [PATCH 1/2] upgrade edn to fix; tag 0.2.2 --- Cargo.lock | 13 ++++++++----- Cargo.toml | 5 ++--- build.sh | 8 +++++--- src/lib.rs | 33 ++++++++++++++++++--------------- 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f9b5dfb..1b08cf1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,7 +62,7 @@ checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" [[package]] name = "calcit_wss" -version = "0.2.1" +version = "0.2.2" dependencies = [ "cirru_edn", "lazy_static", @@ -77,9 +77,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cirru_edn" -version = "0.5.4" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fedb67d87075cec51cc76323ebceb2e177c157ab06b4111e37849e5e15f5db7" +checksum = "08d343bd5f40a4d0c77552307fa1d4a1457ebdafe988a5a478c8b15b59b89087" dependencies = [ "bincode", "cirru_parser", @@ -89,9 +89,12 @@ dependencies = [ [[package]] name = "cirru_parser" -version = "0.1.24" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c942c2dafb7e7cab267b66e6ccbb0b4ef11a471b83c90a9e072cdd02d2081aa" +checksum = "c96247e15778d471f8c94b321fa11220dfb987546fcf8fb73b1a5c2b3a018a78" +dependencies = [ + "bincode", +] [[package]] name = "cpufeatures" diff --git a/Cargo.toml b/Cargo.toml index 76c9041..12613f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "calcit_wss" -version = "0.2.1" +version = "0.2.2" authors = ["jiyinyiyong "] edition = "2021" @@ -13,7 +13,6 @@ crate-type = ["dylib"] # Creates dynamic lib # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cirru_edn = "0.5.4" +cirru_edn = "0.6.2" lazy_static = "1.4.0" simple-websockets = "0.1.6" - diff --git a/build.sh b/build.sh index 1144082..fd63aa9 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,6 @@ -rm -rfv dylibs/ -cargo build --release -mkdir -p dylibs/ && ls target/release/ && cp -v target/release/*.* dylibs/ +rm -rfv dylibs/ && \ +cargo build --release && \ +mkdir -p dylibs/ && \ +ls target/release/ && \ +cp -v target/release/*.* dylibs/ diff --git a/src/lib.rs b/src/lib.rs index ff404f0..a98a25e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -use cirru_edn::Edn; +use cirru_edn::{Edn, EdnTupleView}; use lazy_static::lazy_static; use simple_websockets::{Event, Message, Responder}; use std::collections::HashMap; @@ -21,7 +21,7 @@ pub fn wss_serve( _finish: Box, ) -> Result { let port = match args.first() { - Some(Edn::Map(m)) => match m.get(&Edn::tag("port")) { + Some(Edn::Map(m)) => match m.get("port") { Some(Edn::Number(n)) => n.floor().round() as u16, Some(a) => return Err(format!("Unknown port: {}", a)), None => 9001, @@ -44,7 +44,10 @@ pub fn wss_serve( let mut clients = CLIENTS.write().unwrap(); clients.insert(client_id, responder); } - if let Err(e) = handler(vec![Edn::Tuple(Arc::new(Edn::tag("connect")), vec![Edn::Number(client_id as f64)])]) { + if let Err(e) = handler(vec![Edn::Tuple(EdnTupleView { + tag: Arc::new(Edn::tag("connect")), + extra: vec![Edn::Number(client_id as f64)], + })]) { println!("Failed to handle connect: {}", e) } } @@ -54,27 +57,27 @@ pub fn wss_serve( let mut clients = CLIENTS.write().unwrap(); clients.remove(&client_id); } - if let Err(e) = handler(vec![Edn::Tuple( - Arc::new(Edn::tag("disconnect")), - vec![Edn::Number(client_id as f64)], - )]) { + if let Err(e) = handler(vec![Edn::Tuple(EdnTupleView { + tag: Arc::new(Edn::tag("disconnect")), + extra: vec![Edn::Number(client_id as f64)], + })]) { println!("Failed to handle disconnect: {}", e) } } Event::Message(client_id, message) => match message { Message::Text(s) => { - if let Err(e) = handler(vec![Edn::Tuple( - Arc::new(Edn::tag("message")), - vec![Edn::Number(client_id as f64), Edn::Str(s.into())], - )]) { + if let Err(e) = handler(vec![Edn::Tuple(EdnTupleView { + tag: Arc::new(Edn::tag("message")), + extra: vec![Edn::Number(client_id as f64), Edn::Str(s.into())], + })]) { println!("Failed to handle text message: {}", e) } } Message::Binary(buf) => { - if let Err(e) = handler(vec![Edn::Tuple( - Arc::new(Edn::tag("blob")), - vec![Edn::Number(client_id as f64), Edn::Buffer(buf)], - )]) { + if let Err(e) = handler(vec![Edn::Tuple(EdnTupleView { + tag: Arc::new(Edn::tag("blob")), + extra: vec![Edn::Number(client_id as f64), Edn::Buffer(buf)], + })]) { println!("Failed to handle binary message: {}", e) } } From 2b5a2eed5a3f8e9d9a03e8d65fe19d1c4a2f520b Mon Sep 17 00:00:00 2001 From: tiye Date: Sun, 25 Feb 2024 17:58:44 +0800 Subject: [PATCH 2/2] fix getting port; tag 0.2.3 --- Cargo.lock | 6 +++--- Cargo.toml | 4 ++-- calcit.cirru | 2 +- src/lib.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1b08cf1..0c1b1bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,7 +62,7 @@ checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" [[package]] name = "calcit_wss" -version = "0.2.2" +version = "0.2.3" dependencies = [ "cirru_edn", "lazy_static", @@ -77,9 +77,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cirru_edn" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d343bd5f40a4d0c77552307fa1d4a1457ebdafe988a5a478c8b15b59b89087" +checksum = "b4e435d0f66a1d16f727720f46a89c7a203e306bf466483ba5ff65903fd0f05c" dependencies = [ "bincode", "cirru_parser", diff --git a/Cargo.toml b/Cargo.toml index 12613f6..6cd47ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "calcit_wss" -version = "0.2.2" +version = "0.2.3" authors = ["jiyinyiyong "] edition = "2021" @@ -13,6 +13,6 @@ crate-type = ["dylib"] # Creates dynamic lib # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cirru_edn = "0.6.2" +cirru_edn = "0.6.3" lazy_static = "1.4.0" simple-websockets = "0.1.6" diff --git a/calcit.cirru b/calcit.cirru index 5af7971..6f61ef0 100644 --- a/calcit.cirru +++ b/calcit.cirru @@ -101,7 +101,7 @@ |j $ %{} :Expr (:at 1634969741701) (:by |u0) :data $ {} |T $ %{} :Leaf (:at 1634969743184) (:by |u0) (:text |:port) - |j $ %{} :Leaf (:at 1635317855022) (:by |u0) (:text |9001) + |j $ %{} :Leaf (:at 1708855103612) (:by |u0) (:text |9001) |r $ %{} :Expr (:at 1634969749769) (:by |u0) :data $ {} |T $ %{} :Leaf (:at 1634969750160) (:by |u0) (:text |fn) diff --git a/src/lib.rs b/src/lib.rs index a98a25e..ff78ffb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ pub fn wss_serve( _finish: Box, ) -> Result { let port = match args.first() { - Some(Edn::Map(m)) => match m.get("port") { + Some(Edn::Map(m)) => match m.tag_get("port") { Some(Edn::Number(n)) => n.floor().round() as u16, Some(a) => return Err(format!("Unknown port: {}", a)), None => 9001,