-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlib.rs
More file actions
91 lines (79 loc) · 2.82 KB
/
lib.rs
File metadata and controls
91 lines (79 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#![deny(unsafe_op_in_unsafe_fn)]
#[cfg(target_os = "solid_asp3")]
solid::staticenv! {
"TMPDIR" => r"\OSCOM_FS\tmp",
// Increase the default stack size used by `std::thread::spawn`
// (Debug builds are stack-hungry)
"RUST_MIN_STACK" => "125536",
}
/// The root task entry point
#[no_mangle]
extern "C" fn slo_main() {
std::panic::resume_unwind(
std::thread::Builder::new()
// Rocket's startup code is very stack-heavy
.stack_size(256 * 1024)
.spawn(rust_entry_inner)
.expect("failed to spawn a thread")
.join()
.err()
.unwrap(),
);
}
fn rust_entry_inner() {
env_logger::Builder::new()
.filter_level(log::LevelFilter::Info)
.init();
// Initialize Tokio
let rt = tokio::runtime::Builder::new_multi_thread()
.worker_threads(solid::abi::SOLID_CORE_MAX)
.thread_name("tokio worker")
.on_thread_start(|| {
#[cfg(target_os = "solid_asp3")]
{
// Distribute the worker threads across all processors
use std::sync::atomic::{AtomicUsize, Ordering};
static TID: AtomicUsize = AtomicUsize::new(0);
let thread_index = TID.fetch_add(1, Ordering::Relaxed);
let i = thread_index % solid::abi::SOLID_CORE_MAX;
itron::task::current()
.unwrap()
.as_ref()
.migrate(itron::processor::Processor::from_raw(i as i32 + 1).unwrap())
.unwrap();
}
})
.max_blocking_threads(20)
.enable_all()
.build()
.unwrap();
// Start HTTP server
rt.block_on(server_loop());
}
// ----------------------------------------------------------------------------
// HTTP Server
// ----------------------------------------------------------------------------
#[macro_use]
extern crate rocket;
/// Start an HTTP server on the current async task. This async function will never complete.
async fn server_loop() -> ! {
let config = rocket::Config {
address: [0, 0, 0, 0].into(),
port: 8080,
temp_dir: r"\OSCOM_FS\tmp".into(),
..Default::default()
};
let _rocket = rocket::custom(&config)
.mount("/hello", routes![world])
.launch()
.await
.expect("web server failed to start");
panic!("web server exited unexpectedly");
}
// ----------------------------------------------------------------------------
// Request Handlers
// ----------------------------------------------------------------------------
#[get("/world")]
fn world() -> &'static str {
"Hello, world!"
}