MCPcopy Index your code
hub / github.com/RustPython/RustPython / getresult

Method getresult

crates/stdlib/src/overlapped.rs:466–564  ·  view source on GitHub ↗
(zelf: &Py<Self>, wait: OptionalArg<bool>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

464
465 #[pymethod]
466 fn getresult(zelf: &Py<Self>, wait: OptionalArg<bool>, vm: &VirtualMachine) -> PyResult {
467 use windows_sys::Win32::Foundation::{
468 ERROR_BROKEN_PIPE, ERROR_MORE_DATA, ERROR_SUCCESS,
469 };
470
471 let mut inner = zelf.inner.lock();
472 let wait = wait.unwrap_or(false);
473
474 // Check operation state
475 if matches!(inner.data, OverlappedData::None) {
476 return Err(vm.new_value_error("operation not yet attempted"));
477 }
478 if matches!(inner.data, OverlappedData::NotStarted) {
479 return Err(vm.new_value_error("operation failed to start"));
480 }
481
482 // Get the result
483 let mut transferred: u32 = 0;
484 let ret = unsafe {
485 windows_sys::Win32::System::IO::GetOverlappedResult(
486 inner.handle,
487 &inner.overlapped,
488 &mut transferred,
489 if wait { 1 } else { 0 },
490 )
491 };
492
493 let err = if ret != 0 {
494 ERROR_SUCCESS
495 } else {
496 unsafe { GetLastError() }
497 };
498 inner.error = err;
499
500 // Handle errors
501 match err {
502 ERROR_SUCCESS | ERROR_MORE_DATA => {}
503 ERROR_BROKEN_PIPE => {
504 let allow_broken_pipe = match &inner.data {
505 OverlappedData::Read(_) | OverlappedData::ReadInto(_) => true,
506 OverlappedData::ReadFrom(_) => true,
507 OverlappedData::ReadFromInto(rfi) => rfi.result.is_some(),
508 _ => false,
509 };
510 if !allow_broken_pipe {
511 return Err(set_from_windows_err(err, vm));
512 }
513 }
514 _ => return Err(set_from_windows_err(err, vm)),
515 }
516
517 // Return result based on operation type
518 match &mut inner.data {
519 OverlappedData::Read(buf) => {
520 let len = buf.as_bytes().len();
521 let result = if transferred as usize != len {
522 let resized = vm
523 .ctx

Callers 2

test_pipe_overlappedMethod · 0.95
test_popenMethod · 0.95

Calls 13

set_from_windows_errFunction · 0.85
unparse_addressFunction · 0.85
to_vecMethod · 0.80
ErrClass · 0.50
GetLastErrorFunction · 0.50
SomeClass · 0.50
lockMethod · 0.45
lenMethod · 0.45
as_bytesMethod · 0.45
new_bytesMethod · 0.45
cloneMethod · 0.45
new_tupleMethod · 0.45

Tested by 2

test_pipe_overlappedMethod · 0.76
test_popenMethod · 0.76