aboutsummaryrefslogtreecommitdiff
path: root/src/platform/posix
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/posix')
-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
7 files changed, 90 insertions, 71 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)) {