diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-09-28 11:52:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-28 20:52:24 +0200 |
commit | e2828ad762034a0e8d38387d4e5d38cafa409f13 (patch) | |
tree | 8c3996bdf75900fcfe8bd62d074c25c3797c3207 /ext/flash/lib.rs | |
parent | fcb20ab952fb78cd3069239a25f8e24d49cca541 (diff) |
fix(ext/flash): reregister socket on partial read on Windows (#16076)
Diffstat (limited to 'ext/flash/lib.rs')
-rw-r--r-- | ext/flash/lib.rs | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/ext/flash/lib.rs b/ext/flash/lib.rs index 65d52d083..0714e379d 100644 --- a/ext/flash/lib.rs +++ b/ext/flash/lib.rs @@ -987,22 +987,48 @@ fn run_server( // sockets.remove(&token); continue 'events; } - Ok(read) => match req.parse(&buffer[..offset + read]) { - Ok(httparse::Status::Complete(n)) => { - body_offset = n; - body_len = offset + read; - socket.parse_done = ParseStatus::None; - break; - } - Ok(httparse::Status::Partial) => { - socket.parse_done = ParseStatus::Ongoing(offset + read); - continue; - } - Err(_) => { - let _ = socket.write(b"HTTP/1.1 400 Bad Request\r\n\r\n"); - continue 'events; + Ok(read) => { + match req.parse(&buffer[..offset + read]) { + Ok(httparse::Status::Complete(n)) => { + body_offset = n; + body_len = offset + read; + socket.parse_done = ParseStatus::None; + // On Windows, We must keep calling socket.read() until it fails with WouldBlock. + // + // Mio tries to emulate edge triggered events on Windows. + // AFAICT it only rearms the event on WouldBlock, but it doesn't when a partial read happens. + // https://github.com/denoland/deno/issues/15549 + #[cfg(target_os = "windows")] + match &mut socket.inner { + InnerStream::Tcp(ref mut socket) => { + poll + .registry() + .reregister(socket, token, Interest::READABLE) + .unwrap(); + } + InnerStream::Tls(ref mut socket) => { + poll + .registry() + .reregister( + &mut socket.sock, + token, + Interest::READABLE, + ) + .unwrap(); + } + }; + break; + } + Ok(httparse::Status::Partial) => { + socket.parse_done = ParseStatus::Ongoing(offset + read); + continue; + } + Err(_) => { + let _ = socket.write(b"HTTP/1.1 400 Bad Request\r\n\r\n"); + continue 'events; + } } - }, + } Err(ref e) if e.kind() == std::io::ErrorKind::WouldBlock => { break 'events } |