diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-06 08:18:50 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-06 08:21:09 -0800 |
| commit | a2801adffebb6a3679e41789b38ba925ed32832b (patch) | |
| tree | 8e3a743301fedb04d19d9af3e30f5622b737c337 /src/protocol | |
| parent | 601d7a6ca95678613ca576258314f50a6e5e742c (diff) | |
| download | nng-a2801adffebb6a3679e41789b38ba925ed32832b.tar.gz nng-a2801adffebb6a3679e41789b38ba925ed32832b.tar.bz2 nng-a2801adffebb6a3679e41789b38ba925ed32832b.zip | |
Message API was awkward.
The use of a single function to get both size and length actually
turned out to be awkward to use; better to have separate functions
to get each. While here, disable some of the initialization/fork
checks, because it turns out they aren't needed.
Diffstat (limited to 'src/protocol')
| -rw-r--r-- | src/protocol/pubsub/sub.c | 3 | ||||
| -rw-r--r-- | src/protocol/reqrep/rep.c | 18 | ||||
| -rw-r--r-- | src/protocol/reqrep/req.c | 14 |
3 files changed, 14 insertions, 21 deletions
diff --git a/src/protocol/pubsub/sub.c b/src/protocol/pubsub/sub.c index 6cd22712..1243ca47 100644 --- a/src/protocol/pubsub/sub.c +++ b/src/protocol/pubsub/sub.c @@ -303,7 +303,8 @@ nni_sub_recvfilter(void *arg, nni_msg *msg) return (msg); } - body = nni_msg_body(msg, &len); + body = nni_msg_body(msg); + len = nni_msg_len(msg); // Check to see if the message matches one of our subscriptions. NNI_LIST_FOREACH (&sub->topics, topic) { diff --git a/src/protocol/reqrep/rep.c b/src/protocol/reqrep/rep.c index 8c375b61..5e9c3696 100644 --- a/src/protocol/reqrep/rep.c +++ b/src/protocol/reqrep/rep.c @@ -174,7 +174,6 @@ nni_rep_topsender(void *arg) for (;;) { uint8_t *header; - size_t size; uint32_t id; nni_rep_pipe *rp; int rv; @@ -183,11 +182,11 @@ nni_rep_topsender(void *arg) break; } // We yank the outgoing pipe id from the header - header = nni_msg_header(msg, &size); - if (size < 4) { + if (nni_msg_header_len(msg) < 4) { nni_msg_free(msg); continue; } + header = nni_msg_header(msg); NNI_GET32(header, id); nni_msg_trim_header(msg, 4); @@ -281,11 +280,11 @@ again: nni_msg_free(msg); goto again; } - body = nni_msg_body(msg, &len); - if (len < 4) { + if (nni_msg_len(msg) < 4) { nni_msg_free(msg); goto again; } + body = nni_msg_body(msg); end = (body[0] & 0x80) ? 1 : 0; rv = nni_msg_append_header(msg, body, 4); if (rv != 0) { @@ -293,7 +292,6 @@ again: goto again; } nni_msg_trim(msg, 4); - body = nni_msg_body(msg, &len); if (end) { break; } @@ -384,8 +382,7 @@ nni_rep_sendfilter(void *arg, nni_msg *msg) } // drop anything else in the header... - (void) nni_msg_header(msg, &len); - nni_msg_trim_header(msg, len); + nni_msg_trunc_header(msg, nni_msg_header_len(msg)); if (nni_msg_append_header(msg, rep->btrace, rep->btrace_len) != 0) { nni_free(rep->btrace, rep->btrace_len); @@ -418,7 +415,8 @@ nni_rep_recvfilter(void *arg, nni_msg *msg) } nni_sock_senderr(rep->sock, 0); - header = nni_msg_header(msg, &len); + len = nni_msg_header_len(msg); + header = nni_msg_header(msg); if (rep->btrace != NULL) { nni_free(rep->btrace, rep->btrace_len); rep->btrace = NULL; @@ -431,7 +429,7 @@ nni_rep_recvfilter(void *arg, nni_msg *msg) } rep->btrace_len = len; memcpy(rep->btrace, header, len); - nni_msg_trim_header(msg, len); + nni_msg_trunc_header(msg, len); nni_mtx_unlock(&rep->mx); return (msg); } diff --git a/src/protocol/reqrep/req.c b/src/protocol/reqrep/req.c index d4098526..037acd1c 100644 --- a/src/protocol/reqrep/req.c +++ b/src/protocol/reqrep/req.c @@ -206,20 +206,17 @@ nni_req_pipe_recv(void *arg) int rv; for (;;) { - size_t len; - char *body; rv = nni_pipe_recv(pipe, &msg); if (rv != 0) { break; } // We yank 4 bytes of body, and move them to the header. - body = nni_msg_body(msg, &len); - if (len < 4) { + if (nni_msg_len(msg) < 4) { // Not enough data, just toss it. nni_msg_free(msg); continue; } - if (nni_msg_append_header(msg, body, 4) != 0) { + if (nni_msg_append_header(msg, nni_msg_body(msg), 4) != 0) { // Should be NNG_ENOMEM nni_msg_free(msg); continue; @@ -375,8 +372,6 @@ static nni_msg * nni_req_recvfilter(void *arg, nni_msg *msg) { nni_req_sock *req = arg; - char *header; - size_t len; nni_mtx_lock(&req->mx); if (req->raw) { @@ -385,8 +380,7 @@ nni_req_recvfilter(void *arg, nni_msg *msg) return (msg); } - header = nni_msg_header(msg, &len); - if (len < 4) { + if (nni_msg_header_len(msg) < 4) { nni_mtx_unlock(&req->mx); nni_msg_free(msg); return (NULL); @@ -398,7 +392,7 @@ nni_req_recvfilter(void *arg, nni_msg *msg) nni_msg_free(msg); return (NULL); } - if (memcmp(header, req->reqid, 4) != 0) { + if (memcmp(nni_msg_header(msg), req->reqid, 4) != 0) { // Wrong request id nni_mtx_unlock(&req->mx); nni_msg_free(msg); |
