Merge pull request #3352 from danilp-id/http_interrupt

Interrupts support for http server + other improvements
This commit is contained in:
Mark Thom
2026-06-03 13:36:21 -07:00
committed by GitHub
6 changed files with 132 additions and 33 deletions

View File

@@ -4690,6 +4690,16 @@ impl Machine {
try_or_throw!(self.machine_st, self.http_listen(), continue);
step_or_fail!(self.machine_st, self.machine_st.p = self.machine_st.cp);
}
&Instruction::CallHttpListenStop => {
#[cfg(feature = "http")]
try_or_throw!(self.machine_st, self.http_listen_stop(), continue);
step_or_fail!(self.machine_st, self.machine_st.p += 1);
}
&Instruction::ExecuteHttpListenStop => {
#[cfg(feature = "http")]
try_or_throw!(self.machine_st, self.http_listen_stop(), continue);
step_or_fail!(self.machine_st, self.machine_st.p = self.machine_st.cp);
}
&Instruction::CallHttpAccept => {
#[cfg(feature = "http")]
try_or_throw!(self.machine_st, self.http_accept(), continue);

View File

@@ -61,6 +61,7 @@ use std::str::FromStr;
use std::sync::LazyLock;
#[cfg(feature = "http")]
use std::sync::{Arc, Condvar, Mutex};
use tokio::sync::Notify;
use chrono::{offset::Local, DateTime};
#[cfg(not(target_arch = "wasm32"))]
@@ -4593,6 +4594,9 @@ impl Machine {
let (tx, rx) = std::sync::mpsc::sync_channel(1024);
// warp shutdown channel
let warp_shutdown = Arc::new(Notify::new());
let runtime = tokio::runtime::Handle::current();
let _guard = runtime.enter();
@@ -4654,16 +4658,35 @@ impl Machine {
},
);
let warp_shutdown_clone = warp_shutdown.clone();
runtime.spawn(async move {
match ssl_server {
Some((key, cert)) => {
warp::serve(serve).tls().key(key).cert(cert).run(addr).await
let (_addr, server) = warp::serve(serve)
.tls()
.key(key)
.cert(cert)
.bind_with_graceful_shutdown(addr, async move {
warp_shutdown_clone.notified().await;
});
tokio::task::spawn(server);
}
None => {
let (_addr, server) =
warp::serve(serve).bind_with_graceful_shutdown(addr, async move {
warp_shutdown_clone.notified().await;
});
tokio::task::spawn(server);
}
None => warp::serve(serve).run(addr).await,
}
});
let http_listener = HttpListener { incoming: rx };
let http_listener = HttpListener {
incoming: rx,
warp_shutdown: warp_shutdown,
};
let http_listener: TypedArenaPtr<HttpListener> =
arena_alloc!(http_listener, &mut self.machine_st.arena);
@@ -4676,6 +4699,30 @@ impl Machine {
Ok(())
}
#[cfg(feature = "http")]
#[inline(always)]
pub(crate) fn http_listen_stop(&mut self) -> CallResult {
let culprit = self.deref_register(1);
read_heap_cell!(culprit,
(HeapCellValueTag::Cons, cons_ptr) => {
match_untyped_arena_ptr!(cons_ptr,
(ArenaHeaderTag::HttpListener, http_listener) => {
http_listener.warp_shutdown.notify_one();
}
_ => {
unreachable!();
}
);
}
_ => {
unreachable!();
}
);
Ok(())
}
#[cfg(feature = "http")]
#[inline(always)]
pub(crate) fn http_accept(&mut self) -> CallResult {