diff --git a/trunk/3rdparty/st-srs/Makefile b/trunk/3rdparty/st-srs/Makefile index 7e641d195..7102eedb4 100644 --- a/trunk/3rdparty/st-srs/Makefile +++ b/trunk/3rdparty/st-srs/Makefile @@ -189,10 +189,6 @@ OTHER_FLAGS = -Wall ifeq ($(shell test -f /usr/include/sys/epoll.h && echo yes), yes) DEFINES += -DMD_HAVE_EPOLL endif -# For SRS, sendmmsg -ifeq ($(shell grep -qs sendmmsg /usr/include/sys/socket.h && echo yes), yes) -DEFINES += -DMD_HAVE_SENDMMSG -D_GNU_SOURCE -endif endif ifeq ($(OS), NETBSD) diff --git a/trunk/3rdparty/st-srs/io.c b/trunk/3rdparty/st-srs/io.c index 750099450..7e05f99ae 100644 --- a/trunk/3rdparty/st-srs/io.c +++ b/trunk/3rdparty/st-srs/io.c @@ -742,17 +742,16 @@ int st_sendmsg(_st_netfd_t *fd, const struct msghdr *msg, int flags, st_utime_t return n; } - -#if defined(MD_HAVE_SENDMMSG) && defined(_GNU_SOURCE) -int st_sendmmsg(st_netfd_t fd, struct mmsghdr *msgvec, unsigned int vlen, int flags, st_utime_t timeout) +int st_sendmmsg(st_netfd_t fd, struct st_mmsghdr *msgvec, unsigned int vlen, int flags, st_utime_t timeout) { +#if defined(MD_HAVE_SENDMMSG) && defined(_GNU_SOURCE) int n; int left; struct mmsghdr *p; left = (int)vlen; while (left > 0) { - p = msgvec + (vlen - left); + p = (struct mmsghdr*)msgvec + (vlen - left); if ((n = sendmmsg(fd->osfd, p, left, flags)) < 0) { if (errno == EINTR) @@ -772,8 +771,30 @@ int st_sendmmsg(st_netfd_t fd, struct mmsghdr *msgvec, unsigned int vlen, int fl return n; } return (int)vlen - left; -} +#else + struct st_mmsghdr *p; + int i, n; + + // @see http://man7.org/linux/man-pages/man2/sendmmsg.2.html + for (i = 0; i < (int)vlen; ++i) { + p = msgvec + i; + n = st_sendmsg(fd, &p->msg_hdr, flags, timeout); + if (n < 0) { + // An error is returned only if no datagrams could be sent. + if (i == 0) { + return n; + } + return i + 1; + } + + p->msg_len = n; + } + + // Returns the number of messages sent from msgvec; if this is less than vlen, the caller can retry with a + // further sendmmsg() call to send the remaining messages. + return vlen; #endif +} /* diff --git a/trunk/3rdparty/st-srs/public.h b/trunk/3rdparty/st-srs/public.h index c54bd790a..80fd93346 100644 --- a/trunk/3rdparty/st-srs/public.h +++ b/trunk/3rdparty/st-srs/public.h @@ -151,7 +151,15 @@ extern int st_recvfrom(st_netfd_t fd, void *buf, int len, struct sockaddr *from, extern int st_sendto(st_netfd_t fd, const void *msg, int len, const struct sockaddr *to, int tolen, st_utime_t timeout); extern int st_recvmsg(st_netfd_t fd, struct msghdr *msg, int flags, st_utime_t timeout); extern int st_sendmsg(st_netfd_t fd, const struct msghdr *msg, int flags, st_utime_t timeout); -extern int st_sendmmsg(st_netfd_t fd, struct mmsghdr *msgvec, unsigned int vlen, int flags, st_utime_t timeout); + +// @see http://man7.org/linux/man-pages/man2/sendmmsg.2.html +#include +struct st_mmsghdr { + struct msghdr msg_hdr; /* Message header */ + unsigned int msg_len; /* Number of bytes transmitted */ +}; +extern int st_sendmmsg(st_netfd_t fd, struct st_mmsghdr *msgvec, unsigned int vlen, int flags, st_utime_t timeout); + extern st_netfd_t st_open(const char *path, int oflags, mode_t mode); #ifdef DEBUG