Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
udp: implement recvmmsg emulation for older linux kernels
  • Loading branch information
perexg committed Jan 1, 2015
1 parent 2dcf53f commit 9aa0600
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/udp.c
Expand Up @@ -497,17 +497,18 @@ int recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
#endif
#endif


#ifndef CONFIG_RECVMMSG

struct mmsghdr {
struct msghdr msg_hdr;
unsigned int msg_len;
};

static int
recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
unsigned int flags, struct timespec *timeout)
#endif

static inline int
recvmmsg_i(int sockfd, struct mmsghdr *msgvec,
unsigned int vlen, unsigned int flags)
{
ssize_t r;
unsigned int i;
Expand All @@ -522,8 +523,16 @@ recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
return i;
}

#endif
#ifndef CONFIG_RECVMMSG

int
recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
unsigned int flags, struct timespec *timeout)
{
return recvmmsg_i(sockfd, msgvec, vlen, flags);
}

#endif

void
udp_multirecv_init( udp_multirecv_t *um, int packets, int psize )
Expand Down Expand Up @@ -563,14 +572,24 @@ int
udp_multirecv_read( udp_multirecv_t *um, int fd, int packets,
struct iovec **iovec )
{
static char use_emul = 0;
int n, i;
if (um == NULL || iovec == NULL) {
errno = EINVAL;
return -1;
}
if (packets > um->um_packets)
packets = um->um_packets;
n = recvmmsg(fd, (struct mmsghdr *)um->um_msg, packets, MSG_DONTWAIT, NULL);
if (!use_emul) {
n = recvmmsg(fd, (struct mmsghdr *)um->um_msg, packets, MSG_DONTWAIT, NULL);
} else {
n = -1;
errno = ENOSYS;
}
if (n < 0 && errno == ENOSYS) {
use_emul = 1;
n = recvmmsg_i(fd, (struct mmsghdr *)um->um_msg, packets, MSG_DONTWAIT);
}
if (n > 0) {
for (i = 0; i < n; i++)
um->um_riovec[i].iov_len = ((struct mmsghdr *)um->um_msg)[i].msg_len;
Expand Down

0 comments on commit 9aa0600

Please sign in to comment.