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

Method WSARecvInto

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

Source from the content-addressed store, hash-verified

748 // WSARecvInto
749 #[pymethod]
750 fn WSARecvInto(
751 zelf: &Py<Self>,
752 handle: isize,
753 buf: PyBuffer,
754 flags: u32,
755 vm: &VirtualMachine,
756 ) -> PyResult {
757 use windows_sys::Win32::Foundation::{
758 ERROR_BROKEN_PIPE, ERROR_IO_PENDING, ERROR_MORE_DATA, ERROR_SUCCESS,
759 };
760 use windows_sys::Win32::Networking::WinSock::{WSABUF, WSAGetLastError, WSARecv};
761
762 let mut inner = zelf.inner.lock();
763 if !matches!(inner.data, OverlappedData::None) {
764 return Err(vm.new_value_error("operation already attempted"));
765 }
766
767 let mut flags = flags;
768 inner.handle = handle as HANDLE;
769 let buf_len = buf.desc.len;
770 if buf_len > u32::MAX as usize {
771 return Err(vm.new_value_error("buffer too large"));
772 }
773
774 let Some(contiguous) = buf.as_contiguous_mut() else {
775 return Err(vm.new_buffer_error("buffer is not contiguous"));
776 };
777
778 inner.data = OverlappedData::ReadInto(buf.clone());
779
780 let wsabuf = WSABUF {
781 buf: contiguous.as_ptr() as *mut _,
782 len: buf_len as u32,
783 };
784 let mut nread: u32 = 0;
785
786 let ret = unsafe {
787 WSARecv(
788 handle as _,
789 &wsabuf,
790 1,
791 &mut nread,
792 &mut flags,
793 &mut inner.overlapped,
794 None,
795 )
796 };
797
798 let err = if ret < 0 {
799 unsafe { WSAGetLastError() as u32 }
800 } else {
801 ERROR_SUCCESS
802 };
803 inner.error = err;
804
805 match err {
806 ERROR_BROKEN_PIPE => {
807 mark_as_completed(&mut inner.overlapped);

Callers 1

recv_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