(
zelf: &Py<Self>,
handle: isize,
buf: PyBuffer,
flags: u32,
address: PyTupleRef,
vm: &VirtualMachine,
)
| 1231 | // WSASendTo |
| 1232 | #[pymethod] |
| 1233 | fn WSASendTo( |
| 1234 | zelf: &Py<Self>, |
| 1235 | handle: isize, |
| 1236 | buf: PyBuffer, |
| 1237 | flags: u32, |
| 1238 | address: PyTupleRef, |
| 1239 | vm: &VirtualMachine, |
| 1240 | ) -> PyResult { |
| 1241 | use windows_sys::Win32::Foundation::{ERROR_IO_PENDING, ERROR_SUCCESS}; |
| 1242 | use windows_sys::Win32::Networking::WinSock::{WSABUF, WSAGetLastError, WSASendTo}; |
| 1243 | |
| 1244 | let mut inner = zelf.inner.lock(); |
| 1245 | if !matches!(inner.data, OverlappedData::None) { |
| 1246 | return Err(vm.new_value_error("operation already attempted")); |
| 1247 | } |
| 1248 | |
| 1249 | let (addr_bytes, addr_len) = parse_address(&address, vm)?; |
| 1250 | |
| 1251 | inner.handle = handle as HANDLE; |
| 1252 | let buf_len = buf.desc.len; |
| 1253 | if buf_len > u32::MAX as usize { |
| 1254 | return Err(vm.new_value_error("buffer too large")); |
| 1255 | } |
| 1256 | |
| 1257 | let Some(contiguous) = buf.as_contiguous() else { |
| 1258 | return Err(vm.new_buffer_error("buffer is not contiguous")); |
| 1259 | }; |
| 1260 | |
| 1261 | // Store both buffer and address in OverlappedData to keep them alive |
| 1262 | inner.data = OverlappedData::WriteTo(OverlappedWriteTo { |
| 1263 | buf: buf.clone(), |
| 1264 | address: addr_bytes, |
| 1265 | }); |
| 1266 | |
| 1267 | let wsabuf = WSABUF { |
| 1268 | buf: contiguous.as_ptr() as *mut _, |
| 1269 | len: buf_len as u32, |
| 1270 | }; |
| 1271 | let mut written: u32 = 0; |
| 1272 | |
| 1273 | // Get pointer to the stored address data |
| 1274 | let addr_ptr = match &inner.data { |
| 1275 | OverlappedData::WriteTo(wt) => wt.address.as_ptr(), |
| 1276 | _ => unreachable!(), |
| 1277 | }; |
| 1278 | |
| 1279 | let ret = unsafe { |
| 1280 | WSASendTo( |
| 1281 | handle as _, |
| 1282 | &wsabuf, |
| 1283 | 1, |
| 1284 | &mut written, |
| 1285 | flags, |
| 1286 | addr_ptr as *const SOCKADDR, |
| 1287 | addr_len, |
| 1288 | &mut inner.overlapped, |
| 1289 | None, |
| 1290 | ) |
no test coverage detected