aboutsummaryrefslogtreecommitdiff
path: root/src/protocol/survey0/xrespond.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocol/survey0/xrespond.c')
-rw-r--r--src/protocol/survey0/xrespond.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/protocol/survey0/xrespond.c b/src/protocol/survey0/xrespond.c
index 6318fe8b..65bd047e 100644
--- a/src/protocol/survey0/xrespond.c
+++ b/src/protocol/survey0/xrespond.c
@@ -37,12 +37,12 @@ static void xresp0_pipe_fini(void *);
// resp0_sock is our per-socket protocol private structure.
struct xresp0_sock {
- nni_msgq * urq;
- nni_msgq * uwq;
- int ttl;
- nni_idhash *pipes;
- nni_aio * aio_getq;
- nni_mtx mtx;
+ nni_msgq * urq;
+ nni_msgq * uwq;
+ nni_atomic_int ttl;
+ nni_idhash * pipes;
+ nni_aio * aio_getq;
+ nni_mtx mtx;
};
// resp0_pipe is our per-pipe protocol private structure.
@@ -74,13 +74,15 @@ xresp0_sock_init(void *arg, nni_sock *nsock)
int rv;
nni_mtx_init(&s->mtx);
+ nni_atomic_init(&s->ttl);
+ nni_atomic_set(&s->ttl, 8); // Per RFC
if (((rv = nni_idhash_init(&s->pipes)) != 0) ||
- ((rv = nni_aio_alloc(&s->aio_getq, xresp0_sock_getq_cb, s)) != 0)) {
+ ((rv = nni_aio_alloc(&s->aio_getq, xresp0_sock_getq_cb, s)) !=
+ 0)) {
xresp0_sock_fini(s);
return (rv);
}
- s->ttl = 8; // Per RFC
s->urq = nni_sock_recvq(nsock);
s->uwq = nni_sock_sendq(nsock);
@@ -269,6 +271,9 @@ xresp0_recv_cb(void *arg)
nni_msgq * urq = s->urq;
nni_msg * msg;
int hops;
+ int ttl;
+
+ ttl = nni_atomic_get(&s->ttl);
if (nni_aio_result(p->aio_recv) != 0) {
nni_pipe_close(p->npipe);
@@ -290,7 +295,7 @@ xresp0_recv_cb(void *arg)
bool end;
uint8_t *body;
- if (hops > s->ttl) {
+ if (hops > ttl) {
goto drop;
}
hops++;
@@ -340,14 +345,19 @@ static int
xresp0_sock_set_maxttl(void *arg, const void *buf, size_t sz, nni_opt_type t)
{
xresp0_sock *s = arg;
- return (nni_copyin_int(&s->ttl, buf, sz, 1, 255, t));
+ int ttl;
+ int rv;
+ if ((rv = nni_copyin_int(&ttl, buf, sz, 1, 255, t)) == 0) {
+ nni_atomic_set(&s->ttl, ttl);
+ }
+ return (rv);
}
static int
xresp0_sock_get_maxttl(void *arg, void *buf, size_t *szp, nni_opt_type t)
{
xresp0_sock *s = arg;
- return (nni_copyout_int(s->ttl, buf, szp, t));
+ return (nni_copyout_int(nni_atomic_get(&s->ttl), buf, szp, t));
}
static void