Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.development.system > #783
| X-Received | by 2002:a6b:6315:: with SMTP id p21-v6mr134616iog.43.1529043032688; Thu, 14 Jun 2018 23:10:32 -0700 (PDT) |
|---|---|
| X-Received | by 2002:aca:c456:: with SMTP id u83-v6mr15718oif.4.1529043032545; Thu, 14 Jun 2018 23:10:32 -0700 (PDT) |
| Path | csiph.com!xmission!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!d7-v6no1604585itj.0!news-out.google.com!z3-v6ni1838iti.0!nntp.google.com!d7-v6no1604584itj.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.os.linux.development.system |
| Date | Thu, 14 Jun 2018 23:10:32 -0700 (PDT) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=45.77.23.212; posting-account=D8RqywoAAAB9saFadYLhSvBbR5qn61-_ |
| NNTP-Posting-Host | 45.77.23.212 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <ffca76e7-36df-4ebd-8947-a4acd314de94@googlegroups.com> (permalink) |
| Subject | why epoll_wait delivers events more than once in ET mode on stdin |
| From | chenstrace <k54765254@gmail.com> |
| Injection-Date | Fri, 15 Jun 2018 06:10:32 +0000 |
| Content-Type | text/plain; charset="UTF-8" |
| Lines | 86 |
| Xref | csiph.com comp.os.linux.development.system:783 |
Show key headers only | View raw
As my expection, the following test code should only return from epoll_wait once, just like man page of epoll said:
"edge-triggered mode delivers events only when changes occur on the monitored file descriptor"
But in fact, the epoll_wait returned more than once, why?
#include <stdio.h>
#include <sys/epoll.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#define MAX_EVENTS 512
static char* get_epoll_events_str(uint32_t event);
int main(int argc, char *argv[]) {
int i,nfds;
struct epoll_event event;
struct epoll_event events[MAX_EVENTS];
int fd = STDIN_FILENO;
int epfd = epoll_create1(0);
if (epfd == -1) {
perror("epoll_create1");
exit(EXIT_FAILURE);
}
event.events = EPOLLOUT | EPOLLET;
event.data.u64 = 123;
int ret = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &event);
if (ret == -1) {
perror("epoll_ctl");
exit(EXIT_FAILURE);
}
while (1) {
nfds = epoll_wait(epfd, events, MAX_EVENTS, -1);
if (nfds == -1) {
perror("epoll_wait");
exit(EXIT_FAILURE);
}
printf("epoll_wait return %d\n", nfds);
for (i = 0; i < nfds; i++) {
char* str = get_epoll_events_str(events[i].events);
printf("%dth fd's data.u64=%lu,event is %s\n",i,events[i].data.u64,str);
free(str);
}
sleep(1);
}
return 0;
}
static char* get_epoll_events_str(uint32_t event) {
char str[4096] = {0};
if(event == 0)
{
return NULL;
}
if (event & EPOLLIN) strcat(str, "EPOLLIN,");
if (event & EPOLLPRI) strcat(str, "EPOLLPRI,");
if (event & EPOLLOUT) strcat(str, "EPOLLOUT,");
if (event & EPOLLRDNORM) strcat(str, "EPOLLRDNORM,");
if (event & EPOLLRDBAND) strcat(str, "EPOLLRDBAND,");
if (event & EPOLLWRNORM) strcat(str, "EPOLLWRNORM,");
if (event & EPOLLWRBAND) strcat(str, "EPOLLWRBAND,");
if (event & EPOLLMSG) strcat(str, "EPOLLMSG,");
if (event & EPOLLERR) strcat(str, "EPOLLERR,");
if (event & EPOLLHUP) strcat(str, "EPOLLHUP,");
if (event & EPOLLRDHUP) strcat(str, "EPOLLRDHUP,");
if (event & EPOLLWAKEUP) strcat(str, "EPOLLWAKEUP,");
if (event & EPOLLONESHOT) strcat(str, "EPOLLONESHOT,");
if (event & EPOLLET) strcat(str, "EPOLLET,");
if(strlen(str) == 0)
{
return NULL;
}
return strdup(str);
}
Back to comp.os.linux.development.system | Previous | Next — Next in thread | Find similar
why epoll_wait delivers events more than once in ET mode on stdin chenstrace <k54765254@gmail.com> - 2018-06-14 23:10 -0700 Re: why epoll_wait delivers events more than once in ET mode on stdin Rainer Weikusat <rweikusat@talktalk.net> - 2018-06-15 13:15 +0100
csiph-web