title: How to fix "Broken Pipe" error when trying to write a named pipe?
body: <p>I'm experimenting with named pipes in rust, and I want to create a server that receives the messages from a client that never ends.</p>
  <pre><code>//reciever.rs
  use libc::{c_char, mkfifo};
  use std::ffi::CString;
  use std::fs::OpenOptions;
  use std::io::Read;
  
  fn main() {
      let _ = std::fs::remove_file(&quot;rust-fifo&quot;);
      let name_fifo = CString::new(&quot;rust-fifo&quot;).unwrap();
      let name_fifo: *const c_char = name_fifo.as_ptr() as *const c_char;
  
      if unsafe { mkfifo(name_fifo, 0o644) } != 0 {
          panic!(&quot;Error creating fifo.&quot;)
      }
  
      loop {
          let mut file = OpenOptions::new().read(true).open(&quot;rust-fifo&quot;).unwrap();
          let mut buffer = Vec::new();
          file.read_to_end(&amp;mut buffer).unwrap();
          //println!(&quot;{:#?}&quot;, &amp;buffer);
          println!(&quot;{}&quot;, String::from_utf8(buffer).unwrap());
      }
  }
  
  </code></pre>
  <pre><code>//sender.rs
  use std::{fs::OpenOptions, io::Write};
  
  fn main() {
      loop {
          let mut file = OpenOptions::new().write(true).open(&quot;rust-fifo&quot;).expect(&quot;error opening the file&quot;);
          file.write_all(b&quot;hello&quot;).expect(&quot;error writing the file&quot;);//ERROR HERE &quot;BROKEN PIPE&quot;
      }
  }
  </code></pre>
  <p><code>receiver.rs</code> receives some messages but then <code>sender.rs</code> throws error,when not using the loop everything works fine, but i want to have a client that never ends, this is the error,why it happens?</p>
  <pre><code>thread 'main' panicked at 'error writing the file: Os { code: 32, kind: BrokenPipe, message: &quot;Broken pipe&quot; }', src/bin/sender.rs:6:34
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
  </code></pre>