state.buf = NULL;
state.buflen = 0;
- ret = unix_msg_send(ctx1, &addr2, NULL, 0);
+ ret = unix_msg_send(ctx1, &addr2, NULL, 0, NULL, 0);
if (ret != 0) {
fprintf(stderr, "unix_msg_send failed: %s\n",
strerror(ret));
state.buf = &msg;
state.buflen = sizeof(msg);
- ret = unix_msg_send(ctx1, &addr2, &iov, 1);
+ ret = unix_msg_send(ctx1, &addr2, &iov, 1, NULL, 0);
if (ret != 0) {
fprintf(stderr, "unix_msg_send failed: %s\n",
strerror(ret));
state.buflen = sizeof(buf);
for (i=0; i<3; i++) {
- ret = unix_msg_send(ctx1, &addr2, &iov, 1);
+ ret = unix_msg_send(ctx1, &addr2, &iov, 1, NULL, 0);
if (ret != 0) {
fprintf(stderr, "unix_msg_send failed: %s\n",
strerror(ret));
return 1;
}
- ret = unix_msg_send(ctx2, &addr2, &iov, 1);
+ ret = unix_msg_send(ctx2, &addr2, &iov, 1, NULL, 0);
if (ret != 0) {
fprintf(stderr, "unix_msg_send failed: %s\n",
strerror(ret));
j++;
}
- ret = unix_msg_send(ctx1, &addr1, iovs, j);
+ ret = unix_msg_send(ctx1, &addr1, iovs, j, NULL, 0);
if (ret != 0) {
fprintf(stderr, "unix_msg_send failed: %s\n",
strerror(ret));
printf("Filling send queues before freeing\n");
for (i=0; i<5; i++) {
- ret = unix_msg_send(ctx1, &addr2, &iov, 1);
+ ret = unix_msg_send(ctx1, &addr2, &iov, 1, NULL, 0);
if (ret != 0) {
fprintf(stderr, "unix_msg_send failed: %s\n",
strerror(ret));
return 1;
}
- ret = unix_msg_send(ctx1, &addr1, &iov, 1);
+ ret = unix_msg_send(ctx1, &addr1, &iov, 1, NULL, 0);
if (ret != 0) {
fprintf(stderr, "unix_msg_send failed: %s\n",
strerror(ret));
}
int unix_msg_send(struct unix_msg_ctx *ctx, const struct sockaddr_un *dst,
- const struct iovec *iov, int iovlen)
+ const struct iovec *iov, int iovlen,
+ const int *fds, size_t num_fds)
{
ssize_t msglen;
size_t sent;
return EINVAL;
}
+#ifndef HAVE_STRUCT_MSGHDR_MSG_CONTROL
+ if (num_fds > 0) {
+ return ENOSYS;
+ }
+#endif /* ! HAVE_STRUCT_MSGHDR_MSG_CONTROL */
+
+ if (num_fds > INT8_MAX) {
+ return EINVAL;
+ }
+
if (msglen <= (ctx->fragment_len - sizeof(uint64_t))) {
uint64_t cookie = 0;
}
return unix_dgram_send(ctx->dgram, dst, iov_copy, iovlen+1,
- NULL, 0);
+ fds, num_fds);
}
hdr = (struct unix_msg_hdr) {
}
sent += (fragment_len - sizeof(ctx->cookie) - sizeof(hdr));
- ret = unix_dgram_send(ctx->dgram, dst, iov_copy, iov_index,
- NULL, 0);
+ /*
+ * only the last fragment should pass the fd array.
+ * That simplifies the receiver a lot.
+ */
+ if (sent < msglen) {
+ ret = unix_dgram_send(ctx->dgram, dst,
+ iov_copy, iov_index,
+ NULL, 0);
+ } else {
+ ret = unix_dgram_send(ctx->dgram, dst,
+ iov_copy, iov_index,
+ fds, num_fds);
+ }
if (ret != 0) {
break;
}
* @param[in] dst_sock The destination socket path
* @param[in] iov The message
* @param[in] iovlen The number of iov structs
+ * @param[in] fds - optional fd array
+ * @param[in] num_fds - fd array size
* @return 0 on success, errno on failure
*/
int unix_msg_send(struct unix_msg_ctx *ctx, const struct sockaddr_un *dst,
- const struct iovec *iov, int iovlen);
+ const struct iovec *iov, int iovlen,
+ const int *fds, size_t num_fds);
/**
* @brief Free a unix_msg_ctx