diff options
author | Michael Adam <obnox@samba.org> | 2014-09-29 12:15:54 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2014-09-30 16:36:10 +0200 |
commit | a96f0f4c3bd66cb44f882a836bf80b2ce39523e0 (patch) | |
tree | c95b650366d99290e4696635d0d3bfbff227dd33 | |
parent | e38f4f4ceb5b2605dd0804ab7629f9b5e8d5cd5c (diff) | |
download | samba-a96f0f4c3bd66cb44f882a836bf80b2ce39523e0.tar.gz |
s3:unix_msg: use an iov in unix_dgram_msg/queue_msg instead of buffer and length
This is equivalent, reads more easily and makes extraction
more obvious.
Pair-Programmed-With: Volker Lendecke <vl@samba.org>
Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Volker Lendecke <vl@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
-rw-r--r-- | source3/lib/unix_msg/unix_msg.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/source3/lib/unix_msg/unix_msg.c b/source3/lib/unix_msg/unix_msg.c index dca2ab151b9..87265757776 100644 --- a/source3/lib/unix_msg/unix_msg.c +++ b/source3/lib/unix_msg/unix_msg.c @@ -44,8 +44,7 @@ struct unix_dgram_msg { int sys_errno; size_t num_fds; int *fds; - size_t buflen; - uint8_t buf[]; + struct iovec iov; }; struct unix_dgram_send_queue { @@ -480,7 +479,8 @@ static int queue_msg(struct unix_dgram_send_queue *q, goto invalid; } - msglen = offsetof(struct unix_dgram_msg, buf); + msglen = sizeof(struct unix_dgram_msg); + tmp = msglen + data_len; if ((tmp < msglen) || (tmp < data_len)) { /* overflow */ @@ -514,10 +514,16 @@ static int queue_msg(struct unix_dgram_send_queue *q, ret = ENOMEM; goto fail; } - msg->buflen = data_len; + msg->sock = q->sock; - data_buf = msg->buf; + data_buf = (uint8_t *)(msg + 1); + + msg->iov = (struct iovec) { + .iov_base = (void *)data_buf, + .iov_len = data_len, + }; + for (i=0; i<iovlen; i++) { memcpy(data_buf, iov[i].iov_base, iov[i].iov_len); data_buf += iov[i].iov_len; @@ -547,12 +553,8 @@ fail: static void unix_dgram_send_job(void *private_data) { struct unix_dgram_msg *dmsg = private_data; - struct iovec iov = { - .iov_base = (void *)dmsg->buf, - .iov_len = dmsg->buflen, - }; struct msghdr msg = { - .msg_iov = &iov, + .msg_iov = &dmsg->iov, .msg_iovlen = 1, }; #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL |