aboutsummaryrefslogtreecommitdiff
path: root/src/core/endpt.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-07-03 12:44:02 -0700
committerGarrett D'Amore <garrett@damore.org>2017-07-03 12:44:02 -0700
commitc1a92ee76a3e9e70ecae4646763bade0c16e4807 (patch)
treec6cca5b8ff6227e38e1dc9dabec24a4b1373d799 /src/core/endpt.c
parent14c8396d6954622de9e07b010810ee49f0496b2a (diff)
downloadnng-c1a92ee76a3e9e70ecae4646763bade0c16e4807.tar.gz
nng-c1a92ee76a3e9e70ecae4646763bade0c16e4807.tar.bz2
nng-c1a92ee76a3e9e70ecae4646763bade0c16e4807.zip
inproc transport uses aio for connect/accept.
Diffstat (limited to 'src/core/endpt.c')
-rw-r--r--src/core/endpt.c58
1 files changed, 54 insertions, 4 deletions
diff --git a/src/core/endpt.c b/src/core/endpt.c
index b24d7643..20874c90 100644
--- a/src/core/endpt.c
+++ b/src/core/endpt.c
@@ -237,15 +237,40 @@ nni_ep_remove(nni_ep *ep)
static int
+nni_ep_connect_aio(nni_ep *ep, void **pipep)
+{
+ nni_aio aio;
+ int rv;
+
+ nni_aio_init(&aio, NULL, NULL);
+ aio.a_endpt = ep->ep_data;
+ ep->ep_ops.ep_connect(ep->ep_data, &aio);
+ nni_aio_wait(&aio);
+
+ if ((rv = nni_aio_result(&aio)) == 0) {
+ *pipep = aio.a_pipe;
+ }
+ nni_aio_fini(&aio);
+ return (rv);
+}
+
+
+static int
nni_ep_connect_sync(nni_ep *ep)
{
nni_pipe *pipe;
int rv;
- if ((rv = nni_pipe_create(&pipe, ep, ep->ep_sock, ep->ep_tran)) != 0) {
+ rv = nni_pipe_create(&pipe, ep, ep->ep_sock, ep->ep_tran);
+ if (rv != 0) {
return (rv);
}
- rv = ep->ep_ops.ep_connect_sync(ep->ep_data, &pipe->p_tran_data);
+ if (ep->ep_ops.ep_connect != NULL) {
+ rv = nni_ep_connect_aio(ep, &pipe->p_tran_data);
+ } else {
+ rv = ep->ep_ops.ep_connect_sync(ep->ep_data,
+ &pipe->p_tran_data);
+ }
if (rv != 0) {
nni_pipe_remove(pipe);
return (rv);
@@ -400,6 +425,25 @@ nni_ep_dial(nni_ep *ep, int flags)
static int
+nni_ep_accept_aio(nni_ep *ep, void **pipep)
+{
+ nni_aio aio;
+ int rv;
+
+ nni_aio_init(&aio, NULL, NULL);
+ aio.a_endpt = ep->ep_data;
+ ep->ep_ops.ep_accept(ep->ep_data, &aio);
+ nni_aio_wait(&aio);
+
+ if ((rv = nni_aio_result(&aio)) == 0) {
+ *pipep = aio.a_pipe;
+ }
+ nni_aio_fini(&aio);
+ return (rv);
+}
+
+
+static int
nni_ep_accept_sync(nni_ep *ep)
{
nni_pipe *pipe;
@@ -408,10 +452,16 @@ nni_ep_accept_sync(nni_ep *ep)
if (ep->ep_closed) {
return (NNG_ECLOSED);
}
- if ((rv = nni_pipe_create(&pipe, ep, ep->ep_sock, ep->ep_tran)) != 0) {
+ rv = nni_pipe_create(&pipe, ep, ep->ep_sock, ep->ep_tran);
+ if (rv != 0) {
return (rv);
}
- rv = ep->ep_ops.ep_accept_sync(ep->ep_data, &pipe->p_tran_data);
+ if (ep->ep_ops.ep_accept != NULL) {
+ rv = nni_ep_accept_aio(ep, &pipe->p_tran_data);
+ } else {
+ rv = ep->ep_ops.ep_accept_sync(ep->ep_data,
+ &pipe->p_tran_data);
+ }
if (rv != 0) {
nni_pipe_remove(pipe);
return (rv);