Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save piscisaureus/1135788 to your computer and use it in GitHub Desktop.
Save piscisaureus/1135788 to your computer and use it in GitHub Desktop.
From 91bb98696abd65117adf5b4bb25ec12eac160c0c Mon Sep 17 00:00:00 2001
From: Bert Belder <[email protected]>
Date: Wed, 10 Aug 2011 03:21:17 +0200
Subject: [PATCH 1/1] GetQueuedCompletionStatusEx experiment
---
config-mingw.mk | 2 +-
include/uv-win.h | 2 +-
src/win/core.c | 53 ++++++++++++++++++++++++++++++++++++++---------------
3 files changed, 40 insertions(+), 17 deletions(-)
diff --git a/config-mingw.mk b/config-mingw.mk
index 8081fce..7a1cedf 100644
--- a/config-mingw.mk
+++ b/config-mingw.mk
@@ -24,7 +24,7 @@ CC = $(PREFIX)gcc
AR = $(PREFIX)ar
E=.exe
-CFLAGS=$(CPPFLAGS) -g --std=gnu89 -D_WIN32_WINNT=0x0501 -Isrc/ares/config_win32
+CFLAGS=$(CPPFLAGS) -O2 --std=gnu89 -D_WIN32_WINNT=0x0701 -Isrc/ares/config_win32
LINKFLAGS=-lm
CARES_OBJS += src/ares/windows_port.o
diff --git a/include/uv-win.h b/include/uv-win.h
index 12588e9..9e89997 100644
--- a/include/uv-win.h
+++ b/include/uv-win.h
@@ -20,7 +20,7 @@
*/
#ifndef _WIN32_WINNT
-# define _WIN32_WINNT 0x0501
+# define _WIN32_WINNT 0x0701
#endif
#include <stdint.h>
diff --git a/src/win/core.c b/src/win/core.c
index 3200947..bb7456c 100644
--- a/src/win/core.c
+++ b/src/win/core.c
@@ -34,6 +34,24 @@
/* The only event loop we support right now */
uv_loop_t uv_main_loop_;
+typedef struct _OVERLAPPED_ENTRY {
+ ULONG_PTR lpCompletionKey;
+ LPOVERLAPPED lpOverlapped;
+ ULONG_PTR Internal;
+ DWORD dwNumberOfBytesTransferred;
+} OVERLAPPED_ENTRY, *LPOVERLAPPED_ENTRY;
+
+DECLSPEC_IMPORT BOOL WINAPI GetQueuedCompletionStatusEx(
+ HANDLE CompletionPort,
+ LPOVERLAPPED_ENTRY lpCompletionPortEntries,
+ ULONG ulCount,
+ PULONG ulNumEntriesRemoved,
+ DWORD dwMilliseconds,
+ BOOL fAlertable
+);
+
+
+
static void uv_loop_init() {
/* Create an I/O completion port */
@@ -94,25 +112,30 @@ static void uv_poll() {
ULONG_PTR key;
OVERLAPPED* overlapped;
uv_req_t* req;
-
- success = GetQueuedCompletionStatus(LOOP->iocp,
- &bytes,
- &key,
- &overlapped,
- uv_get_poll_timeout());
+ OVERLAPPED_ENTRY overlappeds[64];
+ ULONG count;
+ int i;
+
+ success = GetQueuedCompletionStatusEx(
+ LOOP->iocp,
+ overlappeds,
+ COUNTOF(overlappeds),
+ &count,
+ uv_get_poll_timeout(),
+ FALSE
+ );
uv_update_time();
- if (overlapped) {
- /* Package was dequeued */
- req = uv_overlapped_to_req(overlapped);
-
- if (!success) {
- req->error = uv_new_sys_error(GetLastError());
+ if (success) {
+ for (i = 0; i < count; i++) {
+ /* Package was dequeued */
+ req = uv_overlapped_to_req(overlappeds[i].lpOverlapped);
+ if (overlappeds[i].lpOverlapped->Internal) {
+ req->error = uv_new_sys_error(overlappeds[i].lpOverlapped->Internal);
+ }
+ uv_insert_pending_req(req);
}
-
- uv_insert_pending_req(req);
-
} else if (GetLastError() != WAIT_TIMEOUT) {
/* Serious error */
uv_fatal_error(GetLastError(), "GetQueuedCompletionStatus");
--
1.7.3.1.msysgit.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment