epoll_wait () запускается для стандартного ввода только после нажатия клавиши ввода - PullRequest
0 голосов
/ 03 марта 2019

События epoll_wait () срабатывают только при нажатии клавиши ввода на терминале gnome.Как заставить это работать, не нажимая клавишу ввода?Следующий код демонстрирует это поведение.

#include <sys/epoll.h>
#include <stdio.h>
#include <unistd.h>

int main(void)
{
    char buffer[10];
    int stdinfd = 0;
    struct epoll_event event;
    event.events = EPOLLIN;
    event.data.fd = 0;
    int epollfd = epoll_create(1);
    if (epollfd == -1) {
        printf("Failure to create epoll object");
        exit(-1);
    }
    if (epoll_ctl(epollfd, EPOLL_CTL_ADD, stdinfd, &event) == -1) {
        printf("unable to epoll_ctrl\n");
        exit(-2);
    }
    printf("Entering for loop\n");
    for (;;) {
        int epoll_return = epoll_wait(epollfd, &event, 1, 1000/* 1 sec timout */);
    printf("epoll_wait() = %d\n", epoll_return);
        if (epoll_return < 1) {
      continue;
    }
    printf("event->events: %d\n", event.events);
    int read_bytes = read(stdinfd, buffer, sizeof(buffer));
    printf("read bytes: %d\n", read_bytes);
    printf("first character: %c\n", buffer[0]);
    }
}
...