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

Function ConnectNamedPipe

crates/vm/src/stdlib/_winapi.rs:1046–1101  ·  view source on GitHub ↗
(args: ConnectNamedPipeArgs, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1044
1045 #[pyfunction]
1046 fn ConnectNamedPipe(args: ConnectNamedPipeArgs, vm: &VirtualMachine) -> PyResult<PyObjectRef> {
1047 use windows_sys::Win32::Foundation::{
1048 ERROR_IO_PENDING, ERROR_PIPE_CONNECTED, GetLastError,
1049 };
1050
1051 let handle = args.handle;
1052 let use_overlapped = args.overlapped.unwrap_or(false);
1053
1054 if use_overlapped {
1055 // Overlapped (async) mode
1056 let ov = Overlapped::new_with_handle(handle.0);
1057
1058 let _ret = {
1059 let mut inner = ov.inner.lock();
1060 unsafe {
1061 windows_sys::Win32::System::Pipes::ConnectNamedPipe(
1062 handle.0,
1063 &mut *inner.overlapped,
1064 )
1065 }
1066 };
1067
1068 let err = unsafe { GetLastError() };
1069 match err {
1070 ERROR_IO_PENDING => {
1071 let mut inner = ov.inner.lock();
1072 inner.pending = true;
1073 }
1074 ERROR_PIPE_CONNECTED => {
1075 let inner = ov.inner.lock();
1076 unsafe {
1077 windows_sys::Win32::System::Threading::SetEvent(inner.overlapped.hEvent);
1078 }
1079 }
1080 _ => {
1081 return Err(std::io::Error::from_raw_os_error(err as i32).to_pyexception(vm));
1082 }
1083 }
1084
1085 Ok(ov.into_pyobject(vm))
1086 } else {
1087 // Synchronous mode
1088 let ret = unsafe {
1089 windows_sys::Win32::System::Pipes::ConnectNamedPipe(handle.0, null_mut())
1090 };
1091
1092 if ret == 0 {
1093 let err = unsafe { GetLastError() };
1094 if err != ERROR_PIPE_CONNECTED {
1095 return Err(std::io::Error::from_raw_os_error(err as i32).to_pyexception(vm));
1096 }
1097 }
1098
1099 Ok(vm.ctx.none())
1100 }
1101 }
1102
1103 /// Helper for GetShortPathName and GetLongPathName

Callers 1

ConnectNamedPipeMethod · 0.85

Calls 7

noneMethod · 0.80
GetLastErrorFunction · 0.70
SetEventFunction · 0.70
ErrClass · 0.50
lockMethod · 0.45
to_pyexceptionMethod · 0.45
into_pyobjectMethod · 0.45

Tested by

no test coverage detected