|
@@ -1,19 +1,14 @@
|
|
-#![feature(core_intrinsics)]
|
|
|
|
-
|
|
|
|
-#[global_allocator]
|
|
|
|
-static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
|
|
|
|
|
+#![feature(core_intrinsics, asm)]
|
|
|
|
+#![feature(start, lang_items)]
|
|
|
|
+#![allow(clippy::missing_safety_doc, unused_imports, dead_code)]
|
|
|
|
|
|
|
|
+use core::intrinsics::likely;
|
|
use faf::const_concat_bytes;
|
|
use faf::const_concat_bytes;
|
|
-use faf::const_config::*;
|
|
|
|
use faf::const_http::*;
|
|
use faf::const_http::*;
|
|
-use faf::extern_http_date;
|
|
|
|
use faf::util::{const_len, memcmp};
|
|
use faf::util::{const_len, memcmp};
|
|
-use std::intrinsics::likely;
|
|
|
|
|
|
|
|
-const ROUTE_PLAINTEXT: &[u8] = b"/p";
|
|
|
|
|
|
+const ROUTE_PLAINTEXT: &[u8] = b"/plaintext";
|
|
const ROUTE_PLAINTEXT_LEN: usize = const_len(ROUTE_PLAINTEXT);
|
|
const ROUTE_PLAINTEXT_LEN: usize = const_len(ROUTE_PLAINTEXT);
|
|
-// const ROUTE_JSON: &[u8] = b"/j";
|
|
|
|
-// const ROUTE_JSON_LEN: usize = const_len(ROUTE_JSON);
|
|
|
|
|
|
|
|
const TEXT_PLAIN_CONTENT_TYPE: &[u8] = b"Content-Type: text/plain";
|
|
const TEXT_PLAIN_CONTENT_TYPE: &[u8] = b"Content-Type: text/plain";
|
|
const CONTENT_LENGTH: &[u8] = b"Content-Length: ";
|
|
const CONTENT_LENGTH: &[u8] = b"Content-Length: ";
|
|
@@ -35,35 +30,30 @@ const PLAINTEXT_BASE: &[u8] = const_concat_bytes!(
|
|
|
|
|
|
const PLAINTEXT_BASE_LEN: usize = const_len(PLAINTEXT_BASE);
|
|
const PLAINTEXT_BASE_LEN: usize = const_len(PLAINTEXT_BASE);
|
|
|
|
|
|
|
|
+const PLAINTEXT_TEST: &[u8] = b"HTTP/1.1 200 OK\r\nServer: F\r\nContent-Type: text/plain\r\nContent-Length: 13\r\nDate: Thu, 18 Nov 2021 23:15:07 GMT\r\n\r\nHello, World!";
|
|
|
|
+const PLAINTEXT_TEST_LEN: usize = const_len(PLAINTEXT_TEST);
|
|
|
|
+
|
|
#[inline]
|
|
#[inline]
|
|
fn cb(
|
|
fn cb(
|
|
- method: *const i8,
|
|
|
|
|
|
+ method: *const u8,
|
|
method_len: usize,
|
|
method_len: usize,
|
|
- path: *const i8,
|
|
|
|
|
|
+ path: *const u8,
|
|
path_len: usize,
|
|
path_len: usize,
|
|
- _headers: &[faf::phr_header; MAX_HEADERS_TO_PARSE],
|
|
|
|
- _num_headers: usize,
|
|
|
|
response_buffer: *mut u8,
|
|
response_buffer: *mut u8,
|
|
|
|
+ date_buff: *const u8,
|
|
) -> usize {
|
|
) -> usize {
|
|
unsafe {
|
|
unsafe {
|
|
if likely(method_len >= GET_LEN && path_len >= ROUTE_PLAINTEXT_LEN) {
|
|
if likely(method_len >= GET_LEN && path_len >= ROUTE_PLAINTEXT_LEN) {
|
|
- if likely(memcmp(GET.as_ptr() as *const i8, method, GET_LEN) == 0) {
|
|
|
|
- // For performance purposes, this will successfully match '/p' to '/plaintext' and '/pickle'. Use with caution
|
|
|
|
- if likely(memcmp(ROUTE_PLAINTEXT.as_ptr() as *const i8, path, ROUTE_PLAINTEXT_LEN) == 0) {
|
|
|
|
- let mut date_buff = crate::extern_http_date::get_buff_with_date();
|
|
|
|
- extern_http_date::get_http_date(&mut date_buff);
|
|
|
|
- std::ptr::copy_nonoverlapping(PLAINTEXT_BASE.as_ptr(), response_buffer, PLAINTEXT_BASE_LEN);
|
|
|
|
- std::ptr::copy_nonoverlapping(
|
|
|
|
- date_buff.as_ptr(),
|
|
|
|
- response_buffer.add(PLAINTEXT_BASE_LEN),
|
|
|
|
- DATE_LEN,
|
|
|
|
- );
|
|
|
|
- std::ptr::copy_nonoverlapping(
|
|
|
|
|
|
+ if likely(memcmp(GET.as_ptr(), method, GET_LEN) == 0) {
|
|
|
|
+ if likely(memcmp(ROUTE_PLAINTEXT.as_ptr(), path, ROUTE_PLAINTEXT_LEN) == 0) {
|
|
|
|
+ core::ptr::copy_nonoverlapping(PLAINTEXT_BASE.as_ptr(), response_buffer, PLAINTEXT_BASE_LEN);
|
|
|
|
+ core::ptr::copy_nonoverlapping(date_buff, response_buffer.add(PLAINTEXT_BASE_LEN), DATE_LEN);
|
|
|
|
+ core::ptr::copy_nonoverlapping(
|
|
CRLFCRLF.as_ptr(),
|
|
CRLFCRLF.as_ptr(),
|
|
response_buffer.add(PLAINTEXT_BASE_LEN + DATE_LEN),
|
|
response_buffer.add(PLAINTEXT_BASE_LEN + DATE_LEN),
|
|
CRLFCRLF_LEN,
|
|
CRLFCRLF_LEN,
|
|
);
|
|
);
|
|
- std::ptr::copy_nonoverlapping(
|
|
|
|
|
|
+ core::ptr::copy_nonoverlapping(
|
|
PLAINTEXT_BODY.as_ptr(),
|
|
PLAINTEXT_BODY.as_ptr(),
|
|
response_buffer.add(PLAINTEXT_BASE_LEN + DATE_LEN + CRLFCRLF_LEN),
|
|
response_buffer.add(PLAINTEXT_BASE_LEN + DATE_LEN + CRLFCRLF_LEN),
|
|
PLAINTEXT_BODY_LEN,
|
|
PLAINTEXT_BODY_LEN,
|
|
@@ -71,19 +61,11 @@ fn cb(
|
|
|
|
|
|
PLAINTEXT_BASE_LEN + DATE_LEN + CRLFCRLF_LEN + PLAINTEXT_BODY_LEN
|
|
PLAINTEXT_BASE_LEN + DATE_LEN + CRLFCRLF_LEN + PLAINTEXT_BODY_LEN
|
|
} else {
|
|
} else {
|
|
- std::ptr::copy_nonoverlapping(
|
|
|
|
- HTTP_404_NOTFOUND.as_ptr(),
|
|
|
|
- response_buffer,
|
|
|
|
- HTTP_404_NOTFOUND_LEN,
|
|
|
|
- );
|
|
|
|
|
|
+ core::ptr::copy_nonoverlapping(HTTP_404_NOTFOUND.as_ptr(), response_buffer, HTTP_404_NOTFOUND_LEN);
|
|
HTTP_404_NOTFOUND_LEN
|
|
HTTP_404_NOTFOUND_LEN
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- std::ptr::copy_nonoverlapping(
|
|
|
|
- HTTP_405_NOTALLOWED.as_ptr(),
|
|
|
|
- response_buffer,
|
|
|
|
- HTTP_405_NOTALLOWED_LEN,
|
|
|
|
- );
|
|
|
|
|
|
+ core::ptr::copy_nonoverlapping(HTTP_405_NOTALLOWED.as_ptr(), response_buffer, HTTP_405_NOTALLOWED_LEN);
|
|
HTTP_405_NOTALLOWED_LEN
|
|
HTTP_405_NOTALLOWED_LEN
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -92,7 +74,6 @@ fn cb(
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-#[inline]
|
|
|
|
-fn main() {
|
|
|
|
|
|
+pub fn main() {
|
|
faf::epoll::go(8089, cb);
|
|
faf::epoll::go(8089, cb);
|
|
}
|
|
}
|