aboutsummaryrefslogtreecommitdiff
path: root/src/platform/windows
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/windows')
-rw-r--r--src/platform/windows/win_iocp.c2
-rw-r--r--src/platform/windows/win_ipc.c22
-rw-r--r--src/platform/windows/win_resolv.c8
-rw-r--r--src/platform/windows/win_tcp.c30
-rw-r--r--src/platform/windows/win_udp.c56
5 files changed, 55 insertions, 63 deletions
diff --git a/src/platform/windows/win_iocp.c b/src/platform/windows/win_iocp.c
index 0f9348d6..1189433a 100644
--- a/src/platform/windows/win_iocp.c
+++ b/src/platform/windows/win_iocp.c
@@ -89,7 +89,7 @@ nni_win_iocp_handler(void *arg)
static void
nni_win_event_cancel(nni_aio *aio, int rv)
{
- nni_win_event *evt = aio->a_prov_data;
+ nni_win_event *evt = nni_aio_get_prov_data(aio);
nni_mtx_lock(&evt->mtx);
if (aio == evt->active) {
diff --git a/src/platform/windows/win_ipc.c b/src/platform/windows/win_ipc.c
index 68a6ea2c..022a18ea 100644
--- a/src/platform/windows/win_ipc.c
+++ b/src/platform/windows/win_ipc.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -60,9 +60,10 @@ nni_win_ipc_pipe_start(nni_win_event *evt, nni_aio *aio)
int rv;
nni_plat_ipc_pipe *pipe = evt->ptr;
int idx;
+ int naiov;
+ nni_iov * aiov;
NNI_ASSERT(aio != NULL);
- NNI_ASSERT(aio->a_niov > 0);
if (pipe->p == INVALID_HANDLE_VALUE) {
evt->status = NNG_ECLOSED;
@@ -70,18 +71,19 @@ nni_win_ipc_pipe_start(nni_win_event *evt, nni_aio *aio)
return (1);
}
+ nni_aio_get_iov(aio, &naiov, &aiov);
idx = 0;
- while ((idx < aio->a_niov) && (aio->a_iov[idx].iov_len == 0)) {
+ while ((idx < naiov) && (aiov[idx].iov_len == 0)) {
idx++;
}
- NNI_ASSERT(idx < aio->a_niov);
+ NNI_ASSERT(idx < naiov);
// Now start a transfer. We assume that only one send can be
// outstanding on a pipe at a time. This is important to avoid
// scrambling the data anyway. Note that Windows named pipes do
// not appear to support scatter/gather, so we have to process
// each element in turn.
- buf = aio->a_iov[idx].iov_buf;
- len = (DWORD) aio->a_iov[idx].iov_len;
+ buf = aiov[idx].iov_buf;
+ len = (DWORD) aiov[idx].iov_len;
NNI_ASSERT(buf != NULL);
NNI_ASSERT(len != 0);
@@ -152,8 +154,6 @@ nni_win_ipc_pipe_init(nni_plat_ipc_pipe **pipep, HANDLE p)
void
nni_plat_ipc_pipe_send(nni_plat_ipc_pipe *pipe, nni_aio *aio)
{
- NNI_ASSERT(aio->a_niov > 0);
- NNI_ASSERT(aio->a_iov[0].iov_len > 0);
nni_win_event_submit(&pipe->snd_ev, aio);
}
@@ -198,7 +198,7 @@ nni_plat_ipc_ep_init(nni_plat_ipc_ep **epp, const nni_sockaddr *sa, int mode)
if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) {
return (NNG_ENOMEM);
}
- ZeroMemory(ep, sizeof(ep));
+ ZeroMemory(ep, sizeof(*ep));
ep->mode = mode;
NNI_LIST_NODE_INIT(&ep->node);
@@ -465,7 +465,7 @@ static void
nni_win_ipc_conn_cancel(nni_aio *aio, int rv)
{
nni_win_ipc_conn_work *w = &nni_win_ipc_connecter;
- nni_plat_ipc_ep * ep = aio->a_prov_data;
+ nni_plat_ipc_ep * ep = nni_aio_get_prov_data(aio);
nni_mtx_lock(&w->mtx);
if (aio == ep->con_aio) {
diff --git a/src/platform/windows/win_resolv.c b/src/platform/windows/win_resolv.c
index 331a2a56..6ee55d16 100644
--- a/src/platform/windows/win_resolv.c
+++ b/src/platform/windows/win_resolv.c
@@ -47,7 +47,7 @@ nni_win_resolv_finish(nni_win_resolv_item *item, int rv)
{
nni_aio *aio = item->aio;
- aio->a_prov_data = NULL;
+ nni_aio_set_prov_data(aio, NULL);
nni_aio_finish(aio, rv, 0);
NNI_FREE_STRUCT(item);
}
@@ -58,11 +58,11 @@ nni_win_resolv_cancel(nni_aio *aio, int rv)
nni_win_resolv_item *item;
nni_mtx_lock(&nni_win_resolv_mtx);
- if ((item = aio->a_prov_data) == NULL) {
+ if ((item = nni_aio_get_prov_data(aio)) == NULL) {
nni_mtx_unlock(&nni_win_resolv_mtx);
return;
}
- aio->a_prov_data = NULL;
+ nni_aio_set_prov_data(aio, NULL);
nni_mtx_unlock(&nni_win_resolv_mtx);
nni_task_cancel(&item->task);
NNI_FREE_STRUCT(item);
@@ -141,7 +141,7 @@ nni_win_resolv_task(void *arg)
if (probe != NULL) {
struct sockaddr_in * sin;
struct sockaddr_in6 *sin6;
- nng_sockaddr * sa = aio->a_addr;
+ nni_sockaddr * sa = nni_aio_get_input(aio, 0);
switch (probe->ai_addr->sa_family) {
case AF_INET:
diff --git a/src/platform/windows/win_tcp.c b/src/platform/windows/win_tcp.c
index 93cead91..c9935719 100644
--- a/src/platform/windows/win_tcp.c
+++ b/src/platform/windows/win_tcp.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -101,22 +101,21 @@ nni_win_tcp_pipe_start(nni_win_event *evt, nni_aio *aio)
{
int rv;
SOCKET s;
- WSABUF iov[4];
+ WSABUF iov[4]; // XXX: consider _alloca()
DWORD niov;
DWORD flags;
nni_plat_tcp_pipe *pipe = evt->ptr;
int i;
+ int naiov;
+ nni_iov * aiov;
- NNI_ASSERT(aio->a_niov > 0);
- NNI_ASSERT(aio->a_niov <= 4);
- NNI_ASSERT(aio->a_iov[0].iov_len > 0);
- NNI_ASSERT(aio->a_iov[0].iov_buf != NULL);
+ nni_aio_get_iov(aio, &naiov, &aiov);
// Put the AIOs in Windows form.
- for (niov = 0, i = 0; i < aio->a_niov; i++) {
- if (aio->a_iov[i].iov_len != 0) {
- iov[niov].buf = aio->a_iov[i].iov_buf;
- iov[niov].len = (ULONG) aio->a_iov[i].iov_len;
+ for (niov = 0, i = 0; i < naiov; i++) {
+ if (aiov[i].iov_len != 0) {
+ iov[niov].buf = aiov[i].iov_buf;
+ iov[niov].len = (ULONG) aiov[i].iov_len;
niov++;
}
}
@@ -265,7 +264,7 @@ nni_plat_tcp_ep_init(nni_plat_tcp_ep **epp, const nni_sockaddr *lsa,
if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) {
return (NNG_ENOMEM);
}
- ZeroMemory(ep, sizeof(ep));
+ ZeroMemory(ep, sizeof(*ep));
ep->s = INVALID_SOCKET;
@@ -509,7 +508,7 @@ nni_win_tcp_acc_start(nni_win_event *evt, nni_aio *aio)
void
nni_plat_tcp_ep_accept(nni_plat_tcp_ep *ep, nni_aio *aio)
{
- aio->a_pipe = NULL;
+ nni_aio_set_pipe(aio, NULL);
nni_win_event_submit(&ep->acc_ev, aio);
}
@@ -559,8 +558,7 @@ nni_win_tcp_con_finish(nni_win_event *evt, nni_aio *aio)
len = sizeof(pipe->sockname);
(void) getsockname(s, (SOCKADDR *) &pipe->sockname, &len);
- aio->a_pipe = pipe;
- nni_aio_finish(aio, 0, 0);
+ nni_aio_finish_pipe(aio, pipe);
}
static int
@@ -630,7 +628,7 @@ nni_win_tcp_con_start(nni_win_event *evt, nni_aio *aio)
extern void
nni_plat_tcp_ep_connect(nni_plat_tcp_ep *ep, nni_aio *aio)
{
- aio->a_pipe = NULL;
+ nni_aio_set_pipe(aio, NULL);
nni_win_event_submit(&ep->con_ev, aio);
}
diff --git a/src/platform/windows/win_udp.c b/src/platform/windows/win_udp.c
index 678b4ae7..ba947719 100644
--- a/src/platform/windows/win_udp.c
+++ b/src/platform/windows/win_udp.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -134,10 +134,11 @@ nni_win_udp_start_rx(nni_win_event *evt, nni_aio *aio)
{
int rv;
SOCKET s;
- WSABUF iov[4];
- DWORD niov;
+ WSABUF iov[4]; // XXX: consider _alloca
DWORD flags;
nni_plat_udp *u = evt->ptr;
+ nni_iov * aiov;
+ int naiov;
if ((s = u->s) == INVALID_SOCKET) {
evt->status = NNG_ECLOSED;
@@ -146,17 +147,12 @@ nni_win_udp_start_rx(nni_win_event *evt, nni_aio *aio)
}
u->rxsalen = sizeof(SOCKADDR_STORAGE);
- NNI_ASSERT(aio->a_niov > 0);
- NNI_ASSERT(aio->a_niov <= 4);
- NNI_ASSERT(aio->a_iov[0].iov_len > 0);
- NNI_ASSERT(aio->a_iov[0].iov_buf != NULL);
-
- niov = aio->a_niov;
+ nni_aio_get_iov(aio, &naiov, &aiov);
// Put the AIOs in Windows form.
- for (int i = 0; i < aio->a_niov; i++) {
- iov[i].buf = aio->a_iov[i].iov_buf;
- iov[i].len = (ULONG) aio->a_iov[i].iov_len;
+ for (int i = 0; i < naiov; i++) {
+ iov[i].buf = aiov[i].iov_buf;
+ iov[i].len = (ULONG) aiov[i].iov_len;
}
// Note that the IOVs for the event were prepared on entry
@@ -165,7 +161,7 @@ nni_win_udp_start_rx(nni_win_event *evt, nni_aio *aio)
evt->count = 0;
flags = 0;
- rv = WSARecvFrom(u->s, iov, niov, NULL, &flags,
+ rv = WSARecvFrom(u->s, iov, (DWORD) naiov, NULL, &flags,
(struct sockaddr *) &u->rxsa, &u->rxsalen, &evt->olpd, NULL);
if ((rv == SOCKET_ERROR) &&
@@ -188,9 +184,11 @@ nni_win_udp_start_tx(nni_win_event *evt, nni_aio *aio)
int rv;
SOCKET s;
WSABUF iov[4];
- DWORD niov;
+ int naiov;
+ nni_iov * aiov;
nni_plat_udp *u = evt->ptr;
int salen;
+ nni_sockaddr *sa;
if ((s = u->s) == INVALID_SOCKET) {
evt->status = NNG_ECLOSED;
@@ -198,24 +196,19 @@ nni_win_udp_start_tx(nni_win_event *evt, nni_aio *aio)
return (1);
}
- if ((salen = nni_win_nn2sockaddr(&u->txsa, aio->a_addr)) < 0) {
+ sa = nni_aio_get_input(aio, 0);
+
+ if ((salen = nni_win_nn2sockaddr(&u->txsa, sa)) < 0) {
evt->status = NNG_EADDRINVAL;
evt->count = 0;
return (1);
}
- NNI_ASSERT(aio->a_addr != NULL);
- NNI_ASSERT(aio->a_niov > 0);
- NNI_ASSERT(aio->a_niov <= 4);
- NNI_ASSERT(aio->a_iov[0].iov_len > 0);
- NNI_ASSERT(aio->a_iov[0].iov_buf != NULL);
-
- niov = aio->a_niov;
-
+ nni_aio_get_iov(aio, &naiov, &aiov);
// Put the AIOs in Windows form.
- for (int i = 0; i < aio->a_niov; i++) {
- iov[i].buf = aio->a_iov[i].iov_buf;
- iov[i].len = (ULONG) aio->a_iov[i].iov_len;
+ for (int i = 0; i < naiov; i++) {
+ iov[i].buf = aiov[i].iov_buf;
+ iov[i].len = (ULONG) aiov[i].iov_len;
}
// Note that the IOVs for the event were prepared on entry
@@ -223,8 +216,8 @@ nni_win_udp_start_tx(nni_win_event *evt, nni_aio *aio)
evt->count = 0;
- rv = WSASendTo(u->s, iov, niov, NULL, 0, (struct sockaddr *) &u->txsa,
- salen, &evt->olpd, NULL);
+ rv = WSASendTo(u->s, iov, (DWORD) naiov, NULL, 0,
+ (struct sockaddr *) &u->txsa, salen, &evt->olpd, NULL);
if ((rv == SOCKET_ERROR) &&
((rv = GetLastError()) != ERROR_IO_PENDING)) {
@@ -257,9 +250,10 @@ nni_win_udp_finish_rx(nni_win_event *evt, nni_aio *aio)
cnt = evt->count;
if ((rv = evt->status) == 0) {
+ nni_sockaddr *sa;
// convert address from Windows form...
- if (aio->a_addr != NULL) {
- if (nni_win_sockaddr2nn(aio->a_addr, &u->rxsa) != 0) {
+ if ((sa = nni_aio_get_input(aio, 0)) != NULL) {
+ if (nni_win_sockaddr2nn(sa, &u->rxsa) != 0) {
rv = NNG_EADDRINVAL;
cnt = 0;
}