topheman / snake-pipe-rust

🦀 A snake game based on stdin/stdout (+tcp and unix sockets) in rust
MIT License
12 stars 1 forks source link

Handle broken pipes #49

Open topheman opened 7 months ago

topheman commented 7 months ago

Reproduce:

Terminal 1: run snakepipe gamestate|snakepipe render-browser

Terminal 2: run snakepipe gamestate|snakepipe render-browser

In terminal 2, you get the error:

Error: port 8080 already in use
thread 'main' panicked at library/std/src/io/stdio.rs:1021:9:
failed printing to stdout: Broken pipe (os error 32)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Because

  1. the port 8080 is already in use (normal)
  2. Since snakepipe render-browser exit, its stdin doesn't exist anymore, so snakepipe gamestate can't write to it via its stdout

Maybe rely on https://crates.io/crates/calm_io

It might be a solution for https://github.com/topheman/snake-pipe-rust/issues/25

Example of use: