Skip to content

Commit

Permalink
Upgrade winapi to 0.3.7 and miow to 0.3.3 (#956)
Browse files Browse the repository at this point in the history
  • Loading branch information
aloucks authored and carllerche committed May 27, 2019
1 parent 1185510 commit 756bf28
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 21 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ iovec = "0.1.1"
libc = "0.2.42"

[target.'cfg(windows)'.dependencies]
winapi = "0.2.6"
miow = "0.2.1"
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
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: &dyn 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 @@ -12,7 +12,9 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
use std::time::Duration;
use std::{fmt, io};
use winapi::*;
use winapi::shared::winerror::WAIT_TIMEOUT;
use winapi::um::minwinbase::OVERLAPPED;
use winapi::um::minwinbase::OVERLAPPED_ENTRY;

/// Each Selector has a globally unique(ish) ID associated with it. This ID
/// gets tracked by `TcpStream`, `TcpListener`, etc... when they are first
Expand Down
11 changes: 7 additions & 4 deletions src/sys/windows/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use std::net::{self, Shutdown, SocketAddr};
use std::os::windows::prelude::*;
use std::sync::{Mutex, MutexGuard};
use std::time::Duration;
use winapi::*;
use winapi::um::minwinbase::OVERLAPPED_ENTRY;
use winapi::um::winnt::HANDLE;

pub struct TcpStream {
/// Separately stored implementation to ensure that the `Drop`
Expand Down Expand Up @@ -759,11 +760,13 @@ impl ListenerImp {
}
.and_then(|builder| unsafe {
trace!("scheduling an accept");
self.inner.socket.accept_overlapped(
&builder,
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 @@ -19,7 +19,8 @@ use std::io::prelude::*;
use std::mem;
use std::net::{self, Ipv4Addr, Ipv6Addr, SocketAddr};
use std::sync::{Mutex, MutexGuard};
use winapi::*;
use winapi::um::minwinbase::OVERLAPPED_ENTRY;
use winapi::um::winsock2::WSAEMSGSIZE;

pub struct UdpSocket {
imp: Imp,
Expand Down
3 changes: 0 additions & 3 deletions test/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![allow(deprecated)]

use net2;

#[macro_use]
extern crate log;

Expand Down Expand Up @@ -172,7 +170,6 @@ mod ports {

pub fn sleep_ms(ms: u64) {
use std::thread;
use std::time::Duration;
thread::sleep(Duration::from_millis(ms));
}

Expand Down
3 changes: 2 additions & 1 deletion test/test_udp_socket.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::localhost;
use bytes::{Buf, MutBuf, RingBuf, SliceBuf};
use iovec::IoVec;
use mio::net::UdpSocket;
use mio::{Events, Interests, Poll, PollOpt, Token};
use std::io::ErrorKind;
Expand Down Expand Up @@ -188,6 +187,8 @@ pub fn test_udp_socket_discard() {
#[cfg(unix)]
#[test]
pub fn test_udp_socket_send_recv_bufs() {
use iovec::IoVec;

let (tx, rx) = connected_sockets();

let mut poll = Poll::new().unwrap();
Expand Down

0 comments on commit 756bf28

Please sign in to comment.