aboutsummaryrefslogtreecommitdiff
path: root/src/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocol')
-rw-r--r--src/protocol/bus/bus.c7
-rw-r--r--src/protocol/pair/pair_v1.c3
-rw-r--r--src/protocol/reqrep/rep.c18
-rw-r--r--src/protocol/reqrep/req.c9
-rw-r--r--src/protocol/survey/respond.c18
-rw-r--r--src/protocol/survey/survey.c35
6 files changed, 29 insertions, 61 deletions
diff --git a/src/protocol/bus/bus.c b/src/protocol/bus/bus.c
index c5a6ce06..79d7187e 100644
--- a/src/protocol/bus/bus.c
+++ b/src/protocol/bus/bus.c
@@ -240,16 +240,14 @@ nni_bus_pipe_recv_cb(void *arg)
nni_bus_pipe *ppipe = arg;
nni_bus_sock *psock = ppipe->psock;
nni_msg * msg;
- uint32_t id;
if (nni_aio_result(&ppipe->aio_recv) != 0) {
nni_pipe_stop(ppipe->npipe);
return;
}
msg = ppipe->aio_recv.a_msg;
- id = nni_pipe_id(ppipe->npipe);
- if (nni_msg_prepend_header(msg, &id, 4) != 0) {
+ if (nni_msg_header_insert_u32(msg, nni_pipe_id(ppipe->npipe)) != 0) {
// XXX: bump a nomemory stat
nni_msg_free(msg);
nni_pipe_stop(ppipe->npipe);
@@ -298,8 +296,7 @@ nni_bus_sock_getq_cb(void *arg)
// is doing this probably.) In this case grab the pipe
// ID from the header, so we can exclude it.
if (nni_msg_header_len(msg) >= 4) {
- memcpy(&sender, nni_msg_header(msg), 4);
- nni_msg_trim_header(msg, 4);
+ sender = nni_msg_header_trim_u32(msg);
} else {
sender = 0;
}
diff --git a/src/protocol/pair/pair_v1.c b/src/protocol/pair/pair_v1.c
index ea8c1226..812617f1 100644
--- a/src/protocol/pair/pair_v1.c
+++ b/src/protocol/pair/pair_v1.c
@@ -224,7 +224,7 @@ pair1_pipe_recv_cb(void *arg)
// If we bounced too many times, discard the message, but
// keep getting more.
- if (hdr >= s->ttl) {
+ if (hdr >= (unsigned) s->ttl) {
nni_msg_free(msg);
nni_pipe_recv(npipe, &p->aio_recv);
return;
@@ -309,7 +309,6 @@ pair1_pipe_getq_cb(void *arg)
pair1_sock *s = p->psock;
nni_msg * msg;
uint32_t hops;
- uint8_t * data;
if (nni_aio_result(&p->aio_getq) != 0) {
nni_pipe_stop(p->npipe);
diff --git a/src/protocol/reqrep/rep.c b/src/protocol/reqrep/rep.c
index 1adfd0f8..49bcdce2 100644
--- a/src/protocol/reqrep/rep.c
+++ b/src/protocol/reqrep/rep.c
@@ -207,7 +207,6 @@ nni_rep_sock_getq_cb(void *arg)
nni_rep_sock *rep = arg;
nni_msgq * uwq = rep->uwq;
nni_msg * msg;
- uint8_t * header;
uint32_t id;
nni_rep_pipe *rp;
int rv;
@@ -234,9 +233,7 @@ nni_rep_sock_getq_cb(void *arg)
return;
}
- header = nni_msg_header(msg);
- NNI_GET32(header, id);
- nni_msg_trim_header(msg, 4);
+ id = nni_msg_header_trim_u32(msg);
// Look for the pipe, and attempt to put the message there
// (nonblocking) if we can. If we can't for any reason, then we
@@ -291,7 +288,6 @@ nni_rep_pipe_recv_cb(void *arg)
nni_rep_sock *rep = rp->rep;
nni_msg * msg;
int rv;
- uint8_t idbuf[4];
uint8_t * body;
int hops;
@@ -300,13 +296,11 @@ nni_rep_pipe_recv_cb(void *arg)
return;
}
- NNI_PUT32(idbuf, nni_pipe_id(rp->pipe));
-
msg = rp->aio_recv.a_msg;
rp->aio_recv.a_msg = NULL;
// Store the pipe id in the header, first thing.
- rv = nni_msg_append_header(msg, idbuf, 4);
+ rv = nni_msg_header_append_u32(msg, nni_pipe_id(rp->pipe));
if (rv != 0) {
goto malformed;
}
@@ -323,7 +317,7 @@ nni_rep_pipe_recv_cb(void *arg)
}
body = nni_msg_body(msg);
end = (body[0] & 0x80) ? 1 : 0;
- rv = nni_msg_append_header(msg, body, 4);
+ rv = nni_msg_header_append(msg, body, 4);
if (rv != 0) {
// Presumably this is due to out of memory.
// We could just discard and try again, but we
@@ -422,9 +416,9 @@ nni_rep_sock_sfilter(void *arg, nni_msg *msg)
}
// drop anything else in the header...
- nni_msg_trunc_header(msg, nni_msg_header_len(msg));
+ nni_msg_header_clear(msg);
- if (nni_msg_append_header(msg, rep->btrace, rep->btrace_len) != 0) {
+ if (nni_msg_header_append(msg, rep->btrace, rep->btrace_len) != 0) {
nni_free(rep->btrace, rep->btrace_len);
rep->btrace = NULL;
rep->btrace_len = 0;
@@ -463,7 +457,7 @@ nni_rep_sock_rfilter(void *arg, nni_msg *msg)
}
rep->btrace_len = len;
memcpy(rep->btrace, header, len);
- nni_msg_trunc_header(msg, len);
+ nni_msg_header_clear(msg);
return (msg);
}
diff --git a/src/protocol/reqrep/req.c b/src/protocol/reqrep/req.c
index d0dd3887..20fb07f8 100644
--- a/src/protocol/reqrep/req.c
+++ b/src/protocol/reqrep/req.c
@@ -437,17 +437,14 @@ nni_req_recv_cb(void *arg)
// Malformed message.
goto malformed;
}
- if (nni_msg_append_header(msg, nni_msg_body(msg), 4) != 0) {
+ if (nni_msg_header_append(msg, nni_msg_body(msg), 4) != 0) {
// Arguably we could just discard and carry on. But
// dropping the connection is probably more helpful since
// it lets the other side see that a problem occurred.
// Plus it gives us a chance to reclaim some memory.
goto malformed;
}
- if (nni_msg_trim(msg, 4) != 0) {
- // This should never happen - could be an assert.
- nni_panic("Failed to trim REQ header from body");
- }
+ (void) nni_msg_trim(msg, 4); // Cannot fail
rp->aio_putq.a_msg = msg;
nni_msgq_aio_put(rp->req->urq, &rp->aio_putq);
@@ -548,7 +545,7 @@ nni_req_sock_sfilter(void *arg, nni_msg *msg)
// Request ID is in big endian format.
NNI_PUT32(req->reqid, id);
- if (nni_msg_append_header(msg, req->reqid, 4) != 0) {
+ if (nni_msg_header_append(msg, req->reqid, 4) != 0) {
// Should be ENOMEM.
nni_msg_free(msg);
return (NULL);
diff --git a/src/protocol/survey/respond.c b/src/protocol/survey/respond.c
index 4db79b86..32513134 100644
--- a/src/protocol/survey/respond.c
+++ b/src/protocol/survey/respond.c
@@ -225,7 +225,6 @@ nni_resp_sock_getq_cb(void *arg)
{
nni_resp_sock *psock = arg;
nni_msg * msg;
- uint8_t * header;
uint32_t id;
nni_resp_pipe *ppipe;
int rv;
@@ -244,9 +243,7 @@ nni_resp_sock_getq_cb(void *arg)
nni_msgq_aio_get(psock->uwq, &psock->aio_getq);
return;
}
- header = nni_msg_header(msg);
- NNI_GET32(header, id);
- nni_msg_trim_header(msg, 4);
+ id = nni_msg_header_trim_u32(msg);
nni_mtx_lock(&psock->mtx);
rv = nni_idhash_find(psock->pipes, id, (void **) &ppipe);
@@ -301,7 +298,6 @@ nni_resp_recv_cb(void *arg)
nni_resp_sock *psock = ppipe->psock;
nni_msgq * urq;
nni_msg * msg;
- uint8_t idbuf[4];
int hops;
int rv;
@@ -311,13 +307,11 @@ nni_resp_recv_cb(void *arg)
urq = nni_sock_recvq(psock->nsock);
- NNI_PUT32(idbuf, ppipe->id);
-
msg = ppipe->aio_recv.a_msg;
ppipe->aio_recv.a_msg = NULL;
// Store the pipe id in the header, first thing.
- if (nni_msg_append_header(msg, idbuf, 4) != 0) {
+ if (nni_msg_header_append_u32(msg, ppipe->id) != 0) {
nni_msg_free(msg);
goto error;
}
@@ -338,7 +332,7 @@ nni_resp_recv_cb(void *arg)
}
body = nni_msg_body(msg);
end = (body[0] & 0x80) ? 1 : 0;
- rv = nni_msg_append_header(msg, body, 4);
+ rv = nni_msg_header_append(msg, body, 4);
if (rv != 0) {
nni_msg_free(msg);
goto error;
@@ -439,9 +433,9 @@ nni_resp_sock_sfilter(void *arg, nni_msg *msg)
}
// drop anything else in the header...
- nni_msg_trunc_header(msg, nni_msg_header_len(msg));
+ nni_msg_header_clear(msg);
- if (nni_msg_append_header(msg, psock->btrace, psock->btrace_len) !=
+ if (nni_msg_header_append(msg, psock->btrace, psock->btrace_len) !=
0) {
nni_free(psock->btrace, psock->btrace_len);
psock->btrace = NULL;
@@ -481,7 +475,7 @@ nni_resp_sock_rfilter(void *arg, nni_msg *msg)
}
psock->btrace_len = len;
memcpy(psock->btrace, header, len);
- nni_msg_trunc_header(msg, len);
+ nni_msg_header_clear(msg);
return (msg);
}
diff --git a/src/protocol/survey/survey.c b/src/protocol/survey/survey.c
index 91fe4ad3..45b06d67 100644
--- a/src/protocol/survey/survey.c
+++ b/src/protocol/survey/survey.c
@@ -33,8 +33,8 @@ struct nni_surv_sock {
nni_time expire;
int raw;
int closing;
- uint32_t nextid; // next id
- uint8_t survid[4]; // outstanding request ID (big endian)
+ uint32_t nextid; // next id
+ uint32_t survid; // outstanding request ID (big endian)
nni_list pipes;
nni_aio aio_getq;
nni_timer_node timer;
@@ -271,16 +271,13 @@ nni_surv_recv_cb(void *arg)
nni_msg_free(msg);
goto failed;
}
- if (nni_msg_append_header(msg, nni_msg_body(msg), 4) != 0) {
+ if (nni_msg_header_append(msg, nni_msg_body(msg), 4) != 0) {
// Should be NNG_ENOMEM
nni_msg_free(msg);
goto failed;
}
- if (nni_msg_trim(msg, 4) != 0) {
- // This should never happen - could be an assert.
- nni_msg_free(msg);
- goto failed;
- }
+ (void) nni_msg_trim(msg, 4);
+
ppipe->aio_putq.a_msg = msg;
nni_msgq_aio_put(ppipe->psock->urq, &ppipe->aio_putq);
return;
@@ -309,7 +306,7 @@ nni_surv_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
} else {
nni_sock_recverr(psock->nsock, NNG_ESTATE);
}
- memset(psock->survid, 0, sizeof(psock->survid));
+ psock->survid = 0;
nni_timer_cancel(&psock->timer);
}
break;
@@ -381,7 +378,7 @@ nni_surv_timeout(void *arg)
nni_surv_sock *psock = arg;
nni_sock_lock(psock->nsock);
- memset(psock->survid, 0, sizeof(psock->survid));
+ psock->survid = 0;
nni_sock_recverr(psock->nsock, NNG_ESTATE);
nni_msgq_set_get_error(psock->urq, NNG_ETIMEDOUT);
nni_sock_unlock(psock->nsock);
@@ -391,7 +388,6 @@ static nni_msg *
nni_surv_sock_sfilter(void *arg, nni_msg *msg)
{
nni_surv_sock *psock = arg;
- uint32_t id;
if (psock->raw) {
// No automatic retry, and the request ID must
@@ -402,12 +398,9 @@ nni_surv_sock_sfilter(void *arg, nni_msg *msg)
// Generate a new request ID. We always set the high
// order bit so that the peer can locate the end of the
// backtrace. (Pipe IDs have the high order bit clear.)
- id = (psock->nextid++) | 0x80000000u;
-
- // Survey ID is in big endian format.
- NNI_PUT32(psock->survid, id);
+ psock->survid = (psock->nextid++) | 0x80000000u;
- if (nni_msg_append_header(msg, psock->survid, 4) != 0) {
+ if (nni_msg_header_append_u32(msg, psock->survid) != 0) {
// Should be ENOMEM.
nni_msg_free(msg);
return (NULL);
@@ -436,18 +429,12 @@ nni_surv_sock_rfilter(void *arg, nni_msg *msg)
return (msg);
}
- if (nni_msg_header_len(msg) < 4) {
- nni_msg_free(msg);
- return (NULL);
- }
-
- if (memcmp(nni_msg_header(msg), ssock->survid, 4) != 0) {
+ if ((nni_msg_header_len(msg) < sizeof(uint32_t)) ||
+ (nni_msg_header_trim_u32(msg) != ssock->survid)) {
// Wrong request id
nni_msg_free(msg);
return (NULL);
}
- // Prune the survey ID.
- nni_msg_trim_header(msg, 4);
return (msg);
}