mmsg.test: prefer direct sendmmsg/recvmmsg syscalls to libc wrappers
* tests/mmsg.c: Include <sys/syscall.h>. Check for __NR_sendmmsg as an alternative to HAVE_SENDMMSG. [!HAVE_STRUCT_MMSGHDR] (struct mmsghdr): Define. (send_mmsg, recv_mmsg): New functions. (main): Use them instead of sendmmsg and recvmmsg. Reported-by: Szabolcs Nagy <nsz@port70.net>
This commit is contained in:
parent
8df07e1039
commit
6e815ce640
49
tests/mmsg.c
49
tests/mmsg.c
@ -27,8 +27,9 @@
|
||||
*/
|
||||
|
||||
#include "tests.h"
|
||||
# include <sys/syscall.h>
|
||||
|
||||
#if defined(HAVE_SENDMMSG) && defined(HAVE_STRUCT_MMSGHDR)
|
||||
#if defined __NR_sendmmsg || defined HAVE_SENDMMSG
|
||||
|
||||
# include <assert.h>
|
||||
# include <errno.h>
|
||||
@ -36,6 +37,46 @@
|
||||
# include <unistd.h>
|
||||
# include <sys/socket.h>
|
||||
|
||||
#ifndef HAVE_STRUCT_MMSGHDR
|
||||
struct mmsghdr {
|
||||
struct msghdr msg_hdr;
|
||||
unsigned msg_len;
|
||||
};
|
||||
#endif
|
||||
|
||||
static int
|
||||
send_mmsg(int fd, struct mmsghdr *vec, unsigned int vlen, unsigned int flags)
|
||||
{
|
||||
int rc;
|
||||
#ifdef __NR_sendmmsg
|
||||
rc = syscall(__NR_sendmmsg, (long) fd, vec, (unsigned long) vlen,
|
||||
(unsigned long) flags);
|
||||
if (rc >= 0 || ENOSYS != errno)
|
||||
return rc;
|
||||
#endif
|
||||
#ifdef HAVE_SENDMMSG
|
||||
rc = sendmmsg(fd, vec, vlen, flags);
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int
|
||||
recv_mmsg(int fd, struct mmsghdr *vec, unsigned int vlen, unsigned int flags,
|
||||
struct timespec *timeout)
|
||||
{
|
||||
int rc;
|
||||
#ifdef __NR_sendmmsg
|
||||
rc = syscall(__NR_recvmmsg, (long) fd, vec, (unsigned long) vlen,
|
||||
(unsigned long) flags, timeout);
|
||||
if (rc >= 0 || ENOSYS != errno)
|
||||
return rc;
|
||||
#endif
|
||||
#ifdef HAVE_SENDMMSG
|
||||
rc = recvmmsg(fd, vec, vlen, flags, timeout);
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
@ -91,13 +132,13 @@ main(void)
|
||||
assert(dup2(sv[R], R) == R);
|
||||
assert(close(sv[R]) == 0);
|
||||
|
||||
int r = sendmmsg(W, mmh, n_mmh, 0);
|
||||
int r = send_mmsg(W, mmh, n_mmh, 0);
|
||||
if (r < 0 && errno == ENOSYS)
|
||||
perror_msg_and_skip("sendmmsg");
|
||||
assert((size_t)r == n_mmh);
|
||||
assert(close(W) == 0);
|
||||
|
||||
assert(recvmmsg(R, mmh, n_mmh, 0, NULL) == n_mmh);
|
||||
assert(recv_mmsg(R, mmh, n_mmh, 0, NULL) == n_mmh);
|
||||
assert(close(R) == 0);
|
||||
|
||||
return 0;
|
||||
@ -105,6 +146,6 @@ main(void)
|
||||
|
||||
#else
|
||||
|
||||
SKIP_MAIN_UNDEFINED("HAVE_SENDMMSG && HAVE_STRUCT_MMSGHDR")
|
||||
SKIP_MAIN_UNDEFINED("__NR_sendmmsg || HAVE_SENDMMSG")
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user