archive mirror
 help / color / mirror / Atom feed
From: Heiher <>
Subject: Why the edge-triggered mode doesn't work for epoll file descriptor?
Date: Sun, 18 Aug 2019 00:36:46 +0800	[thread overview]
Message-ID: <> (raw)


I've added a pipe file descriptor (fd1) to an epoll (fd3) with
EPOLLOUT in edge-triggered mode, and then added the fd3 to another
epoll (fd4) with EPOLLIN in edge-triggered too.

Next, waiting for fd4 without timeout. When fd1 to be writable, i
think epoll_wait(fd4, ...)  only return once, because all file
descriptors are added in edge-triggered mode.

But, the actual result is returns many and many times until do once
eopll_wait(fd3, ...).

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

main (int argc, char *argv[])
    int efd[2];
    struct epoll_event e;

    efd[0] = epoll_create (1);
    if (efd[0] < 0)
        return -1;

    efd[1] = epoll_create (1);
    if (efd[1] < 0)
        return -2; = EPOLLIN | EPOLLET; = 1;
    if (epoll_ctl (efd[0], EPOLL_CTL_ADD, efd[1], &e) < 0)
        return -3; = EPOLLOUT | EPOLLET; = 2;
    if (epoll_ctl (efd[1], EPOLL_CTL_ADD, 1, &e) < 0)
        return -4;

    for (;;) {
        struct epoll_event events[16];
        int nfds;

        nfds = epoll_wait (efd[0], events, 16, -1);
        printf ("nfds: %d\n", nfds);

    close (efd[1]);
    close (efd[0]);

    return 0;

Best regards!

             reply	other threads:[~2019-08-17 16:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-17 16:36 Heiher [this message]
2019-08-19  0:58 ` Heiher
2019-08-26  6:22 ` Eric Wong
2019-08-28 15:33   ` Heiher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='' \ \ \ \
    --subject='Re: Why the edge-triggered mode doesn'\''t work for epoll file descriptor?' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).