1
1
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
- use logger:: error;
5
4
use std:: io:: { Read , Write } ;
6
5
use std:: os:: unix:: io:: AsRawFd ;
7
6
use std:: os:: unix:: io:: RawFd ;
@@ -15,7 +14,7 @@ use crate::request::Request;
15
14
use crate :: response:: { Response , StatusCode } ;
16
15
use std:: collections:: HashMap ;
17
16
18
- use utils :: epoll;
17
+ use vmm_sys_util :: epoll;
19
18
20
19
static SERVER_FULL_ERROR_MESSAGE : & [ u8 ] = b"HTTP/1.1 503\r \n \
21
20
Server: Firecracker API\r \n \
@@ -310,7 +309,7 @@ impl HttpServer {
310
309
// current thread until at least one event is received.
311
310
// The received notifications will then populate the `events` array with
312
311
// `event_count` elements, where 1 <= event_count <= MAX_CONNECTIONS.
313
- let event_count = match self . epoll . wait ( MAX_CONNECTIONS , -1 , & mut events[ ..] ) {
312
+ let event_count = match self . epoll . wait ( -1 , & mut events[ ..] ) {
314
313
Ok ( event_count) => event_count,
315
314
Err ( e) if e. raw_os_error ( ) == Some ( libc:: EINTR ) => 0 ,
316
315
Err ( e) => return Err ( ServerError :: IOError ( e) ) ,
@@ -403,11 +402,11 @@ impl HttpServer {
403
402
}
404
403
405
404
// Remove dead connections.
406
- let epoll_fd = self . epoll_fd ;
405
+ let epoll = & self . epoll ;
407
406
self . connections . retain ( |rawfd, client_connection| {
408
407
if client_connection. is_done ( ) {
409
408
// The rawfd should have been registered to the epoll fd.
410
- Self :: epoll_del ( epoll_fd , * rawfd) . unwrap ( ) ;
409
+ Self :: epoll_del ( epoll , * rawfd) . unwrap ( ) ;
411
410
false
412
411
} else {
413
412
true
@@ -429,8 +428,6 @@ impl HttpServer {
429
428
if let ServerError :: ConnectionError ( ConnectionError :: InvalidWrite ) = e {
430
429
// Nothing is logged since an InvalidWrite means we have successfully
431
430
// flushed the connection
432
- } else {
433
- error ! ( "Connection write error: {}" , e) ;
434
431
}
435
432
break ;
436
433
}
@@ -450,7 +447,7 @@ impl HttpServer {
450
447
/// use std::os::unix::io::AsRawFd;
451
448
///
452
449
/// use micro_http::{HttpServer, Response, StatusCode};
453
- /// use utils ::epoll;
450
+ /// use vmm_sys_util ::epoll;
454
451
///
455
452
/// // Create our epoll manager.
456
453
/// let epoll = epoll::Epoll::new().unwrap();
@@ -476,7 +473,7 @@ impl HttpServer {
476
473
/// // Control loop of the application.
477
474
/// let mut events = Vec::with_capacity(10);
478
475
/// loop {
479
- /// let num_ev = epoll.wait(10, -1, events.as_mut_slice());
476
+ /// let num_ev = epoll.wait(-1, events.as_mut_slice());
480
477
/// for event in events {
481
478
/// match event.data() {
482
479
/// // The server notification.
@@ -596,14 +593,14 @@ impl HttpServer {
596
593
}
597
594
598
595
/// Removes a stream to the `epoll` notification structure.
599
- fn epoll_del ( epoll_fd : RawFd , stream_fd : RawFd ) -> Result < ( ) > {
600
- epoll:: ctl (
601
- epoll_fd ,
602
- epoll:: ControlOptions :: EPOLL_CTL_DEL ,
603
- stream_fd,
604
- epoll:: Event :: new ( epoll:: Events :: EPOLLIN , stream_fd as u64 ) ,
605
- )
606
- . map_err ( ServerError :: IOError )
596
+ fn epoll_del ( epoll : & epoll :: Epoll , stream_fd : RawFd ) -> Result < ( ) > {
597
+ epoll
598
+ . ctl (
599
+ epoll:: ControlOperation :: Delete ,
600
+ stream_fd,
601
+ epoll:: EpollEvent :: new ( epoll:: EventSet :: IN , stream_fd as u64 ) ,
602
+ )
603
+ . map_err ( ServerError :: IOError )
607
604
}
608
605
}
609
606
@@ -615,7 +612,7 @@ mod tests {
615
612
use std:: os:: unix:: net:: UnixStream ;
616
613
617
614
use crate :: common:: Body ;
618
- use utils :: tempfile:: TempFile ;
615
+ use vmm_sys_util :: tempfile:: TempFile ;
619
616
620
617
fn get_temp_socket_file ( ) -> TempFile {
621
618
let mut path_to_socket = TempFile :: new ( ) . unwrap ( ) ;
0 commit comments