micro_http: gracefully handle EINTR

EINTR errors should not break the HttpServer requests loop,
they are internally consumed and reported as no events rather
than requests errors.

Signed-off-by: Adrian Catangiu <acatan@amazon.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
This commit is contained in:
Adrian Catangiu
2020-03-17 23:25:09 +02:00
committed by Adrian Catangiu
parent 7eb11b44cb
commit d288940391
2 changed files with 6 additions and 4 deletions

View File

@@ -109,6 +109,7 @@
//! }
//! ```
extern crate libc;
extern crate utils;
mod common;

View File

@@ -302,10 +302,11 @@ impl HttpServer {
// current thread until at least one event is received.
// The received notifications will then populate the `events` array with
// `event_count` elements, where 1 <= event_count <= MAX_CONNECTIONS.
let event_count = self
.epoll
.wait(MAX_CONNECTIONS, -1, &mut events[..])
.map_err(ServerError::IOError)?;
let event_count = match self.epoll.wait(MAX_CONNECTIONS, -1, &mut events[..]) {
Ok(event_count) => event_count,
Err(e) if e.raw_os_error() == Some(libc::EINTR) => 0,
Err(e) => return Err(ServerError::IOError(e)),
};
// We use `take()` on the iterator over `events` as, even though only
// `events_count` events have been inserted into `events`, the size of
// the array is still `MAX_CONNECTIONS`, so we discard empty elements