Skip to contentSkip to conversation

unexpected extra pollout events from epoll

DISCUSSION Paul P 2 participants 4 messages Oct 27, 2008

lore
Share & tools
lore

Paul P

author
#0 lore raw
Quoted 4 lines

You do that by writing data until it's finished, or you get EAGAIN. If you
get EAGAIN, you listen for EPOLLOUT.
Reading is same, but you'd wait for EPOLLIN.

I've got a few questions about this approach. The most logical way to do this seems to be:

1) Leave the epoll_wait with the EPOLLIN|EPOLLOUT event flags and use epoll_ctl to switch the interest mask for each fd between EPOLLIN
and EPOLLOUT on a per fd basis.

2) When I'm ready to write, I do a write and if it does not fully write and I get the EAGAIN flag, I switch the fd with epoll_ctl(fd,MOD,EPOLLOUT).

However, I get strange behavior when I tried adding fd's with only the EPOLLIN interest mask. If I use epoll_wait with both the EPOLLIN and EPOLLOUT interest mask, but add fd's with only the EPOLLIN interest mask, I still seem to get EPOLLOUT events on the fd.

Am I supposed to change the main loop with epoll_wait so that when one socket is reading that I switch the main loop to get EPOLLOUT events? That means that I'm not receiving on any fd while I'm sending, so this probably isn't right.

So, I'm a little confused.

Thanks in advance.

Paul

#1 lore raw
Quoted 11 lines · Paul P
Quoted 4 lines

You do that by writing data until it's finished, or you get EAGAIN. If you
get EAGAIN, you listen for EPOLLOUT.
Reading is same, but you'd wait for EPOLLIN.

I've got a few questions about this approach. The most logical way to do this seems to be:

1) Leave the epoll_wait with the EPOLLIN|EPOLLOUT event flags and use epoll_ctl to switch the interest mask for each fd between EPOLLIN
and EPOLLOUT on a per fd basis.

Which version of epoll do you have? The epoll_wait() function does not accept an event mask (like you write above, EPOLLIN|EPOLLOUT). It never had.
But yes, you'd switch interest with epoll_ctl().

Quoted 2 lines

2) When I'm ready to write, I do a write and if it does not fully write and I get the EAGAIN flag, I switch the fd with epoll_ctl(fd,MOD,EPOLLOUT).

As optimization, if the EPOLLOUT bit is already set, you don't need to keep calling epoll_ctl(fd,MOD,EPOLLOUT).

Quoted 4 lines

However, I get strange behavior when I tried adding fd's with only the EPOLLIN interest mask. If I use epoll_wait with both the EPOLLIN and EPOLLOUT interest mask, but add fd's with only the EPOLLIN interest mask, I still seem to get EPOLLOUT events on the fd.

Again, how the heck do you "use epoll_wait with both the EPOLLIN and EPOLLOUT"?!? There is not such a thing.

Quoted 3 lines

So, I'm a little confused.

From the wording above, that doesn't seem like a wrong guess.

- Davide

#2 lore raw
Quoted 9 lines · Davide Libenzi
Quoted 4 lines · Paul P

However, I get strange behavior when I tried adding fd's with only the EPOLLIN interest mask. If I use epoll_wait with both the EPOLLIN and EPOLLOUT interest mask, but add fd's with only the EPOLLIN interest mask, I still seem to get EPOLLOUT events on the fd.

Again, how the heck do you "use epoll_wait with both the EPOLLIN and EPOLLOUT"?!? There is not such a thing.

Wait? It's not that you pass EPOLLIN or EPOLLOUT to the "maxevents" parameter of epoll_wait()?
That's the maximum event count you want to fetch, not an event mask.

- Davide

author
#3 lore raw
In reply to Davide Libenzi
Quoted 4 lines

Which version of epoll do you have? The epoll_wait() function does not
accept an event mask (like you write above, EPOLLIN|EPOLLOUT).

lol, I was a bit tired when I wrote that. Ok, ignore the stuff related to epoll_wait in my previous post.

Quoted 3 lines

As optimization, if the EPOLLOUT bit is already set, you don't need to
keep calling epoll_ctl(fd,MOD,EPOLLOUT).

This is good to know.

So, I've got a few questions about what happens to data that accumulates while I am sending and the fd is set to EPOLLOUT? If I am send out a large buffer and incoming data wants to stream in on a full duplex connection, what happens to that data when I am processing the socket while it is in epollout mode?

Is the following accurate? When data comes in while I am sending, I guess the data fills up the receive buffers until they are full and then it stops accepting data until it is cleared out? When I switch back to EPOLLIN, I'm guessing that I will get a notification on that fd that there is data waiting.

The other question I have is there a way to do full-duplex networking so that I can receive network messages while I am sending or vice versa? It seems that the method of switching the socket between EPOLLIN and EPOLLOUT means that I can't do both operations simultaneously. Thanks

Paul