aboutsummaryrefslogtreecommitdiff
path: root/src/platform/windows/win_iocp.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-07-13 03:01:05 -0700
committerGarrett D'Amore <garrett@damore.org>2017-07-13 03:01:05 -0700
commit4735d7b69aaf0109b49a6a152b50099ad8400f96 (patch)
tree226a34bca67f908e0e70a1ecc858015b4538df06 /src/platform/windows/win_iocp.c
parent85593e678c35c13ed2d37f7f22aa41b0b8d70825 (diff)
downloadnng-4735d7b69aaf0109b49a6a152b50099ad8400f96.tar.gz
nng-4735d7b69aaf0109b49a6a152b50099ad8400f96.tar.bz2
nng-4735d7b69aaf0109b49a6a152b50099ad8400f96.zip
Windows implmentation of TCP is "working now".
This is only lightly tested, and I expect that there remain some race conditions. Endpoint logic in particular needs work.
Diffstat (limited to 'src/platform/windows/win_iocp.c')
-rw-r--r--src/platform/windows/win_iocp.c57
1 files changed, 28 insertions, 29 deletions
diff --git a/src/platform/windows/win_iocp.c b/src/platform/windows/win_iocp.c
index 306f029c..2635a4fc 100644
--- a/src/platform/windows/win_iocp.c
+++ b/src/platform/windows/win_iocp.c
@@ -89,7 +89,7 @@ nni_win_event_cancel(nni_aio *aio)
evt->aio = NULL;
// Use provider specific cancellation.
- evt->ops.wev_cancel(evt, aio);
+ evt->ops.wev_cancel(evt);
// Wait for everything to stop referencing this.
while (evt->flags & NNI_WIN_EVENT_RUNNING) {
@@ -154,23 +154,21 @@ void
nni_win_event_close(nni_win_event *evt)
{
nni_aio *aio;
- nni_mtx_lock(&evt->mtx);
- if (evt->h != NULL) {
- if (CancelIoEx(evt->h, &evt->olpd)) {
- DWORD cnt;
- // Stall waiting for the I/O to complete.
- GetOverlappedResult(evt->h, &evt->olpd, &cnt, TRUE);
+
+ if (evt->ptr != NULL) {
+ nni_mtx_lock(&evt->mtx);
+ evt->flags |= NNI_WIN_EVENT_ABORT;
+ evt->ops.wev_cancel(evt);
+ if ((aio = evt->aio) != NULL) {
+ evt->aio = NULL;
+ // We really don't care if we transferred data or not.
+ // The caller indicates they have closed the pipe.
+ evt->status = ERROR_INVALID_HANDLE;
+ evt->count = 0;
+ evt->ops.wev_finish(evt, aio);
}
+ nni_mtx_unlock(&evt->mtx);
}
- if ((aio = evt->aio) != NULL) {
- evt->aio = NULL;
- // We really don't care if we transferred data or not.
- // The caller indicates they have closed the pipe.
- evt->status = ERROR_INVALID_HANDLE;
- evt->count = 0;
- evt->ops.wev_finish(evt, aio);
- }
- nni_mtx_unlock(&evt->mtx);
}
int
@@ -183,8 +181,7 @@ nni_win_iocp_register(HANDLE h)
}
int
-nni_win_event_init(
- nni_win_event *evt, nni_win_event_ops *ops, void *ptr, HANDLE h)
+nni_win_event_init(nni_win_event *evt, nni_win_event_ops *ops, void *ptr)
{
int rv;
@@ -200,7 +197,6 @@ nni_win_event_init(
evt->ops = *ops;
evt->aio = NULL;
evt->ptr = ptr;
- evt->h = h;
return (0);
}
@@ -208,20 +204,23 @@ void
nni_win_event_fini(nni_win_event *evt)
{
nni_aio *aio;
- nni_mtx_lock(&evt->mtx);
- if ((aio = evt->aio) != NULL) {
- evt->flags |= NNI_WIN_EVENT_ABORT;
- evt->aio = NULL;
- // Use provider specific cancellation.
- evt->ops.wev_cancel(evt, aio);
+ if (evt->ptr != NULL) {
+ nni_mtx_lock(&evt->mtx);
+ if ((aio = evt->aio) != NULL) {
+ evt->flags |= NNI_WIN_EVENT_ABORT;
+ evt->aio = NULL;
+
+ // Use provider specific cancellation.
+ evt->ops.wev_cancel(evt);
- // Wait for everything to stop referencing this.
- while (evt->flags & NNI_WIN_EVENT_RUNNING) {
- nni_cv_wait(&evt->cv);
+ // Wait for everything to stop referencing this.
+ while (evt->flags & NNI_WIN_EVENT_RUNNING) {
+ nni_cv_wait(&evt->cv);
+ }
}
+ nni_mtx_unlock(&evt->mtx);
}
- nni_mtx_unlock(&evt->mtx);
if (evt->olpd.hEvent != NULL) {
(void) CloseHandle(evt->olpd.hEvent);