www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Linux blocked on file read on exit, need select

reply Darrell Gallion <dgallion1 gmail.com> writes:
Program is blocked on exit, because of a blocking file read.
I'd be glad to just kill it and exit.

In this case I'm using dinotify, I exposed the fd.
This issue is it's not working or blocked on exit.

Never mind the constant monitor.add

static immutable string stdoutFn="passFiles/vAppStdout";

void monitorStdout(){
   auto monitor = iNotify();
   Watch watch = monitor.add(stdoutFn.ptr, IN_ALL_EVENTS );

   timeval timeout={tv_sec:0, tv_usec:500000 };

   //int flags = fcntl(monitor.fd, F_GETFL, 0);
   //fcntl(monitor.fd, F_SETFL, flags | O_NONBLOCK);

     fd_set fdset;
     FD_SET(monitor.fd, &fdset);
     if(select(monitor.fd+1, &fdset, cast(fd_set*)null, 
cast(fd_set*)null, &timeout) ){
       auto events = monitor.read();
       watch = monitor.add(stdoutFn.ptr, IN_ALL_EVENTS );

   writeln("Exit monitor");
Mar 20 2016
parent cy <dlang verge.info.tm> writes:
I don't know, but you could always just use fcntl if you already 
can assume you're on Linux.

extern (C) int fcntl(int, int, int);

C keeps the constants under lock and key of course, so you have 
to specify them manually. But you could write a C program to 
print them out, or generate D code I suppose.

const int F_SETFL = 4
const int F_GETFL = 3
const int O_NONBLOCK = 2048
fcntl(fd,F_SETFL,O_NONBLOCK | fcntl(fd,F_GETFL,42));

not tested or anything.
Mar 20 2016