c - Is it possible to use event file descriptor in combination with interrupt-driven input? -


here smallest possible example (error checking , signal safety overlooked intentionally):

#include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <signal.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/eventfd.h> #include <stdio.h> #include <sys/wait.h>  void reader(int a) {   printf("hello!\n");   wait(null);   exit(exit_success); }  int main() {   signal(sigio, reader);   int efd = eventfd(0, efd_nonblock);   fcntl(efd, f_setown, getpid());   int flags;   flags= fcntl(efd, f_getfl);   fcntl(efd, f_setfl, flags | o_async);    pid_t p = fork();   if (p)   {     for(;;)       pause();   }   else    {     uint64_t buff = 1;     if (write(efd, &buff, sizeof(buff)) == -1)       printf("write error\n");     exit(exit_success);   } } 

this code should generate sigio in parent, after child writes event file descriptor, not. i've tried remove efd_nonblock eventfd system call , i've got same behaviour. here goes couple of questions.

is correct way of handling interrupt-driven i/o?

can interrupt-driven i/o used in combination event file descriptors , how?

eventfd file descriptor doesn't support o_async flag.

it seems man open(2) describes current implementors of o_async functionality:

this feature available terminals, pseudoterminals, sockets, , (since linux 2.6) pipes , fifos.

generally, if o_async flag not supported concrete file, silently ignored. 1 may check whether flag successfully set followed f_getfl:

// try set flag int flags; flags= fcntl(efd, f_getfl); fcntl(efd, f_setfl, flags | o_async); // check whether flag set int new_flags = fcntl(efd, f_getfl); if(!(new_flags & o_async)) {     // failed set flag. } 

there suggestions fcntl return error, if 1 want set o_async flag not supported particular file. this mailing 1 of them. according current implementation of kernel's function setfl them has been rejected:

if (((arg ^ filp->f_flags) & fasync) && filp->f_op->fasync) 

(fasync synonim o_async, ->fasync callback, if exists, implements changing of flag concrete file).


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -