summaryrefslogtreecommitdiff
path: root/event_iocp.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2009-04-13 18:29:31 +0000
committerNick Mathewson <nickm@torproject.org>2009-04-13 18:29:31 +0000
commitca737ff3b5e0b5e93e3b2bd49d5434ff20e95d1e (patch)
treec3ed23199503341b3b79d2cbdfba3198d4505cfb /event_iocp.c
parent4e8cdc6f086bcf0b31df203451aa38741e149ac3 (diff)
downloadlibevent-ca737ff3b5e0b5e93e3b2bd49d5434ff20e95d1e.tar.gz
Add draft (nonworking) versions of iocp code to hack on more.
svn:r1172
Diffstat (limited to 'event_iocp.c')
-rw-r--r--event_iocp.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/event_iocp.c b/event_iocp.c
new file mode 100644
index 00000000..de4c35e2
--- /dev/null
+++ b/event_iocp.c
@@ -0,0 +1,40 @@
+
+#include "iocp-internal.h"
+
+#define N_OVERLAPPED_ENTRIES 32
+
+void
+event_overlapped_init(struct event_overlapped *o, iocp_callback cb)
+{
+ memeset(o, 0, sizeof(struct event_overlapped));
+ o->cb = cb;
+}
+
+static void
+handle_entry(OVERLAPPED_ENTRY *ent)
+{
+ OVERLAPPED *o = ent->lpOverlapped;
+ struct event_overlapped *eo =
+ EVUTIL_UPCAST(o, struct event_overlapped, overlapped);
+ eo = upcast(o, struct event_overlapped, overlapped);
+ eo->cb(eo, ent->lpCompletionKey, ent->dwNumberOfBytesTransferred);
+}
+
+static void
+loop(struct event_iocp_port *port, long ms)
+{
+ OVERLAPPED_ENTRY entries[N_OVERLAPPED_ENTRIES];
+ ULONG n_entries;
+ int i;
+
+ if (ms <= 0)
+ ms = INFINITE;
+
+ while (GetQueuedCompletionStatusEx(port->port,
+ entries, N_OVERLAPPED_ENTRIES, &n_entries, ms, 1)) {
+ for (i = 0; i < n_entries; ++i) {
+ handle_entry(&entries[i]);
+ }
+ }
+}
+