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

Method WSARecvFromInto

crates/stdlib/src/overlapped.rs:1398–1485  ·  view source on GitHub ↗
(
            zelf: &Py<Self>,
            handle: isize,
            buf: PyBuffer,
            size: u32,
            flags: OptionalArg<u32>,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

1396 // WSARecvFromInto
1397 #[pymethod]
1398 fn WSARecvFromInto(
1399 zelf: &Py<Self>,
1400 handle: isize,
1401 buf: PyBuffer,
1402 size: u32,
1403 flags: OptionalArg<u32>,
1404 vm: &VirtualMachine,
1405 ) -> PyResult {
1406 use windows_sys::Win32::Foundation::{
1407 ERROR_BROKEN_PIPE, ERROR_IO_PENDING, ERROR_MORE_DATA, ERROR_SUCCESS,
1408 };
1409 use windows_sys::Win32::Networking::WinSock::{WSABUF, WSAGetLastError, WSARecvFrom};
1410
1411 let mut inner = zelf.inner.lock();
1412 if !matches!(inner.data, OverlappedData::None) {
1413 return Err(vm.new_value_error("operation already attempted"));
1414 }
1415
1416 let mut flags = flags.unwrap_or(0);
1417 inner.handle = handle as HANDLE;
1418
1419 let Some(contiguous) = buf.as_contiguous_mut() else {
1420 return Err(vm.new_buffer_error("buffer is not contiguous"));
1421 };
1422
1423 let buf_len = buf.desc.len;
1424 if buf_len > u32::MAX as usize {
1425 return Err(vm.new_value_error("buffer too large"));
1426 }
1427
1428 let address: SOCKADDR_IN6 = unsafe { core::mem::zeroed() };
1429 let address_length = core::mem::size_of::<SOCKADDR_IN6>() as i32;
1430
1431 inner.data = OverlappedData::ReadFromInto(OverlappedReadFromInto {
1432 result: None,
1433 user_buffer: buf.clone(),
1434 address,
1435 address_length,
1436 });
1437
1438 let wsabuf = WSABUF {
1439 buf: contiguous.as_ptr() as *mut _,
1440 len: size,
1441 };
1442 let mut nread: u32 = 0;
1443
1444 // Get mutable reference to address in inner.data
1445 let (addr_ptr, addr_len_ptr) = match &mut inner.data {
1446 OverlappedData::ReadFromInto(rfi) => (
1447 &mut rfi.address as *mut SOCKADDR_IN6,
1448 &mut rfi.address_length as *mut i32,
1449 ),
1450 _ => unreachable!(),
1451 };
1452
1453 let ret = unsafe {
1454 WSARecvFrom(
1455 handle as _,

Callers 1

recvfrom_intoMethod · 0.95

Calls 8

mark_as_completedFunction · 0.85
set_from_windows_errFunction · 0.85
as_contiguous_mutMethod · 0.80
noneMethod · 0.80
ErrClass · 0.50
lockMethod · 0.45
cloneMethod · 0.45
as_ptrMethod · 0.45

Tested by

no test coverage detected