Skip to content

Commit 9e6ab4b

Browse files
0x00A5acatangiu
authored andcommitted
Clean up after cherry-picking commits from firecracker
Signed-off-by: YUAN LYU <[email protected]>
1 parent e73f412 commit 9e6ab4b

File tree

6 files changed

+37
-34
lines changed

6 files changed

+37
-34
lines changed

Cargo.lock

Lines changed: 12 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ authors = ["Amazon Firecracker team <[email protected]>"]
66
edition = "2018"
77

88
[dependencies]
9-
epoll = ">=4.0.1"
9+
libc = ">=0.2.39"
10+
vmm-sys-util = ">=0.6.1"

src/common/headers.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,10 @@ mod tests {
534534
b"Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT\r\nContent-Length: -55\r\n\r\n"
535535
)
536536
.unwrap_err(),
537-
RequestError::InvalidHeader
537+
RequestError::HeaderError(HttpHeaderError::InvalidValue(
538+
"Content-Length".to_string(),
539+
" -55".to_string()
540+
))
538541
);
539542

540543
let bytes: [u8; 10] = [130, 140, 150, 130, 140, 150, 130, 140, 150, 160];

src/common/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ impl Display for ConnectionError {
134134

135135
/// Errors pertaining to `HttpRoute`.
136136
#[derive(Debug)]
137+
#[allow(dead_code)]
137138
pub enum RouteError {
138139
/// Handler for http routing path already exists.
139140
HandlerExist(String),

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ mod server;
115115
use crate::common::ascii;
116116
use crate::common::headers;
117117

118+
pub use self::router::{EndpointHandler, HttpRoutes, RouteError};
119+
pub use crate::common::headers::{Encoding, Headers, MediaType};
120+
pub use crate::common::{Body, HttpHeaderError, Method, Version};
118121
pub use crate::connection::{ConnectionError, HttpConnection};
119122
pub use crate::request::{Request, RequestError};
120123
pub use crate::response::{Response, ResponseHeaders, StatusCode};
121124
pub use crate::server::{HttpServer, ServerError, ServerRequest, ServerResponse};
122-
123-
pub use crate::common::headers::{Encoding, Headers, MediaType};
124-
pub use crate::common::{Body, HttpHeaderError, Method, Version};

src/server.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use logger::error;
54
use std::io::{Read, Write};
65
use std::os::unix::io::AsRawFd;
76
use std::os::unix::io::RawFd;
@@ -15,7 +14,7 @@ use crate::request::Request;
1514
use crate::response::{Response, StatusCode};
1615
use std::collections::HashMap;
1716

18-
use utils::epoll;
17+
use vmm_sys_util::epoll;
1918

2019
static SERVER_FULL_ERROR_MESSAGE: &[u8] = b"HTTP/1.1 503\r\n\
2120
Server: Firecracker API\r\n\
@@ -310,7 +309,7 @@ impl HttpServer {
310309
// current thread until at least one event is received.
311310
// The received notifications will then populate the `events` array with
312311
// `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[..]) {
314313
Ok(event_count) => event_count,
315314
Err(e) if e.raw_os_error() == Some(libc::EINTR) => 0,
316315
Err(e) => return Err(ServerError::IOError(e)),
@@ -403,11 +402,11 @@ impl HttpServer {
403402
}
404403

405404
// Remove dead connections.
406-
let epoll_fd = self.epoll_fd;
405+
let epoll = &self.epoll;
407406
self.connections.retain(|rawfd, client_connection| {
408407
if client_connection.is_done() {
409408
// 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();
411410
false
412411
} else {
413412
true
@@ -429,8 +428,6 @@ impl HttpServer {
429428
if let ServerError::ConnectionError(ConnectionError::InvalidWrite) = e {
430429
// Nothing is logged since an InvalidWrite means we have successfully
431430
// flushed the connection
432-
} else {
433-
error!("Connection write error: {}", e);
434431
}
435432
break;
436433
}
@@ -450,7 +447,7 @@ impl HttpServer {
450447
/// use std::os::unix::io::AsRawFd;
451448
///
452449
/// use micro_http::{HttpServer, Response, StatusCode};
453-
/// use utils::epoll;
450+
/// use vmm_sys_util::epoll;
454451
///
455452
/// // Create our epoll manager.
456453
/// let epoll = epoll::Epoll::new().unwrap();
@@ -476,7 +473,7 @@ impl HttpServer {
476473
/// // Control loop of the application.
477474
/// let mut events = Vec::with_capacity(10);
478475
/// loop {
479-
/// let num_ev = epoll.wait(10, -1, events.as_mut_slice());
476+
/// let num_ev = epoll.wait(-1, events.as_mut_slice());
480477
/// for event in events {
481478
/// match event.data() {
482479
/// // The server notification.
@@ -596,14 +593,14 @@ impl HttpServer {
596593
}
597594

598595
/// 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)
607604
}
608605
}
609606

@@ -615,7 +612,7 @@ mod tests {
615612
use std::os::unix::net::UnixStream;
616613

617614
use crate::common::Body;
618-
use utils::tempfile::TempFile;
615+
use vmm_sys_util::tempfile::TempFile;
619616

620617
fn get_temp_socket_file() -> TempFile {
621618
let mut path_to_socket = TempFile::new().unwrap();

0 commit comments

Comments
 (0)