Skip to content

Commit

Permalink
fix(plugin): blocking reading from std
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Feb 14, 2024
1 parent 0a37020 commit d29a851
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fmt:
$(CC) fmt --all

check:
@make default
$(CC) test -- --show-output

example:
Expand Down
10 changes: 4 additions & 6 deletions plugin/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,12 @@ impl<'a, T: 'a + Clone> Plugin<T> {
// 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) {

Check warning on line 274 in plugin/src/plugin.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant pattern matching, consider using `is_ok()`

warning: redundant pattern matching, consider using `is_ok()` --> plugin/src/plugin.rs:274:19 | 274 | while let Ok(_) = reader.read_line(&mut buffer) { | ----------^^^^^-------------------------------- help: try: `while reader.read_line(&mut buffer).is_ok()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching = note: `#[warn(clippy::redundant_pattern_matching)]` on by default
let req_str = buffer.to_string();
if req_str.trim().is_empty() {
continue;
}
buffer.clear();
let request: Request<serde_json::Value> = serde_json::from_str(&req_str).unwrap();
let Ok(request) = serde_json::from_str::<Request<serde_json::Value>>(&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);
Expand Down

0 comments on commit d29a851

Please sign in to comment.