Skip to content

Commit 9d76555

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 8fe73f1 + 088ce1a commit 9d76555

File tree

14 files changed

+1099
-295
lines changed

14 files changed

+1099
-295
lines changed

src/libnative/io/c_win32.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
pub struct WSADATA {
@@ -40,6 +48,16 @@ pub struct WSADATA {
4048

4149
pub type LPWSADATA = *mut WSADATA;
4250

51+
#[repr(C)]
52+
pub struct WSANETWORKEVENTS {
53+
pub lNetworkEvents: libc::c_long,
54+
pub iErrorCode: [libc::c_int, ..FD_MAX_EVENTS],
55+
}
56+
57+
pub type LPWSANETWORKEVENTS = *mut WSANETWORKEVENTS;
58+
59+
pub type WSAEVENT = libc::HANDLE;
60+
4361
#[repr(C)]
4462
pub struct fd_set {
4563
fd_count: libc::c_uint,
@@ -56,6 +74,21 @@ extern "system" {
5674
pub fn WSAStartup(wVersionRequested: libc::WORD,
5775
lpWSAData: LPWSADATA) -> libc::c_int;
5876
pub fn WSAGetLastError() -> libc::c_int;
77+
pub fn WSACloseEvent(hEvent: WSAEVENT) -> libc::BOOL;
78+
pub fn WSACreateEvent() -> WSAEVENT;
79+
pub fn WSAEventSelect(s: libc::SOCKET,
80+
hEventObject: WSAEVENT,
81+
lNetworkEvents: libc::c_long) -> libc::c_int;
82+
pub fn WSASetEvent(hEvent: WSAEVENT) -> libc::BOOL;
83+
pub fn WSAWaitForMultipleEvents(cEvents: libc::DWORD,
84+
lphEvents: *const WSAEVENT,
85+
fWaitAll: libc::BOOL,
86+
dwTimeout: libc::DWORD,
87+
fAltertable: libc::BOOL) -> libc::DWORD;
88+
pub fn WSAEnumNetworkEvents(s: libc::SOCKET,
89+
hEventObject: WSAEVENT,
90+
lpNetworkEvents: LPWSANETWORKEVENTS)
91+
-> libc::c_int;
5992

6093
pub fn ioctlsocket(s: libc::SOCKET, cmd: libc::c_long,
6194
argp: *mut libc::c_ulong) -> libc::c_int;
@@ -70,6 +103,12 @@ extern "system" {
70103
optval: *mut libc::c_char,
71104
optlen: *mut libc::c_int) -> libc::c_int;
72105

106+
pub fn SetEvent(hEvent: libc::HANDLE) -> libc::BOOL;
107+
pub fn WaitForMultipleObjects(nCount: libc::DWORD,
108+
lpHandles: *const libc::HANDLE,
109+
bWaitAll: libc::BOOL,
110+
dwMilliseconds: libc::DWORD) -> libc::DWORD;
111+
73112
pub fn CancelIo(hFile: libc::HANDLE) -> libc::BOOL;
74113
pub fn CancelIoEx(hFile: libc::HANDLE,
75114
lpOverlapped: libc::LPOVERLAPPED) -> libc::BOOL;

0 commit comments

Comments
 (0)