⚡ Sangsakala Proxy 🏠 Home
Skip to content

Commit a26d161

Browse files
committed
Detach during blocking Windows multiprocessing socket I/O
Snapshot locked send buffers before waiting and preserve the host-captured Winsock error across VM reattachment. Assisted-by: OpenAI Codex: model identifier unavailable
1 parent e09846b commit a26d161

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎crates/stdlib/src/multiprocessing.rs‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,19 +408,22 @@ mod _multiprocessing {
408408

409409
#[pyfunction]
410410
fn recv(socket: usize, size: usize, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
411-
let mut buf =
412-
host_multiprocessing::recv_socket(socket as host_multiprocessing::RawSocket, size)
413-
.map_err(|_| vm.new_last_os_error())?;
411+
let mut buf = vm
412+
.allow_threads(|| {
413+
host_multiprocessing::recv_socket(socket as host_multiprocessing::RawSocket, size)
414+
})
415+
.map_err(|error| error.to_pyexception(vm))?;
414416
buf.shrink_to_fit();
415417
Ok(buf)
416418
}
417419

418420
#[pyfunction]
419421
fn send(socket: usize, buf: ArgBytesLike, vm: &VirtualMachine) -> PyResult<core::ffi::c_int> {
420-
buf.with_ref(|b| {
421-
host_multiprocessing::send_socket(socket as host_multiprocessing::RawSocket, b)
422+
let buf = buf.borrow_buf_unlocked(vm)?;
423+
vm.allow_threads(|| {
424+
host_multiprocessing::send_socket(socket as host_multiprocessing::RawSocket, &buf)
422425
})
423-
.map_err(|_| vm.new_last_os_error())
426+
.map_err(|error| error.to_pyexception(vm))
424427
}
425428
}
426429

0 commit comments

Comments
 (0)