Thread overview
Non-blocking reads of a fifo (named pipe)?
Dec 04
Basile B.
December 03
I have a fifo that I want to read lines from, but everything is blocking.

execute([ "mkfifo", filename ]);
File fifo = File(filename, "r");  // blocks already
immutable input = fifo.readln();  // blocks
foreach (line; fifo.byLineCopy) { /* blocks */ }

How can I go about doing this to get non-blocking reads? Or perhaps a way to test whether there is text waiting in the fifo? File.eof is not it.

if (fifo.hasData)
{
    immutable stuff = fifo.readln();
    // ...
}
December 03
On Mon, Dec 03, 2018 at 11:32:10PM +0000, Anonymouse via Digitalmars-d-learn wrote:
> I have a fifo that I want to read lines from, but everything is blocking.
> 
> execute([ "mkfifo", filename ]);
> File fifo = File(filename, "r");  // blocks already
> immutable input = fifo.readln();  // blocks
> foreach (line; fifo.byLineCopy) { /* blocks */ }
> 
> How can I go about doing this to get non-blocking reads? Or perhaps a way to test whether there is text waiting in the fifo? File.eof is not it.
> 
> if (fifo.hasData)
> {
>     immutable stuff = fifo.readln();
>     // ...
> }

I assume you're using Posix?  In which case, you should take a look at the `select` or `epoll` system calls. Cf. core.sys.posix.sys.select.

Or possibly `fcntl` (search for O_NONBLOCK), or call `open` directly
with O_NONBLOCK.

There's no common cross-platform way to do this, so generally you have to write your own code to handle it.


T

-- 
Music critic: "That's an imitation fugue!"
December 04
On Monday, 3 December 2018 at 23:32:10 UTC, Anonymouse wrote:
> I have a fifo that I want to read lines from, but everything is blocking.
> [...]
> How can I go about doing this to get non-blocking reads? Or perhaps a way to test whether there is text waiting in the fifo? File.eof is not it.
> [...]

I did this i think for my AsyncProcess class. It was a while ago and i never used it but IIRC it seemed to work on linux (not on Windows still IIRC)

https://github.com/BBasile/iz/blob/master/import/iz/classes.d#L1584