1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Merge ST, support utest and coverage by gtest.

This commit is contained in:
winlin 2021-03-03 10:26:30 +08:00
parent 3bb1b673c5
commit 7d12c3641a
11 changed files with 444 additions and 3 deletions

View file

@ -68,6 +68,8 @@ unsigned long long _st_stat_recvmsg = 0;
unsigned long long _st_stat_recvmsg_eagain = 0;
unsigned long long _st_stat_sendmsg = 0;
unsigned long long _st_stat_sendmsg_eagain = 0;
unsigned long long _st_stat_sendmmsg = 0;
unsigned long long _st_stat_sendmmsg_eagain = 0;
#endif
#if EAGAIN != EWOULDBLOCK
@ -831,6 +833,69 @@ 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, 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;
#if defined(DEBUG) && defined(DEBUG_STATS)
++_st_stat_sendmmsg;
#endif
left = (int)vlen;
while (left > 0) {
p = (struct mmsghdr*)msgvec + (vlen - left);
if ((n = sendmmsg(fd->osfd, p, left, flags)) < 0) {
if (errno == EINTR)
continue;
if (!_IO_NOT_READY_ERROR)
break;
#if defined(DEBUG) && defined(DEBUG_STATS)
++_st_stat_sendmmsg_eagain;
#endif
/* Wait until the socket becomes writable */
if (st_netfd_poll(fd, POLLOUT, timeout) < 0)
break;
}
left -= n;
}
// An error is returned only if no datagrams could be sent.
if (left == (int)vlen) {
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
}
/*
* To open FIFOs or other special files.