Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport switch to winapi 0.3 onto mio 0.6 #1629

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ fuchsia-zircon-sys = "0.3.2"
libc = "0.2.54"

[target.'cfg(windows)'.dependencies]
winapi = "0.2.6"
miow = "0.2.2"
kernel32-sys = "0.2"
winapi = { version = "0.3.7", features = ["minwindef", "minwinbase", "ioapiset", "winsock2"] }
miow = "0.3.3"

[dev-dependencies]
env_logger = { version = "0.4.0", default-features = false }
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ extern crate miow;
#[cfg(windows)]
extern crate winapi;

#[cfg(windows)]
extern crate kernel32;

#[macro_use]
extern crate log;

Expand Down
15 changes: 7 additions & 8 deletions src/sys/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
use std::io;
use std::os::windows::prelude::*;

use kernel32;
use winapi;

mod awakener;
Expand All @@ -162,24 +161,24 @@ enum Family {

unsafe fn cancel(socket: &AsRawSocket,
overlapped: &Overlapped) -> io::Result<()> {
let handle = socket.as_raw_socket() as winapi::HANDLE;
let ret = kernel32::CancelIoEx(handle, overlapped.as_mut_ptr());
let handle = socket.as_raw_socket() as winapi::um::winnt::HANDLE;
let ret = winapi::um::ioapiset::CancelIoEx(handle, overlapped.as_mut_ptr());
if ret == 0 {
Err(io::Error::last_os_error())
} else {
Ok(())
}
}

unsafe fn no_notify_on_instant_completion(handle: winapi::HANDLE) -> io::Result<()> {
unsafe fn no_notify_on_instant_completion(handle: winapi::um::winnt::HANDLE) -> io::Result<()> {
// TODO: move those to winapi
const FILE_SKIP_COMPLETION_PORT_ON_SUCCESS: winapi::UCHAR = 1;
const FILE_SKIP_SET_EVENT_ON_HANDLE: winapi::UCHAR = 2;
const FILE_SKIP_COMPLETION_PORT_ON_SUCCESS: winapi::shared::minwindef::UCHAR = 1;
const FILE_SKIP_SET_EVENT_ON_HANDLE: winapi::shared::minwindef::UCHAR = 2;

let flags = FILE_SKIP_COMPLETION_PORT_ON_SUCCESS | FILE_SKIP_SET_EVENT_ON_HANDLE;

let r = kernel32::SetFileCompletionNotificationModes(handle, flags);
if r == winapi::TRUE {
let r = winapi::um::winbase::SetFileCompletionNotificationModes(handle, flags);
if r == winapi::shared::minwindef::TRUE {
Ok(())
} else {
Err(io::Error::last_os_error())
Expand Down
4 changes: 3 additions & 1 deletion src/sys/windows/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use std::time::Duration;

use lazycell::AtomicLazyCell;

use winapi::*;
use winapi::shared::winerror::WAIT_TIMEOUT;
use winapi::um::minwinbase::OVERLAPPED;
use winapi::um::minwinbase::OVERLAPPED_ENTRY;
use miow;
use miow::iocp::{CompletionPort, CompletionStatus};

Expand Down
12 changes: 9 additions & 3 deletions src/sys/windows/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use std::time::Duration;
use miow::iocp::CompletionStatus;
use miow::net::*;
use net2::{TcpBuilder, TcpStreamExt as Net2TcpExt};
use winapi::*;
use winapi::um::minwinbase::OVERLAPPED_ENTRY;
use winapi::um::winnt::HANDLE;
use iovec::IoVec;

use {poll, Ready, Poll, PollOpt, Token};
Expand Down Expand Up @@ -746,8 +747,13 @@ impl ListenerImp {
Family::V6 => TcpBuilder::new_v6(),
}.and_then(|builder| unsafe {
trace!("scheduling an accept");
self.inner.socket.accept_overlapped(&builder, &mut me.accept_buf,
self.inner.accept.as_mut_ptr())
let socket = builder.to_tcp_stream()?;
let ready = self.inner.socket.accept_overlapped(
&socket,
&mut me.accept_buf,
self.inner.accept.as_mut_ptr(),
)?;
Ok((socket, ready))
});
match res {
Ok((socket, _)) => {
Expand Down
3 changes: 2 additions & 1 deletion src/sys/windows/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use std::sync::{Mutex, MutexGuard};

#[allow(unused_imports)]
use net2::{UdpBuilder, UdpSocketExt};
use winapi::*;
use winapi::um::minwinbase::OVERLAPPED_ENTRY;
use winapi::um::winsock2::WSAEMSGSIZE;
use miow::iocp::CompletionStatus;
use miow::net::SocketAddrBuf;
use miow::net::UdpSocketExt as MiowUdpSocketExt;
Expand Down