From cd21cff29942f24ba7d38287186cce64d0e84e56 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 18 Aug 2022 17:35:02 +0530 Subject: feat(ext/flash): An optimized http/1.1 server (#15405) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartek IwaƄczuk Co-authored-by: Ben Noordhuis Co-authored-by: crowlkats Co-authored-by: Ryan Dahl --- runtime/ops/http.rs | 23 ++++++++++++++++++++++- runtime/ops/io.rs | 10 ++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'runtime/ops') diff --git a/runtime/ops/http.rs b/runtime/ops/http.rs index 67d939976..7a58da361 100644 --- a/runtime/ops/http.rs +++ b/runtime/ops/http.rs @@ -27,7 +27,11 @@ use tokio::net::UnixStream; pub fn init() -> Extension { Extension::builder() - .ops(vec![op_http_start::decl(), op_http_upgrade::decl()]) + .ops(vec![ + op_http_start::decl(), + op_http_upgrade::decl(), + op_flash_upgrade_http::decl(), + ]) .build() } @@ -78,6 +82,23 @@ fn op_http_start( Err(bad_resource_id()) } +#[op] +fn op_flash_upgrade_http( + state: &mut OpState, + token: u32, + server_id: u32, +) -> Result { + let flash_ctx = state.borrow_mut::(); + let ctx = flash_ctx.servers.get_mut(&server_id).unwrap(); + + let tcp_stream = deno_flash::detach_socket(ctx, token)?; + Ok( + state + .resource_table + .add(TcpStreamResource::new(tcp_stream.into_split())), + ) +} + #[derive(Serialize)] #[serde(rename_all = "camelCase")] pub struct HttpUpgradeResult { diff --git a/runtime/ops/io.rs b/runtime/ops/io.rs index 2dcb9964a..900be1034 100644 --- a/runtime/ops/io.rs +++ b/runtime/ops/io.rs @@ -582,6 +582,16 @@ impl Resource for StdFileResource { fn write(self: Rc, buf: ZeroCopyBuf) -> AsyncResult { Box::pin(self.write(buf)) } + + #[cfg(unix)] + fn backing_fd(self: Rc) -> Option { + use std::os::unix::io::AsRawFd; + self + .with_inner_and_metadata(move |std_file, _| { + Ok(std_file.with_file(|f| f.as_raw_fd())) + }) + .ok() + } } // override op_print to use the stdout and stderr in the resource table -- cgit v1.2.3