summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-01-18 11:25:38 -0800
committerGarrett D'Amore <garrett@damore.org>2020-01-18 11:25:38 -0800
commit132acf7ceb59aa9567a7d254686dd612a3a79dfb (patch)
treefda6f4daa999b8b7cd8320f5f995e8a387636565 /src
parentda94097f50dbee98367b65f8331c58dddbffa74b (diff)
downloadnng-132acf7ceb59aa9567a7d254686dd612a3a79dfb.tar.gz
nng-132acf7ceb59aa9567a7d254686dd612a3a79dfb.tar.bz2
nng-132acf7ceb59aa9567a7d254686dd612a3a79dfb.zip
TTL reads could be fewer.
Specifically, we don't need to read the atomic value each loop iteration. We can just get it when a message is first received, and then use that value. This should make receiving through proxies a little more efficient.
Diffstat (limited to 'src')
-rw-r--r--src/protocol/reqrep0/rep.c8
-rw-r--r--src/protocol/reqrep0/xrep.c5
-rw-r--r--src/protocol/survey0/respond.c4
-rw-r--r--src/protocol/survey0/xrespond.c3
4 files changed, 13 insertions, 7 deletions
diff --git a/src/protocol/reqrep0/rep.c b/src/protocol/reqrep0/rep.c
index 3cc1802a..b546044d 100644
--- a/src/protocol/reqrep0/rep.c
+++ b/src/protocol/reqrep0/rep.c
@@ -491,6 +491,7 @@ rep0_pipe_recv_cb(void *arg)
nni_aio * aio;
size_t len;
int hops;
+ int ttl;
if (nni_aio_result(&p->aio_recv) != 0) {
nni_pipe_close(p->pipe);
@@ -498,6 +499,7 @@ rep0_pipe_recv_cb(void *arg)
}
msg = nni_aio_get_msg(&p->aio_recv);
+ ttl = nni_atomic_get(&s->ttl);
nni_msg_set_pipe(msg, p->id);
@@ -506,7 +508,7 @@ rep0_pipe_recv_cb(void *arg)
for (;;) {
bool end;
- if (hops > nni_atomic_get(&s->ttl)) {
+ if (hops > ttl) {
// This isn't malformed, but it has gone
// through too many hops. Do not disconnect,
// because we can legitimately receive messages
@@ -577,8 +579,8 @@ static int
rep0_sock_set_max_ttl(void *arg, const void *buf, size_t sz, nni_opt_type t)
{
rep0_sock *s = arg;
- int ttl;
- int rv;
+ int ttl;
+ int rv;
if ((rv = nni_copyin_int(&ttl, buf, sz, 1, 255, t)) == 0) {
nni_atomic_set(&s->ttl, ttl);
diff --git a/src/protocol/reqrep0/xrep.c b/src/protocol/reqrep0/xrep.c
index e5d96f02..a036e6f6 100644
--- a/src/protocol/reqrep0/xrep.c
+++ b/src/protocol/reqrep0/xrep.c
@@ -283,12 +283,15 @@ xrep0_pipe_recv_cb(void *arg)
xrep0_sock *s = p->rep;
nni_msg * msg;
int hops;
+ int ttl;
if (nni_aio_result(&p->aio_recv) != 0) {
nni_pipe_close(p->pipe);
return;
}
+ ttl = nni_atomic_get(&s->ttl);
+
msg = nni_aio_get_msg(&p->aio_recv);
nni_aio_set_msg(&p->aio_recv, NULL);
@@ -302,7 +305,7 @@ xrep0_pipe_recv_cb(void *arg)
for (;;) {
bool end = 0;
uint8_t *body;
- if (hops > (int)nni_atomic_get(&s->ttl)) {
+ if (hops > ttl) {
// This isn't malformed, but it has gone through
// too many hops. Do not disconnect, because we
// can legitimately receive messages with too many
diff --git a/src/protocol/survey0/respond.c b/src/protocol/survey0/respond.c
index 201811de..19dedef0 100644
--- a/src/protocol/survey0/respond.c
+++ b/src/protocol/survey0/respond.c
@@ -480,12 +480,14 @@ resp0_pipe_recv_cb(void *arg)
nni_aio * aio;
int hops;
size_t len;
+ int ttl;
if (nni_aio_result(&p->aio_recv) != 0) {
nni_pipe_close(p->npipe);
return;
}
+ ttl = nni_atomic_get(&s->ttl);
msg = nni_aio_get_msg(&p->aio_recv);
nni_msg_set_pipe(msg, p->id);
@@ -495,7 +497,7 @@ resp0_pipe_recv_cb(void *arg)
bool end = 0;
uint8_t *body;
- if (hops > nni_atomic_get(&s->ttl)) {
+ if (hops > ttl) {
goto drop;
}
hops++;
diff --git a/src/protocol/survey0/xrespond.c b/src/protocol/survey0/xrespond.c
index 65bd047e..73e541d3 100644
--- a/src/protocol/survey0/xrespond.c
+++ b/src/protocol/survey0/xrespond.c
@@ -273,13 +273,12 @@ xresp0_recv_cb(void *arg)
int hops;
int ttl;
- ttl = nni_atomic_get(&s->ttl);
-
if (nni_aio_result(p->aio_recv) != 0) {
nni_pipe_close(p->npipe);
return;
}
+ ttl = nni_atomic_get(&s->ttl);
msg = nni_aio_get_msg(p->aio_recv);
nni_aio_set_msg(p->aio_recv, NULL);
nni_msg_set_pipe(msg, p->id);