From d29a851f3d28783a35bd1ff612bb4827efca9f6b Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Wed, 14 Feb 2024 13:46:31 +0100 Subject: [PATCH] fix(plugin): blocking reading from std Signed-off-by: Vincenzo Palazzo --- Makefile | 1 + plugin/src/plugin.rs | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 153198e..0b69518 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ fmt: $(CC) fmt --all check: + @make default $(CC) test -- --show-output example: diff --git a/plugin/src/plugin.rs b/plugin/src/plugin.rs index 280078f..a0db96a 100644 --- a/plugin/src/plugin.rs +++ b/plugin/src/plugin.rs @@ -271,14 +271,12 @@ impl<'a, T: 'a + Clone> Plugin { // FIXME: core lightning end with the double endline, so this can cause // problem for some input reader. // we need to parse the writer, and avoid this while loop - loop { - let _ = reader.read_line(&mut buffer); + while let Ok(_) = reader.read_line(&mut buffer) { let req_str = buffer.to_string(); - if req_str.trim().is_empty() { - continue; - } buffer.clear(); - let request: Request = serde_json::from_str(&req_str).unwrap(); + let Ok(request) = serde_json::from_str::>(&req_str) else { + continue; + }; if let Some(id) = request.id { // when the id is specified this is a RPC or Hook, so we need to return a response let response = self.call_rpc_method(&request.method, request.params);