# include <assert.h>
# include <errno.h>
+# include <stdio.h>
# include <unistd.h>
# include <sys/socket.h>
-#ifndef HAVE_STRUCT_MMSGHDR
+# ifndef HAVE_STRUCT_MMSGHDR
struct mmsghdr {
struct msghdr msg_hdr;
unsigned msg_len;
};
-#endif
+# endif
+
+# define LENGTH_OF(arg) ((unsigned int) sizeof(arg) - 1)
+
+static FILE *logfp;
static int
send_mmsg(int fd, struct mmsghdr *vec, unsigned int vlen, unsigned int flags)
(unsigned long) flags);
if (rc >= 0 || ENOSYS != errno)
return rc;
+ fprintf(logfp,
+ "sendmmsg(%d, %p, %u, MSG_DONTROUTE|MSG_NOSIGNAL)"
+ " = -1 ENOSYS (%m)\n", fd, vec, vlen);
#endif
#ifdef HAVE_SENDMMSG
rc = sendmmsg(fd, vec, vlen, flags);
(unsigned long) flags, timeout);
if (rc >= 0 || ENOSYS != errno)
return rc;
+ fprintf(logfp,
+ "recvmmsg(%d, %p, %u, MSG_DONTWAIT, NULL)"
+ " = -1 ENOSYS (%m)\n", fd, vec, vlen);
#endif
#ifdef HAVE_RECVMMSG
rc = recvmmsg(fd, vec, vlen, flags, timeout);
const int R = 0, W = 1;
int sv[2];
+ int logfd = dup(1);
+ assert(logfd > 2);
+ assert((logfp = fdopen(logfd, "w")));
+
(void) close(0);
(void) close(1);
if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sv))
static const char one[] = "one";
static const char two[] = "two";
static const char three[] = "three";
- void *copy_one = tail_memdup(one, sizeof(one) - 1);
- void *copy_two = tail_memdup(two, sizeof(two) - 1);
- void *copy_three = tail_memdup(three, sizeof(three) - 1);
+ static const char ascii_one[] = "6f 6e 65";
+ static const char ascii_two[] = "74 77 6f";
+ static const char ascii_three[] = "74 68 72 65 65";
+
+ void *copy_one = tail_memdup(one, LENGTH_OF(one));
+ void *copy_two = tail_memdup(two, LENGTH_OF(two));
+ void *copy_three = tail_memdup(three, LENGTH_OF(three));
struct iovec iov[] = {
{
.iov_base = copy_one,
- .iov_len = sizeof(one) - 1
+ .iov_len = LENGTH_OF(one)
}, {
.iov_base = copy_two,
- .iov_len = sizeof(two) - 1
+ .iov_len = LENGTH_OF(two)
}, {
.iov_base = copy_three,
- .iov_len = sizeof(three) - 1
+ .iov_len = LENGTH_OF(three)
}
};
struct iovec *copy_iov = tail_memdup(iov, sizeof(iov));
}
};
void *copy_mmh = tail_memdup(mmh, sizeof(mmh));
-# define n_mmh (sizeof(mmh)/sizeof(mmh[0]))
+# define n_mmh ((unsigned int) (sizeof(mmh)/sizeof(mmh[0])))
int r = send_mmsg(W, copy_mmh, n_mmh, MSG_DONTROUTE | MSG_NOSIGNAL);
if (r < 0 && errno == ENOSYS)
perror_msg_and_skip("sendmmsg");
- assert((size_t)r == n_mmh);
+ assert(r == (int) n_mmh);
assert(close(W) == 0);
-
- assert(recv_mmsg(R, copy_mmh, n_mmh, MSG_DONTWAIT, NULL) == n_mmh);
+ fprintf(logfp,
+ "sendmmsg(%d, {{{msg_name(0)=NULL, msg_iov(%u)=[{\"%s\", %u}"
+ ", {\"%s\", %u}], msg_controllen=0, msg_flags=0}, %u}"
+ ", {{msg_name(0)=NULL, msg_iov(%u)=[{\"%s\", %u}]"
+ ", msg_controllen=0, msg_flags=0}, %u}}, %u"
+ ", MSG_DONTROUTE|MSG_NOSIGNAL) = %d\n"
+ " = %u buffers in vector 0\n"
+ " * %u bytes in buffer 0\n"
+ " | 00000 %-48s %-16s |\n"
+ " * %u bytes in buffer 1\n"
+ " | 00000 %-48s %-16s |\n"
+ " = %u buffers in vector 1\n"
+ " * %u bytes in buffer 0\n"
+ " | 00000 %-48s %-16s |\n",
+ W, 2, one, LENGTH_OF(one), two, LENGTH_OF(two),
+ LENGTH_OF(one) + LENGTH_OF(two),
+ 1, three, LENGTH_OF(three), LENGTH_OF(three),
+ n_mmh, r,
+ 2, LENGTH_OF(one), ascii_one, one,
+ LENGTH_OF(two), ascii_two, two,
+ 1, LENGTH_OF(three), ascii_three, three);
+
+ assert(recv_mmsg(R, copy_mmh, n_mmh, MSG_DONTWAIT, NULL) == (int) n_mmh);
assert(close(R) == 0);
-
+ fprintf(logfp,
+ "recvmmsg(%d, {{{msg_name(0)=NULL, msg_iov(%u)=[{\"%s\", %u}"
+ ", {\"%s\", %u}], msg_controllen=0, msg_flags=0}, %u}"
+ ", {{msg_name(0)=NULL, msg_iov(%u)=[{\"%s\", %u}]"
+ ", msg_controllen=0, msg_flags=0}, %u}}, %u"
+ ", MSG_DONTWAIT, NULL) = %d (left NULL)\n"
+ " = %u buffers in vector 0\n"
+ " * %u bytes in buffer 0\n"
+ " | 00000 %-48s %-16s |\n"
+ " * %u bytes in buffer 1\n"
+ " | 00000 %-48s %-16s |\n"
+ " = %u buffers in vector 1\n"
+ " * %u bytes in buffer 0\n"
+ " | 00000 %-48s %-16s |\n",
+ R, 2, one, LENGTH_OF(one), two, LENGTH_OF(two),
+ LENGTH_OF(one) + LENGTH_OF(two),
+ 1, three, LENGTH_OF(three), LENGTH_OF(three),
+ n_mmh, r,
+ 2, LENGTH_OF(one), ascii_one, one,
+ LENGTH_OF(two), ascii_two, two,
+ 1, LENGTH_OF(three), ascii_three, three);
+
+ fprintf(logfp, "+++ exited with 0 +++\n");
return 0;
}