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
This commit is contained in:
dot committed 2026-10-13 18:27:34 +09:00
1 parent e09846b4eb
commit a26d16113f
1 file changed
+9 -6
+9 -6
View File
@@ -408,19 +408,22 @@ mod _multiprocessing {
#[pyfunction] #[pyfunction]
fn recv(socket: usize, size: usize, vm: &VirtualMachine) -> PyResult<Vec<u8>> { fn recv(socket: usize, size: usize, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
let mut buf = let mut buf = vm
host_multiprocessing::recv_socket(socket as host_multiprocessing::RawSocket, size) .allow_threads(|| {
.map_err(|_| vm.new_last_os_error())?; host_multiprocessing::recv_socket(socket as host_multiprocessing::RawSocket, size)
})
.map_err(|error| error.to_pyexception(vm))?;
buf.shrink_to_fit(); buf.shrink_to_fit();
Ok(buf) Ok(buf)
} }
#[pyfunction] #[pyfunction]
fn send(socket: usize, buf: ArgBytesLike, vm: &VirtualMachine) -> PyResult<core::ffi::c_int> { fn send(socket: usize, buf: ArgBytesLike, vm: &VirtualMachine) -> PyResult<core::ffi::c_int> {
buf.with_ref(|b| { let buf = buf.borrow_buf_unlocked(vm)?;
host_multiprocessing::send_socket(socket as host_multiprocessing::RawSocket, b) vm.allow_threads(|| {
host_multiprocessing::send_socket(socket as host_multiprocessing::RawSocket, &buf)
}) })
.map_err(|_| vm.new_last_os_error()) .map_err(|error| error.to_pyexception(vm))
} }
} }