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

Method ConnectEx

crates/stdlib/src/overlapped.rs:1008–1073  ·  view source on GitHub ↗
(
            zelf: &Py<Self>,
            socket: isize,
            address: PyTupleRef,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

1006 // ConnectEx
1007 #[pymethod]
1008 fn ConnectEx(
1009 zelf: &Py<Self>,
1010 socket: isize,
1011 address: PyTupleRef,
1012 vm: &VirtualMachine,
1013 ) -> PyResult {
1014 use windows_sys::Win32::Foundation::{ERROR_IO_PENDING, ERROR_SUCCESS};
1015 use windows_sys::Win32::Networking::WinSock::WSAGetLastError;
1016
1017 let mut inner = zelf.inner.lock();
1018 if !matches!(inner.data, OverlappedData::None) {
1019 return Err(vm.new_value_error("operation already attempted"));
1020 }
1021
1022 let (addr_bytes, addr_len) = parse_address(&address, vm)?;
1023
1024 inner.handle = socket as HANDLE;
1025 // Store addr_bytes in OverlappedData to keep it alive during async operation
1026 inner.data = OverlappedData::Connect(addr_bytes);
1027
1028 type ConnectExFn = unsafe extern "system" fn(
1029 s: usize,
1030 name: *const SOCKADDR,
1031 namelen: i32,
1032 lpSendBuffer: *const core::ffi::c_void,
1033 dwSendDataLength: u32,
1034 lpdwBytesSent: *mut u32,
1035 lpOverlapped: *mut OVERLAPPED,
1036 ) -> i32;
1037
1038 let connect_ex: ConnectExFn =
1039 unsafe { core::mem::transmute(*CONNECT_EX.get().unwrap()) };
1040
1041 // Get pointer to the stored address data
1042 let addr_ptr = match &inner.data {
1043 OverlappedData::Connect(bytes) => bytes.as_ptr(),
1044 _ => unreachable!(),
1045 };
1046
1047 let ret = unsafe {
1048 connect_ex(
1049 socket as _,
1050 addr_ptr as *const SOCKADDR,
1051 addr_len,
1052 core::ptr::null(),
1053 0,
1054 core::ptr::null_mut(),
1055 &mut inner.overlapped,
1056 )
1057 };
1058
1059 let err = if ret != 0 {
1060 ERROR_SUCCESS
1061 } else {
1062 unsafe { WSAGetLastError() as u32 }
1063 };
1064 inner.error = err;
1065

Callers 1

connectMethod · 0.95

Calls 8

parse_addressFunction · 0.85
set_from_windows_errFunction · 0.85
noneMethod · 0.80
ErrClass · 0.50
lockMethod · 0.45
unwrapMethod · 0.45
getMethod · 0.45
as_ptrMethod · 0.45

Tested by

no test coverage detected