[Bug] epoll_wait return EPOLLOUT even with EPOLLET flag

Started by Robin Dong on Nov 17, 2011 · 3 messages from 3 authors · Last reply Nov 17, 2011

open the first message on its own page

Message details and related content
Hi,

I am a linux user and I found some question when using epoll with EPOLLET.

My program's step:

1. create a socket (sfd) and connect to server
2. create epoll (efd)
3. add socket descriptor (sfd) to epoll (efd) with flag EPOLLET
4. get a EPOLLOUT event through epoll_wait

After that, the program will nerver get a EPOLLOUT event because ituse
EPOLLET mode (the same event will not be got twice)

BUT,when a message comes from server,the client socket will get aevent
and this event contains EPOLLOUT and EPOLLIN, looks epoll_waitreturn
too much events than it should

My question is: Is this a bug for epoll ?

Any reply will be appreciate.

--
--
Best Regard
Robin Dong
Message details and related content
Le jeudi 17 novembre 2011 à 16:07 +0800, Robin Dong a écrit :
Hi,

I am a linux user and I found some question when using epoll with EPOLLET.

My program's step:

1. create a socket (sfd) and connect to server
2. create epoll (efd)
3. add socket descriptor (sfd) to epoll (efd) with flag EPOLLET
4. get a EPOLLOUT event through epoll_wait

After that, the program will nerver get a EPOLLOUT event because ituse
EPOLLET mode (the same event will not be got twice)
Its not true. Same "status" can be delivered several time.

Think about Edge and Level trigger. An event (change of status) is the
trigger.

As soon as on trigger is done, epoll delivers a status.

And your file status is indeed EPOLLOUT | EPOLLIN, since you can read or
write on it.

BUT,when a message comes from server,the client socket will get aevent
and this event contains EPOLLOUT and EPOLLIN, looks epoll_waitreturn
too much events than it should

My question is: Is this a bug for epoll ?
Not a bug, but a misinterpretation of what is an event and what is a
status.
Message details and related content
Robin Dong wrote:
Hi,

I am a linux user and I found some question when using epoll with EPOLLET.

My program's step:

1. create a socket (sfd) and connect to server
2. create epoll (efd)
3. add socket descriptor (sfd) to epoll (efd) with flag EPOLLET
4. get a EPOLLOUT event through epoll_wait

After that, the program will nerver get a EPOLLOUT event because ituse
EPOLLET mode (the same event will not be got twice)
Hi Robin,

With EPOLLET|EPOLLOUT, you should get a message from epoll whenever
the fd's status changes from "cannot output" to "can output".

So you should get a message when sfd transitions from write()
returning EAGAIN to write() accepting more data.

Until you get EAGAIN while writing, your program should assume the
socket is still writable.  "man epoll" has a few things to say about
this (look for all the places here it says EAGAIN).
BUT,when a message comes from server,the client socket will get aevent
and this event contains EPOLLOUT and EPOLLIN, looks epoll_waitreturn
too much events than it should
The message always contains the latest status, so says EPOLLOUT|EPOLLIN.

It's doesn't mean there's an EPOLLOUT "event", it just means a message
is triggered (by the socket becoming readable) so you get a status
update.  In theory the program doesn't need to be told about EPOLLOUT
here (it should be assuming the socket is writable already), but it
doesn't do any harm.

EPOLLET is just a way to reduce the number of messages from epoll when
you call epoll_wait().  In effect you are telling the kernel "don't
send me repeated status messages and I'll maintain my own flags".  But
it doesn't change the status value in messages that are sent.

Enjoy,
-- Jamie
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help