aboutsummaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-01-24 17:38:16 -0800
committerGarrett D'Amore <garrett@damore.org>2018-02-01 16:11:38 -0800
commit3dae30ed5e543dc73fc993334ef56b9b157b9b3c (patch)
treed7e294b5d544aa18e8fc8749abfe605a05fa4bd7 /src/platform
parent5914e40c2ff7fcf346c90705785f3fb7650a9fdc (diff)
downloadnng-3dae30ed5e543dc73fc993334ef56b9b157b9b3c.tar.gz
nng-3dae30ed5e543dc73fc993334ef56b9b157b9b3c.tar.bz2
nng-3dae30ed5e543dc73fc993334ef56b9b157b9b3c.zip
fixes #173 Define public HTTP server API
This introduces enough of the HTTP API to support fully server applications, including creation of websocket style protocols, pluggable handlers, and so forth. We have also introduced scatter/gather I/O (rudimentary) for aios, and made other enhancements to the AIO framework. The internals of the AIOs themselves are now fully private, and we have eliminated the aio->a_addr member, with plans to remove the pipe and possibly message members as well. A few other minor issues were found and fixed as well. The HTTP API includes request, response, and connection objects, which can be used with both servers and clients. It also defines the HTTP server and handler objects, which support server applications. Support for client applications will require a client object to be exposed, and that should be happening shortly. None of this is "documented" yet, bug again, we will follow up shortly.
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/posix/posix_aio.h3
-rw-r--r--src/platform/posix/posix_epdesc.c11
-rw-r--r--src/platform/posix/posix_ipc.c3
-rw-r--r--src/platform/posix/posix_pipedesc.c67
-rw-r--r--src/platform/posix/posix_resolv_gai.c26
-rw-r--r--src/platform/posix/posix_tcp.c3
-rw-r--r--src/platform/posix/posix_udp.c48
-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
12 files changed, 145 insertions, 134 deletions
diff --git a/src/platform/posix/posix_aio.h b/src/platform/posix/posix_aio.h
index fe677591..ebc2eb99 100644
--- a/src/platform/posix/posix_aio.h
+++ b/src/platform/posix/posix_aio.h
@@ -1,5 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// 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
diff --git a/src/platform/posix/posix_epdesc.c b/src/platform/posix/posix_epdesc.c
index 7b168679..931ed052 100644
--- a/src/platform/posix/posix_epdesc.c
+++ b/src/platform/posix/posix_epdesc.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
@@ -47,13 +47,12 @@ struct nni_posix_epdesc {
static void
nni_posix_epdesc_cancel(nni_aio *aio, int rv)
{
- nni_posix_epdesc *ed = aio->a_prov_data;
+ nni_posix_epdesc *ed = nni_aio_get_prov_data(aio);
NNI_ASSERT(rv != 0);
nni_mtx_lock(&ed->mtx);
if (nni_aio_list_active(aio)) {
nni_aio_list_remove(aio);
- NNI_ASSERT(aio->a_pipe == NULL);
nni_aio_finish_error(aio, rv);
}
nni_mtx_unlock(&ed->mtx);
@@ -318,7 +317,7 @@ nni_posix_epdesc_accept(nni_posix_epdesc *ed, nni_aio *aio)
// connection is ready for us. There isn't anything else for us to
// do really, as that will have been done in listen.
nni_mtx_lock(&ed->mtx);
- aio->a_pipe = NULL;
+ nni_aio_set_pipe(aio, NULL);
// If we can't start, it means that the AIO was stopped.
if ((rv = nni_aio_start(aio, nni_posix_epdesc_cancel, ed)) != 0) {
nni_mtx_unlock(&ed->mtx);
@@ -344,7 +343,7 @@ nni_posix_epdesc_connect(nni_posix_epdesc *ed, nni_aio *aio)
int fd;
nni_mtx_lock(&ed->mtx);
- aio->a_pipe = NULL;
+ nni_aio_set_pipe(aio, NULL);
// If we can't start, it means that the AIO was stopped.
if ((rv = nni_aio_start(aio, nni_posix_epdesc_cancel, ed)) != 0) {
nni_mtx_unlock(&ed->mtx);
diff --git a/src/platform/posix/posix_ipc.c b/src/platform/posix/posix_ipc.c
index f0a9a973..fc312736 100644
--- a/src/platform/posix/posix_ipc.c
+++ b/src/platform/posix/posix_ipc.c
@@ -1,5 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// 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
diff --git a/src/platform/posix/posix_pipedesc.c b/src/platform/posix/posix_pipedesc.c
index 6ae0d752..23d69e51 100644
--- a/src/platform/posix/posix_pipedesc.c
+++ b/src/platform/posix/posix_pipedesc.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
@@ -39,7 +39,7 @@ static void
nni_posix_pipedesc_finish(nni_aio *aio, int rv)
{
nni_aio_list_remove(aio);
- nni_aio_finish(aio, rv, aio->a_count);
+ nni_aio_finish(aio, rv, nni_aio_count(aio));
}
static void
@@ -66,21 +66,23 @@ nni_posix_pipedesc_doclose(nni_posix_pipedesc *pd)
static void
nni_posix_pipedesc_dowrite(nni_posix_pipedesc *pd)
{
- int n;
- struct iovec iovec[4];
- nni_aio * aio;
- int niov;
+ nni_aio *aio;
while ((aio = nni_list_first(&pd->writeq)) != NULL) {
- int i;
- for (niov = 0, i = 0; i < aio->a_niov; i++) {
- iovec[niov].iov_len = aio->a_iov[i].iov_len;
- iovec[niov].iov_base = aio->a_iov[i].iov_buf;
- niov++;
- }
- if (niov == 0) {
- nni_posix_pipedesc_finish(aio, NNG_EINVAL);
- continue;
+ int i;
+ int n;
+ struct iovec iovec[4];
+ int niov;
+ int naiov;
+ nni_iov * aiov;
+
+ nni_aio_get_iov(aio, &naiov, &aiov);
+ for (niov = 0, i = 0; i < naiov; i++) {
+ if (aiov[i].iov_len > 0) {
+ iovec[niov].iov_len = aiov[i].iov_len;
+ iovec[niov].iov_base = aiov[i].iov_buf;
+ niov++;
+ }
}
n = writev(pd->node.fd, iovec, niov);
@@ -95,8 +97,7 @@ nni_posix_pipedesc_dowrite(nni_posix_pipedesc *pd)
return;
}
- aio->a_count += n;
-
+ nni_aio_bump_count(aio, n);
// We completed the entire operation on this aioq.
nni_posix_pipedesc_finish(aio, 0);
@@ -108,24 +109,24 @@ nni_posix_pipedesc_dowrite(nni_posix_pipedesc *pd)
static void
nni_posix_pipedesc_doread(nni_posix_pipedesc *pd)
{
- int n;
- struct iovec iovec[4];
- nni_aio * aio;
- int niov;
+ nni_aio *aio;
while ((aio = nni_list_first(&pd->readq)) != NULL) {
- int i;
- for (i = 0, niov = 0; i < aio->a_niov; i++) {
- if (aio->a_iov[i].iov_len != 0) {
- iovec[niov].iov_len = aio->a_iov[i].iov_len;
- iovec[niov].iov_base = aio->a_iov[i].iov_buf;
+ int i;
+ int n;
+ struct iovec iovec[4];
+ int niov;
+ int naiov;
+ nni_iov * aiov;
+
+ nni_aio_get_iov(aio, &naiov, &aiov);
+ for (niov = 0, i = 0; i < naiov; i++) {
+ if (aiov[i].iov_len != 0) {
+ iovec[niov].iov_len = aiov[i].iov_len;
+ iovec[niov].iov_base = aiov[i].iov_buf;
niov++;
}
}
- if (niov == 0) {
- nni_posix_pipedesc_finish(aio, NNG_EINVAL);
- continue;
- }
n = readv(pd->node.fd, iovec, niov);
if (n < 0) {
@@ -146,7 +147,7 @@ nni_posix_pipedesc_doread(nni_posix_pipedesc *pd)
return;
}
- aio->a_count += n;
+ nni_aio_bump_count(aio, n);
// We completed the entire operation on this aioq.
nni_posix_pipedesc_finish(aio, 0);
@@ -198,7 +199,7 @@ nni_posix_pipedesc_close(nni_posix_pipedesc *pd)
static void
nni_posix_pipedesc_cancel(nni_aio *aio, int rv)
{
- nni_posix_pipedesc *pd = aio->a_prov_data;
+ nni_posix_pipedesc *pd = nni_aio_get_prov_data(aio);
nni_mtx_lock(&pd->mtx);
if (nni_aio_list_active(aio)) {
diff --git a/src/platform/posix/posix_resolv_gai.c b/src/platform/posix/posix_resolv_gai.c
index be1d2c6b..f2f8a9fc 100644
--- a/src/platform/posix/posix_resolv_gai.c
+++ b/src/platform/posix/posix_resolv_gai.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
@@ -54,11 +54,16 @@ struct nni_posix_resolv_item {
static void
nni_posix_resolv_finish(nni_posix_resolv_item *item, int rv)
{
- nni_aio *aio = item->aio;
-
- aio->a_prov_data = NULL;
- nni_aio_finish(aio, rv, 0);
- NNI_FREE_STRUCT(item);
+ nni_aio *aio;
+
+ if ((aio = item->aio) != NULL) {
+ if (nni_aio_get_prov_data(aio) == item) {
+ nni_aio_set_prov_data(aio, NULL);
+ item->aio = NULL;
+ nni_aio_finish(aio, rv, 0);
+ NNI_FREE_STRUCT(item);
+ }
+ }
}
static void
@@ -67,11 +72,12 @@ nni_posix_resolv_cancel(nni_aio *aio, int rv)
nni_posix_resolv_item *item;
nni_mtx_lock(&nni_posix_resolv_mtx);
- if ((item = aio->a_prov_data) == NULL) {
+ if ((item = nni_aio_get_prov_data(aio)) == NULL) {
nni_mtx_unlock(&nni_posix_resolv_mtx);
return;
}
- aio->a_prov_data = NULL;
+ nni_aio_set_prov_data(aio, NULL);
+ item->aio = NULL;
nni_mtx_unlock(&nni_posix_resolv_mtx);
nni_task_cancel(&item->task);
NNI_FREE_STRUCT(item);
@@ -161,7 +167,7 @@ nni_posix_resolv_task(void *arg)
if (probe != NULL) {
struct sockaddr_in * sin;
struct sockaddr_in6 *sin6;
- nng_sockaddr * sa = aio->a_addr;
+ nng_sockaddr * sa = nni_aio_get_input(aio, 0);
switch (probe->ai_addr->sa_family) {
case AF_INET:
diff --git a/src/platform/posix/posix_tcp.c b/src/platform/posix/posix_tcp.c
index 69d7e7ce..79e241a3 100644
--- a/src/platform/posix/posix_tcp.c
+++ b/src/platform/posix/posix_tcp.c
@@ -1,5 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// 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
diff --git a/src/platform/posix/posix_udp.c b/src/platform/posix/posix_udp.c
index 31ef76f6..e01f6883 100644
--- a/src/platform/posix/posix_udp.c
+++ b/src/platform/posix/posix_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
@@ -62,16 +62,20 @@ nni_posix_udp_dorecv(nni_plat_udp *udp)
nni_list *q = &udp->udp_recvq;
// While we're able to recv, do so.
while ((aio = nni_list_first(q)) != NULL) {
- struct iovec iov[4]; // never have more than 4
+ struct iovec iov[4];
int niov;
+ nni_iov * aiov;
struct sockaddr_storage ss;
+ nng_sockaddr * sa;
struct msghdr hdr;
int rv = 0;
int cnt = 0;
- for (niov = 0; niov < aio->a_niov; niov++) {
- iov[niov].iov_base = aio->a_iov[niov].iov_buf;
- iov[niov].iov_len = aio->a_iov[niov].iov_len;
+ nni_aio_get_iov(aio, &niov, &aiov);
+
+ for (int i = 0; i < niov; i++) {
+ iov[i].iov_base = aiov[i].iov_buf;
+ iov[i].iov_len = aiov[i].iov_len;
}
hdr.msg_iov = iov;
hdr.msg_iovlen = niov;
@@ -88,11 +92,11 @@ nni_posix_udp_dorecv(nni_plat_udp *udp)
return;
}
rv = nni_plat_errno(errno);
- } else if (aio->a_addr != NULL) {
+ } else if ((sa = nni_aio_get_input(aio, 0)) != NULL) {
// We need to store the address information.
// It is incumbent on the AIO submitter to supply
// storage for the address.
- nni_posix_sockaddr2nn(aio->a_addr, (void *) &ss);
+ nni_posix_sockaddr2nn(sa, (void *) &ss);
}
nni_list_remove(q, aio);
nni_aio_finish(aio, rv, cnt);
@@ -109,19 +113,25 @@ nni_posix_udp_dosend(nni_plat_udp *udp)
// While we're able to send, do so.
while ((aio = nni_list_first(q)) != NULL) {
struct sockaddr_storage ss;
- struct msghdr hdr;
- struct iovec iov[4];
- int niov;
- int len;
- int rv = 0;
- int cnt = 0;
- if ((len = nni_posix_nn2sockaddr(&ss, aio->a_addr)) < 0) {
+ int len;
+ int rv = 0;
+ int cnt = 0;
+
+ len = nni_posix_nn2sockaddr(&ss, nni_aio_get_input(aio, 0));
+ if (len < 0) {
rv = NNG_EADDRINVAL;
} else {
- for (niov = 0; niov < aio->a_niov; niov++) {
- iov[niov].iov_base = aio->a_iov[niov].iov_buf;
- iov[niov].iov_len = aio->a_iov[niov].iov_len;
+ struct msghdr hdr;
+ struct iovec iov[4];
+ int niov;
+ nni_iov * aiov;
+
+ nni_aio_get_iov(aio, &niov, &aiov);
+
+ for (int i = 0; i < niov; i++) {
+ iov[i].iov_base = aiov[i].iov_buf;
+ iov[i].iov_len = aiov[i].iov_len;
}
hdr.msg_iov = iov;
hdr.msg_iovlen = niov;
@@ -253,7 +263,7 @@ nni_plat_udp_close(nni_plat_udp *udp)
void
nni_plat_udp_cancel(nni_aio *aio, int rv)
{
- nni_plat_udp *udp = aio->a_prov_data;
+ nni_plat_udp *udp = nni_aio_get_prov_data(aio);
nni_mtx_lock(&udp->udp_mtx);
if (nni_aio_list_active(aio)) {
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;
}