mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refine sendmmsg, move to ST
This commit is contained in:
parent
2a0562da5e
commit
f71b833520
5 changed files with 40 additions and 52 deletions
29
trunk/3rdparty/st-srs/io.c
vendored
29
trunk/3rdparty/st-srs/io.c
vendored
|
@ -742,12 +742,9 @@ int st_sendmsg(_st_netfd_t *fd, const struct msghdr *msg, int flags, st_utime_t
|
|||
return n;
|
||||
}
|
||||
|
||||
|
||||
int st_sendmmsg(st_netfd_t fd, void *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)
|
||||
return -1;
|
||||
#else
|
||||
#if defined(MD_HAVE_SENDMMSG) && defined(_GNU_SOURCE)
|
||||
int n;
|
||||
int left;
|
||||
struct mmsghdr *p;
|
||||
|
@ -774,6 +771,28 @@ int st_sendmmsg(st_netfd_t fd, void *msgvec, unsigned int vlen, int flags, st_ut
|
|||
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
|
||||
}
|
||||
|
||||
|
|
10
trunk/3rdparty/st-srs/public.h
vendored
10
trunk/3rdparty/st-srs/public.h
vendored
|
@ -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, void *msgvec, unsigned int vlen, int flags, st_utime_t timeout);
|
||||
|
||||
// @see http://man7.org/linux/man-pages/man2/sendmmsg.2.html
|
||||
#include <sys/socket.h>
|
||||
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
|
||||
|
|
|
@ -608,6 +608,11 @@ function apply_user_detail_options() {
|
|||
echo "Disable SRTP ASM, because NASM is disabled."
|
||||
SRS_SRTP_ASM=NO
|
||||
fi
|
||||
|
||||
if [[ $SRS_OSX == YES && $SRS_SENDMMSG == YES ]]; then
|
||||
echo "Disable sendmmsg for OSX"
|
||||
SRS_SENDMMSG=NO
|
||||
fi
|
||||
}
|
||||
apply_user_detail_options
|
||||
|
||||
|
|
2
trunk/configure
vendored
2
trunk/configure
vendored
|
@ -188,7 +188,7 @@ if [[ $SRS_GCOV == YES ]]; then
|
|||
SrsLinkOptions="${SrsLinkOptions} ${SrsGcov}";
|
||||
fi
|
||||
# For FFMPEG/RTC.
|
||||
if [[ $SRS_RTC == YES && $SRS_NASM == NO ]]; then
|
||||
if [[ $SRS_RTC == YES && $SRS_NASM == NO && $SRS_OSX == NO ]]; then
|
||||
SrsLinkOptions="${SrsLinkOptions} -lrt";
|
||||
fi
|
||||
|
||||
|
|
|
@ -414,51 +414,7 @@ int srs_sendmsg(srs_netfd_t stfd, const struct msghdr *msg, int flags, srs_utime
|
|||
|
||||
int srs_sendmmsg(srs_netfd_t stfd, struct srs_mmsghdr *msgvec, unsigned int vlen, int flags, srs_utime_t timeout)
|
||||
{
|
||||
#if !defined(SRS_SENDMMSG)
|
||||
// @see http://man7.org/linux/man-pages/man2/sendmmsg.2.html
|
||||
for (int i = 0; i < (int)vlen; ++i) {
|
||||
struct srs_mmsghdr* p = msgvec + i;
|
||||
int n = srs_sendmsg(stfd, &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;
|
||||
#else
|
||||
if (vlen == 1) {
|
||||
#if 1
|
||||
int r0 = srs_sendmsg(stfd, &msgvec->msg_hdr, flags, timeout);
|
||||
if (r0 < 0) {
|
||||
return r0;
|
||||
}
|
||||
msgvec->msg_len = r0;
|
||||
#else
|
||||
msgvec->msg_len = 0;
|
||||
|
||||
int tolen = (int)msgvec->msg_hdr.msg_namelen;
|
||||
const struct sockaddr* to = (const struct sockaddr*)msgvec->msg_hdr.msg_name;
|
||||
for (int i = 0; i < (int)msgvec->msg_hdr.msg_iovlen; i++) {
|
||||
iovec* iov = msgvec->msg_hdr.msg_iov + i;
|
||||
int r0 = srs_sendto(stfd, (void*)iov->iov_base, (int)iov->iov_len, to, tolen, timeout);
|
||||
if (r0 < 0) {
|
||||
return r0;
|
||||
}
|
||||
msgvec->msg_len += r0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
return st_sendmmsg((st_netfd_t)stfd, (void*)msgvec, vlen, flags, (st_utime_t)timeout);
|
||||
#endif
|
||||
return st_sendmmsg((st_netfd_t)stfd, (struct st_mmsghdr*)msgvec, vlen, flags, (st_utime_t)timeout);
|
||||
}
|
||||
|
||||
srs_netfd_t srs_accept(srs_netfd_t stfd, struct sockaddr *addr, int *addrlen, srs_utime_t timeout)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue