1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

lib: Add messaging_rec_create

Essentially a wrapper around messaging_rec_dup

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Volker Lendecke 2016-09-23 19:06:56 -07:00 committed by Jeremy Allison
parent f9a84411e8
commit 1cf8526c60

View File

@ -83,6 +83,8 @@ struct messaging_context {
struct server_id_db *names_db;
};
static struct messaging_rec *messaging_rec_dup(TALLOC_CTX *mem_ctx,
struct messaging_rec *rec);
static void messaging_dispatch_rec(struct messaging_context *msg_ctx,
struct messaging_rec *rec);
@ -105,6 +107,53 @@ static void ping_message(struct messaging_context *msg_ctx,
messaging_send(msg_ctx, src, MSG_PONG, data);
}
static struct messaging_rec *messaging_rec_create(
TALLOC_CTX *mem_ctx, struct server_id src, struct server_id dst,
uint32_t msg_type, const struct iovec *iov, int iovlen,
const int *fds, size_t num_fds)
{
ssize_t buflen;
uint8_t *buf;
struct messaging_rec *result;
if (num_fds > INT8_MAX) {
return NULL;
}
buflen = iov_buflen(iov, iovlen);
if (buflen == -1) {
return NULL;
}
buf = talloc_array(mem_ctx, uint8_t, buflen);
if (buf == NULL) {
return NULL;
}
iov_buf(iov, iovlen, buf, buflen);
{
struct messaging_rec rec;
int64_t fds64[num_fds];
size_t i;
for (i=0; i<num_fds; i++) {
fds64[i] = fds[i];
}
rec = (struct messaging_rec) {
.msg_version = MESSAGE_VERSION, .msg_type = msg_type,
.src = src, .dest = dst,
.buf.data = buf, .buf.length = buflen,
.num_fds = num_fds, .fds = fds64,
};
result = messaging_rec_dup(mem_ctx, &rec);
}
TALLOC_FREE(buf);
return result;
}
static void messaging_recv_cb(const uint8_t *msg, size_t msg_len,
int *fds, size_t num_fds,
void *private_data)