aboutsummaryrefslogtreecommitdiff
path: root/src/sys/windows/waker.rs
blob: ab12c3c689a7cdcccd7dd7d5abd14ab0f6bdbf3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::sys::windows::Event;
use crate::sys::windows::Selector;
use crate::Token;

use miow::iocp::CompletionPort;
use std::io;
use std::sync::Arc;

#[derive(Debug)]
pub struct Waker {
    token: Token,
    port: Arc<CompletionPort>,
}

impl Waker {
    pub fn new(selector: &Selector, token: Token) -> io::Result<Waker> {
        Ok(Waker {
            token,
            port: selector.clone_port(),
        })
    }

    pub fn wake(&self) -> io::Result<()> {
        let mut ev = Event::new(self.token);
        ev.set_readable();

        self.port.post(ev.to_completion_status())
    }
}