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

Method TransmitFile

crates/stdlib/src/overlapped.rs:1128–1191  ·  view source on GitHub ↗
(
            zelf: &Py<Self>,
            socket: isize,
            file: isize,
            offset: u32,
            offset_high: u32,
            count_to_write: u32,
            count_per_send: u

Source from the content-addressed store, hash-verified

1126 )]
1127 #[pymethod]
1128 fn TransmitFile(
1129 zelf: &Py<Self>,
1130 socket: isize,
1131 file: isize,
1132 offset: u32,
1133 offset_high: u32,
1134 count_to_write: u32,
1135 count_per_send: u32,
1136 flags: u32,
1137 vm: &VirtualMachine,
1138 ) -> PyResult {
1139 use windows_sys::Win32::Foundation::{ERROR_IO_PENDING, ERROR_SUCCESS};
1140 use windows_sys::Win32::Networking::WinSock::WSAGetLastError;
1141
1142 let mut inner = zelf.inner.lock();
1143 if !matches!(inner.data, OverlappedData::None) {
1144 return Err(vm.new_value_error("operation already attempted"));
1145 }
1146
1147 inner.handle = socket as HANDLE;
1148 inner.data = OverlappedData::TransmitFile;
1149 inner.overlapped.Anonymous.Anonymous.Offset = offset;
1150 inner.overlapped.Anonymous.Anonymous.OffsetHigh = offset_high;
1151
1152 type TransmitFileFn = unsafe extern "system" fn(
1153 hSocket: usize,
1154 hFile: HANDLE,
1155 nNumberOfBytesToWrite: u32,
1156 nNumberOfBytesPerSend: u32,
1157 lpOverlapped: *mut OVERLAPPED,
1158 lpTransmitBuffers: *const core::ffi::c_void,
1159 dwReserved: u32,
1160 ) -> i32;
1161
1162 let transmit_file: TransmitFileFn =
1163 unsafe { core::mem::transmute(*TRANSMIT_FILE.get().unwrap()) };
1164
1165 let ret = unsafe {
1166 transmit_file(
1167 socket as _,
1168 file as HANDLE,
1169 count_to_write,
1170 count_per_send,
1171 &mut inner.overlapped,
1172 core::ptr::null(),
1173 flags,
1174 )
1175 };
1176
1177 let err = if ret != 0 {
1178 ERROR_SUCCESS
1179 } else {
1180 unsafe { WSAGetLastError() as u32 }
1181 };
1182 inner.error = err;
1183
1184 match err {
1185 ERROR_SUCCESS | ERROR_IO_PENDING => Ok(vm.ctx.none()),

Callers 1

sendfileMethod · 0.95

Calls 6

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

Tested by

no test coverage detected