]> git.proxmox.com Git - rustc.git/blob - src/vendor/miow/src/overlapped.rs
New upstream version 1.24.1+dfsg1
[rustc.git] / src / vendor / miow / src / overlapped.rs
1 use std::mem;
2
3 use winapi::*;
4
5 /// A wrapper around `OVERLAPPED` to provide "rustic" accessors and
6 /// initializers.
7 #[derive(Debug)]
8 pub struct Overlapped(OVERLAPPED);
9
10 unsafe impl Send for Overlapped {}
11 unsafe impl Sync for Overlapped {}
12
13 impl Overlapped {
14 /// Creates a new zeroed out instance of an overlapped I/O tracking state.
15 ///
16 /// This is suitable for passing to methods which will then later get
17 /// notified via an I/O Completion Port.
18 pub fn zero() -> Overlapped {
19 Overlapped(unsafe { mem::zeroed() })
20 }
21
22 /// Creates a new `Overlapped` function pointer from the underlying
23 /// `OVERLAPPED`, wrapping in the "rusty" wrapper for working with
24 /// accessors.
25 ///
26 /// # Unsafety
27 ///
28 /// This function doesn't validate `ptr` nor the lifetime of the returned
29 /// pointer at all, it's recommended to use this method with extreme
30 /// caution.
31 pub unsafe fn from_raw<'a>(ptr: *mut OVERLAPPED) -> &'a mut Overlapped {
32 &mut *(ptr as *mut Overlapped)
33 }
34
35 /// Gain access to the raw underlying data
36 pub fn raw(&self) -> *mut OVERLAPPED {
37 &self.0 as *const _ as *mut _
38 }
39
40 /// Sets the offset inside this overlapped structure.
41 ///
42 /// Note that for I/O operations in general this only has meaning for I/O
43 /// handles that are on a seeking device that supports the concept of an
44 /// offset.
45 pub fn set_offset(&mut self, offset: u64) {
46 self.0.Offset = offset as u32;
47 self.0.OffsetHigh = (offset >> 32) as u32;
48 }
49
50 /// Reads the offset inside this overlapped structure.
51 pub fn offset(&self) -> u64 {
52 (self.0.Offset as u64) | ((self.0.OffsetHigh as u64) << 32)
53 }
54
55 /// Sets the `hEvent` field of this structure.
56 ///
57 /// The event specified can be null.
58 pub fn set_event(&mut self, event: HANDLE) {
59 self.0.hEvent = event;
60 }
61
62 /// Reads the `hEvent` field of this structure, may return null.
63 pub fn event(&self) -> HANDLE {
64 self.0.hEvent
65 }
66 }