1 // Copyright 2022 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 use winapi::shared::ws2def::WSABUF; 6 7 use crate::iobuf::PlatformIoBuf; 8 9 /// Cross platform binary compatible iovec. See [`crate::IoBufMut`] for documentation. 10 pub type IoBuf = WSABUF; 11 12 impl PlatformIoBuf for IoBuf { 13 #[inline] new(ptr: *mut u8, len: usize) -> Self14 fn new(ptr: *mut u8, len: usize) -> Self { 15 WSABUF { 16 buf: ptr as *mut i8, 17 len: len.try_into().unwrap(), 18 } 19 } 20 21 #[inline] len(&self) -> usize22 fn len(&self) -> usize { 23 self.len as usize 24 } 25 26 #[inline] ptr(&self) -> *mut u827 fn ptr(&self) -> *mut u8 { 28 self.buf as *mut u8 29 } 30 31 #[inline] set_len(&mut self, len: usize)32 fn set_len(&mut self, len: usize) { 33 self.len = len.try_into().unwrap(); 34 } 35 36 #[inline] set_ptr(&mut self, ptr: *mut u8)37 fn set_ptr(&mut self, ptr: *mut u8) { 38 self.buf = ptr as *mut i8; 39 } 40 } 41