Crates.io Build Status

unix-fifo-async

[WIP] Eases working with Unix named pipes (FIFOs) anywhere on the filesystem.

Because of the way this works currently, there's no real way to get a lock on the pipe, but there are convenience methods on both NamedPipePath and NamedPipeReader/NamedPipeWriter to ensure the pipe exists.

Example

Create a pipe, write to it in one async task and read from it in another:

```rust

use unixfifoasync::NamedPipePath; use async_std::task;

// Create a new pipe at the given path let pipe = NamedPipePath::new("./mypipe"); // This creates the path if it doesn't exist; it may return a nix::Error // You can also use the ensure_pipe_exists convenience method on // readers/writers, but calling it on both at the same time results // in a race condition so it can never succeed. pipe.ensureexists().unwrap(); // Create a writer and a reader on the path let writer = pipe.openwrite(); let reader = pipe.openread();

// Some data we can send over the pipe let datatosend = "Hello, pipes!";

// Spawn two tasks, one for writing to and one for reading from the pipe. let t1 = task::spawn(async move { writer.writestr(datatosend).await }); let t2 = task::spawn(async move { reader.readstring().await });

// .await both tasks and compare the result with the original t1.await?; let readresult = t2.await?; asserteq!(readresult, datato_send);

// Delete the pipe pipe.delete().await?; ```

Note that in practice, you'll probably want to read the pipe from a different process or have it read by an entirely different program.