Post Go back to editing

epoll()

I've tried all the examples in the man pages and several of my own version of using epoll on a '/sys/class/gpio/gpioXX/value' file and none of it seems to work.  I do have support compiled into my kernel.  Does anyone have a small working example for me to try?

    int n;

    int epfd = epoll_create(1);

    int fd = open("/sys/class/gpio/gpio56/value", O_RDONLY );//| O_NONBLOCK);

    printf("open returned %d: %s\n", fd, strerror(errno));

    if(fd > 0) {

        char buf = 0;


        struct epoll_event ev;

        struct epoll_event events;

        ev.events = EPOLLPRI;

        ev.data.fd = fd;


        n = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev);

        printf("epoll_ctl returned %d: %s\n", n, strerror(errno));


        while(1) {

               n = epoll_wait(epfd, &events, 1, -1);

            printf("epoll returned %d: %s\n", n, strerror(errno));


            if(n > 0) {

                n = lseek(events.data.fd, 0, SEEK_SET);

                printf("seek %d bytes: %s\n", n, strerror(errno));

                while(n = read(events.data.fd, &buf, 1)){

                    printf("read %d bytes: %s\n", n, strerror(errno));

                    printf("buf = 0x%x\n", buf);

                }

                printf("epoll_ctl returned %d: %s\n", n, strerror(errno));

            }

        }

    }

Parents Reply Children
No Data