Skip to content
Advertisement

Linux asynchronous epoll() server having problems when EPOLLRDHUP occurrs

I’m trying to make an asynchronous web server using epoll() in Linux, but problems occur whenever the event EPOLLRDHUP occurs. When the flag EPOLLONESHOT is not set, the server tries to process a useless event (not EPOLLIN or EPOLLOUT) multiple times during the loop without stopping, which causes the server to be come completely unresponsive (and require a restart). When the flag EPOLLONESHOT is set, the server simply becomes unresponsive for a short period of time (seconds) and then becomes responsive again (which still is not ideal). I’m unsure what could be causing this, since I close the socket whenever EPOLLRDHUP occurs. Here is my code:

JavaScript

Advertisement

Answer

This pattern here, which you use twice, is wrong:

JavaScript

You are setting the data.ptr to your local variable currentConnection (which is reused and overwritten all the time), when it really should point into your connections-array!

As far as I can see it, currentConnection should be a pointer type:

JavaScript

and the assignment later in your code should be like

JavaScript

You have to fix the struct member accesses of course and the setting of data.ptr like you do here:

JavaScript

shouldn’t be necessary at all.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement