Re: non-block reading from pipe stdout

2017-10-03 Thread Oleg B via Digitalmars-d-learn
On Tuesday, 3 October 2017 at 12:32:43 UTC, kdevel wrote: IMHO a program should sleep (consume 0 CPU time and 0 energy) if there is nothing to process. This is best accomplished by not polling on a file descriptor in order to check if data has arrived. If your program must yield() there's

Re: non-block reading from pipe stdout

2017-10-03 Thread kdevel via Digitalmars-d-learn
On Tuesday, 3 October 2017 at 12:20:09 UTC, Oleg B wrote: while (!tryWait(pp.pid).terminated) { auto cnt = read(fd, buf.ptr, buf.length); // C-style reading if (cnt == -1 && errno == EAGAIN) // C-style error checking yield();

Re: non-block reading from pipe stdout

2017-10-03 Thread Oleg B via Digitalmars-d-learn
On Tuesday, 3 October 2017 at 10:45:21 UTC, kdevel wrote: On Tuesday, 3 October 2017 at 00:22:28 UTC, Oleg B wrote: but get error "Resource temporarily unavailable". You get EAGAIN because there is no data available at the time of reading. From the manpage of read: ERRORS EAGAIN

Re: non-block reading from pipe stdout

2017-10-03 Thread kdevel via Digitalmars-d-learn
On Tuesday, 3 October 2017 at 11:36:28 UTC, Oleg B wrote: EAGAIN Non-blocking I/O has been selected using O_NONBLOCK and no data was immediately available for reading. And I can't check this without using exception handling? Your programm shall not read before data is

Re: non-block reading from pipe stdout

2017-10-03 Thread Oleg B via Digitalmars-d-learn
On Tuesday, 3 October 2017 at 10:45:21 UTC, kdevel wrote: On Tuesday, 3 October 2017 at 00:22:28 UTC, Oleg B wrote: but get error "Resource temporarily unavailable". You get EAGAIN because there is no data available at the time of reading. From the manpage of read: ERRORS EAGAIN

Re: non-block reading from pipe stdout

2017-10-03 Thread kdevel via Digitalmars-d-learn
On Tuesday, 3 October 2017 at 00:22:28 UTC, Oleg B wrote: but get error "Resource temporarily unavailable". You get EAGAIN because there is no data available at the time of reading. From the manpage of read: ERRORS EAGAIN Non-blocking I/O has been selected using O_NONBLOCK and no

non-block reading from pipe stdout

2017-10-02 Thread Oleg B via Digitalmars-d-learn
Hello. I run program through std.process.pipeShell and want to read from it stdout in loop. How do this non-blocking? I try int fd = p.stdout.fileno; int flags = fcntl(fd, F_GETFL, 0); flags |= O_NONBLOCK; fcntl(fd, F_SETFL, flags); but get error "Resource