Skip to content

Commit 83804f9

Browse files
committed
auto merge of #15704 : alexcrichton/rust/issue-15595, r=brson
If a task is spinning in an accept loop, there is currently no method of gracefully shutting it down. This PR introduces a way to do so by cloning the acceptor and implementing a close_accept method to unblocking any pending acceptor. As with other I/O methods like this, it is `#[experimental]` from the start and sadly carries with it a good deal of code to support it. Much of the complication is from the fact that you can now concurrently accept on the same socket. I tried to add a good deal of tests for this change, but another set of eyes is always appreciated!
2 parents 833277e + fd763a5 commit 83804f9

File tree

14 files changed

+1100
-295
lines changed

14 files changed

+1100
-295
lines changed

src/libnative/io/c_windows.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ pub static ENABLE_INSERT_MODE: libc::DWORD = 0x20;
2626
pub static ENABLE_LINE_INPUT: libc::DWORD = 0x2;
2727
pub static ENABLE_PROCESSED_INPUT: libc::DWORD = 0x1;
2828
pub static ENABLE_QUICK_EDIT_MODE: libc::DWORD = 0x40;
29+
pub static WSA_INVALID_EVENT: WSAEVENT = 0 as WSAEVENT;
30+
31+
pub static FD_ACCEPT: libc::c_long = 0x08;
32+
pub static FD_MAX_EVENTS: uint = 10;
33+
pub static WSA_INFINITE: libc::DWORD = libc::INFINITE;
34+
pub static WSA_WAIT_TIMEOUT: libc::DWORD = libc::consts::os::extra::WAIT_TIMEOUT;
35+
pub static WSA_WAIT_EVENT_0: libc::DWORD = libc::consts::os::extra::WAIT_OBJECT_0;
36+
pub static WSA_WAIT_FAILED: libc::DWORD = libc::consts::os::extra::WAIT_FAILED;
2937

3038
#[repr(C)]
3139
#[cfg(target_arch = "x86")]
@@ -52,6 +60,16 @@ pub struct WSADATA {
5260

5361
pub type LPWSADATA = *mut WSADATA;
5462

63+
#[repr(C)]
64+
pub struct WSANETWORKEVENTS {
65+
pub lNetworkEvents: libc::c_long,
66+
pub iErrorCode: [libc::c_int, ..FD_MAX_EVENTS],
67+
}
68+
69+
pub type LPWSANETWORKEVENTS = *mut WSANETWORKEVENTS;
70+
71+
pub type WSAEVENT = libc::HANDLE;
72+
5573
#[repr(C)]
5674
pub struct fd_set {
5775
fd_count: libc::c_uint,
@@ -68,6 +86,21 @@ extern "system" {
6886
pub fn WSAStartup(wVersionRequested: libc::WORD,
6987
lpWSAData: LPWSADATA) -> libc::c_int;
7088
pub fn WSAGetLastError() -> libc::c_int;
89+
pub fn WSACloseEvent(hEvent: WSAEVENT) -> libc::BOOL;
90+
pub fn WSACreateEvent() -> WSAEVENT;
91+
pub fn WSAEventSelect(s: libc::SOCKET,
92+
hEventObject: WSAEVENT,
93+
lNetworkEvents: libc::c_long) -> libc::c_int;
94+
pub fn WSASetEvent(hEvent: WSAEVENT) -> libc::BOOL;
95+
pub fn WSAWaitForMultipleEvents(cEvents: libc::DWORD,
96+
lphEvents: *const WSAEVENT,
97+
fWaitAll: libc::BOOL,
98+
dwTimeout: libc::DWORD,
99+
fAltertable: libc::BOOL) -> libc::DWORD;
100+
pub fn WSAEnumNetworkEvents(s: libc::SOCKET,
101+
hEventObject: WSAEVENT,
102+
lpNetworkEvents: LPWSANETWORKEVENTS)
103+
-> libc::c_int;
71104

72105
pub fn ioctlsocket(s: libc::SOCKET, cmd: libc::c_long,
73106
argp: *mut libc::c_ulong) -> libc::c_int;
@@ -82,6 +115,12 @@ extern "system" {
82115
optval: *mut libc::c_char,
83116
optlen: *mut libc::c_int) -> libc::c_int;
84117

118+
pub fn SetEvent(hEvent: libc::HANDLE) -> libc::BOOL;
119+
pub fn WaitForMultipleObjects(nCount: libc::DWORD,
120+
lpHandles: *const libc::HANDLE,
121+
bWaitAll: libc::BOOL,
122+
dwMilliseconds: libc::DWORD) -> libc::DWORD;
123+
85124
pub fn CancelIo(hFile: libc::HANDLE) -> libc::BOOL;
86125
pub fn CancelIoEx(hFile: libc::HANDLE,
87126
lpOverlapped: libc::LPOVERLAPPED) -> libc::BOOL;

0 commit comments

Comments
 (0)