From fb2aeb79a113e576ff2cc4f1bf3fc30741969508 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Sun, 21 Aug 2022 21:27:14 +0900 Subject: fix(ext/flash): fix listening port (#15519) --- ext/flash/01_http.js | 4 ++-- ext/flash/lib.rs | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'ext') diff --git a/ext/flash/01_http.js b/ext/flash/01_http.js index d850a1520..e8debd5ec 100644 --- a/ext/flash/01_http.js +++ b/ext/flash/01_http.js @@ -216,8 +216,8 @@ const serverId = core.ops.op_flash_serve(opts); const serverPromise = core.opAsync("op_flash_drive_server", serverId); - core.opAsync("op_flash_wait_for_listening", serverId).then(() => { - onListen({ hostname: opts.hostname, port: opts.port }); + core.opAsync("op_flash_wait_for_listening", serverId).then((port) => { + onListen({ hostname: opts.hostname, port }); }); const server = { diff --git a/ext/flash/lib.rs b/ext/flash/lib.rs index 92350db58..de0a2231c 100644 --- a/ext/flash/lib.rs +++ b/ext/flash/lib.rs @@ -76,7 +76,7 @@ pub struct ServerContext { rx: mpsc::Receiver, requests: HashMap, next_token: u32, - listening_rx: Option>, + listening_rx: Option>, close_tx: mpsc::Sender<()>, cancel_handle: Rc, } @@ -939,7 +939,7 @@ pub struct ListenOpts { fn run_server( tx: mpsc::Sender, - listening_tx: mpsc::Sender<()>, + listening_tx: mpsc::Sender, mut close_rx: mpsc::Receiver<()>, addr: SocketAddr, maybe_cert: Option, @@ -971,7 +971,9 @@ fn run_server( } }; - listening_tx.blocking_send(()).unwrap(); + listening_tx + .blocking_send(listener.local_addr().unwrap().port()) + .unwrap(); let mut sockets = HashMap::with_capacity(1000); let mut counter: usize = 1; let mut events = Events::with_capacity(1024); @@ -1274,7 +1276,7 @@ where fn op_flash_wait_for_listening( state: &mut OpState, server_id: u32, -) -> Result> + 'static, AnyError> { +) -> Result> + 'static, AnyError> { let mut listening_rx = { let flash_ctx = state.borrow_mut::(); let server_ctx = flash_ctx @@ -1284,8 +1286,8 @@ fn op_flash_wait_for_listening( server_ctx.listening_rx.take().unwrap() }; Ok(async move { - listening_rx.recv().await; - Ok(()) + let port = listening_rx.recv().await.unwrap(); + Ok(port) }) } -- cgit v1.2.3