aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nng.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/nng.c b/src/nng.c
index 944d43fc..dd82bcee 100644
--- a/src/nng.c
+++ b/src/nng.c
@@ -105,14 +105,19 @@ nng_recv(nng_socket s, void *buf, size_t *szp, int flags)
// better use nng_recvmsg() instead.
void *nbuf;
- if ((nbuf = nni_alloc(nng_msg_len(msg))) == NULL) {
- nng_msg_free(msg);
- return (NNG_ENOMEM);
+ if (nng_msg_len(msg) != 0) {
+ if ((nbuf = nni_alloc(nng_msg_len(msg))) == NULL) {
+ nng_msg_free(msg);
+ return (NNG_ENOMEM);
+ }
+
+ *(void **) buf = nbuf;
+ memcpy(nbuf, nni_msg_body(msg), nni_msg_len(msg));
+ *szp = nng_msg_len(msg);
+ } else {
+ *(void **)buf = NULL;
+ *szp = 0;
}
-
- *(void **) buf = nbuf;
- memcpy(nbuf, nni_msg_body(msg), nni_msg_len(msg));
- *szp = nng_msg_len(msg);
}
nni_msg_free(msg);
return (0);