udp + SAT>IP: better multipacket handling

- improve the recvmmsg() user space implementation
- some changes which may improve operation under high-loads
This commit is contained in:
Jaroslav Kysela 2014-04-22 17:18:25 +02:00
parent 31977de37a
commit 21ad991222
2 changed files with 33 additions and 29 deletions

View file

@ -864,7 +864,8 @@ static void *
satip_frontend_input_thread ( void *aux )
{
#define RTP_PKTS 64
#define RTP_PKT_SIZE 1472 /* this is maximum UDP payload (standard ethernet) */
#define UDP_PKT_SIZE 1472 /* this is maximum UDP payload (standard ethernet) */
#define RTP_PKT_SIZE (UDP_PKT_SIZE - 12) /* minus RTP minimal RTP header */
#define HTTP_CMD_NONE 9874
satip_frontend_t *lfe = aux, *lfe2;
mpegts_mux_instance_t *mmi = lfe->sf_mmi;
@ -933,7 +934,7 @@ satip_frontend_input_thread ( void *aux )
}
udp_multirecv_init(&um, RTP_PKTS, RTP_PKT_SIZE);
sbuf_init_fixed(&sb, 18800);
sbuf_init_fixed(&sb, RTP_PKTS * RTP_PKT_SIZE);
while (tvheadend_running && !fatal) {
@ -1079,9 +1080,9 @@ satip_frontend_input_thread ( void *aux )
seq = nseq;
/* Process */
sbuf_append(&sb, p + pos, c - pos);
mpegts_input_recv_packets((mpegts_input_t*)lfe, mmi,
&sb, 0, NULL, NULL);
}
mpegts_input_recv_packets((mpegts_input_t*)lfe, mmi,
&sb, 0, NULL, NULL);
}
sbuf_free(&sb);

View file

@ -386,13 +386,10 @@ udp_write_queue( udp_connection_t *uc, htsbuf_queue_t *q,
* UDP multi packet receive support
*/
#ifndef CONFIG_RECVMMSG
#ifdef __linux__
#if !defined (CONFIG_RECVMMSG) && defined(__linux__)
/* define the syscall - works only for linux */
#include <linux/unistd.h>
#ifdef __NR_recvmmsg
struct mmsghdr {
struct msghdr msg_hdr;
@ -402,38 +399,44 @@ struct mmsghdr {
int recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
unsigned int flags, struct timespec *timeout);
#ifdef __NR_recvmmsg
int recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
unsigned int flags, struct timespec *timeout)
{
return syscall(__NR_recvmmsg, sockfd, msgvec, vlen, flags, timeout);
}
#else
#define CONFIG_RECVMMSG
#undef PKTS
#define PKTS 1
/* receive only single packet */
int recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
unsigned int flags, struct timespec *timeout)
#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)
{
ssize_t r = recvmsg(sockfd, &msgvec->msg_hdr, flags);
if (r < 0)
return r;
msgvec->msg_len = r;
return 1;
ssize_t r;
unsigned int i;
for (i = 0; i < vlen; i++) {
r = recvmsg(sockfd, &msgvec->msg_hdr, flags);
if (r < 0)
return (i > 0) ? i : r;
msgvec->msg_len = r;
msgvec++;
}
return i;
}
#endif
#else /* not __linux__ */
#error "Add recvmmsg() support for your platform!!!"
#endif
#endif /* !CONFIG_RECVMMSG */
void
udp_multirecv_init( udp_multirecv_t *um, int packets, int psize )