Unregister fd from epoll_fd when closing a connection
When closing a http connection, the corresponding file descriptor should be unregistered from the epoll fd. Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
This commit is contained in:
committed by
Adrian Catangiu
parent
3832d38d8c
commit
31bc6268c7
@@ -367,8 +367,16 @@ impl HttpServer {
|
||||
}
|
||||
|
||||
// Remove dead connections.
|
||||
self.connections
|
||||
.retain(|_, client_connection| !client_connection.is_done());
|
||||
let epoll_fd = self.epoll_fd;
|
||||
self.connections.retain(|rawfd, client_connection| {
|
||||
if client_connection.is_done() {
|
||||
// The rawfd should have been registered to the epoll fd.
|
||||
Self::epoll_del(epoll_fd, *rawfd).unwrap();
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
});
|
||||
|
||||
Ok(parsed_requests)
|
||||
}
|
||||
@@ -518,6 +526,17 @@ impl HttpServer {
|
||||
)
|
||||
.map_err(ServerError::IOError)
|
||||
}
|
||||
|
||||
/// Removes a stream to the `epoll` notification structure.
|
||||
fn epoll_del(epoll_fd: RawFd, stream_fd: RawFd) -> Result<()> {
|
||||
epoll::ctl(
|
||||
epoll_fd,
|
||||
epoll::ControlOptions::EPOLL_CTL_DEL,
|
||||
stream_fd,
|
||||
epoll::Event::new(epoll::Events::EPOLLIN, stream_fd as u64),
|
||||
)
|
||||
.map_err(ServerError::IOError)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user