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();
else if (cnt > 0)
{
doSomething(buf[0..cnt]);
yield();
}
}
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 probably something
wrong with the design. I would suggest you put all the
filedescriptors into a fd_set an then select(3) on the set.