aboutsummaryrefslogtreecommitdiff
path: root/src/platform/windows/win_impl.h
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-07-11 22:59:38 -0700
committerGarrett D'Amore <garrett@damore.org>2017-07-11 22:59:38 -0700
commit8741c4421ec7a5e889c05a3d7dd46feee93ddf9a (patch)
tree9024d46ff202b065c67c2ea75ee5e43417ce4cdb /src/platform/windows/win_impl.h
parent183bd7e02c81bc09c17c6f4c0d3883d4d45221fc (diff)
downloadnng-8741c4421ec7a5e889c05a3d7dd46feee93ddf9a.tar.gz
nng-8741c4421ec7a5e889c05a3d7dd46feee93ddf9a.tar.bz2
nng-8741c4421ec7a5e889c05a3d7dd46feee93ddf9a.zip
Windows IPC working, mostly.
The IOCP code has been refactored to improve reuse, and hopefully will be easier to use with TCP now. Windows IPC using Named Pipes is mostly working -- mostly because there is a gnarly close-race. It seems that we need to take some more care to ensure that the pipe is not released while requests may be outstanding -- so some deeper synchronization between the IOCP callback logic and the win_event code is needed. In short, we need to add a condvar to the event, and notice when we have submitted work for async completion, and make sure we flag the event "idle" after either completion or cancellation of the event.
Diffstat (limited to 'src/platform/windows/win_impl.h')
-rw-r--r--src/platform/windows/win_impl.h57
1 files changed, 35 insertions, 22 deletions
diff --git a/src/platform/windows/win_impl.h b/src/platform/windows/win_impl.h
index 234acc35..4594da53 100644
--- a/src/platform/windows/win_impl.h
+++ b/src/platform/windows/win_impl.h
@@ -16,10 +16,12 @@
#define WIN32_LEAN_AND_MEAN
#endif
-#include <mswsock.h>
-#include <process.h>
+// These headers must be included first.
#include <windows.h>
#include <winsock2.h>
+
+#include <mswsock.h>
+#include <process.h>
#include <ws2tcpip.h>
#include "core/list.h"
@@ -27,21 +29,6 @@
// These types are provided for here, to permit them to be directly inlined
// elsewhere.
-typedef struct nni_win_event nni_win_event;
-
-// nni_win_event is used with io completion ports. This allows us to get
-// to a specific completion callback without requiring the poller (in the
-// completion port) to know anything about the event itself. We also use
-// this to pass back status and counts to the routine, which may not be
-// conveyed in the OVERLAPPED directly.
-struct nni_win_event {
- OVERLAPPED olpd;
- HANDLE h;
- void * ptr;
- nni_cb cb;
- nni_list aios;
-};
-
struct nni_plat_thr {
void (*func)(void *);
void * arg;
@@ -59,14 +46,40 @@ struct nni_plat_cv {
PSRWLOCK srl;
};
+// nni_win_event is used with io completion ports. This allows us to get
+// to a specific completion callback without requiring the poller (in the
+// completion port) to know anything about the event itself. We also use
+// this to pass back status and counts to the routine, which may not be
+// conveyed in the OVERLAPPED directly.
+typedef struct nni_win_event nni_win_event;
+typedef struct nni_win_event_ops nni_win_event_ops;
+
+struct nni_win_event_ops {
+ int (*wev_start)(nni_win_event *, nni_aio *);
+ void (*wev_finish)(nni_win_event *, nni_aio *);
+ void (*wev_cancel)(nni_win_event *, nni_aio *);
+};
+struct nni_win_event {
+ OVERLAPPED olpd;
+ HANDLE h;
+ void * ptr;
+ nni_aio * aio;
+ nni_mtx mtx;
+ int count;
+ int status;
+ nni_win_event_ops ops;
+};
+
extern int nni_win_error(int);
extern int nni_winsock_error(int);
-extern int nni_win_event_init(nni_win_event *, nni_cb, void *, HANDLE);
-extern void nni_win_event_fini(nni_win_event *);
-extern int nni_win_event_reset(nni_win_event *);
-extern OVERLAPPED *nni_win_event_overlapped(nni_win_event *);
-extern void nni_win_event_cancel(nni_win_event *);
+extern int nni_win_event_init(
+ nni_win_event *, nni_win_event_ops *, void *, HANDLE);
+extern void nni_win_event_fini(nni_win_event *);
+extern void nni_win_event_submit(nni_win_event *, nni_aio *);
+extern void nni_win_event_resubmit(nni_win_event *, nni_aio *);
+extern void nni_win_event_close(nni_win_event *);
+extern void nni_win_event_complete(nni_win_event *, int);
extern int nni_win_iocp_register(HANDLE);