Don't try to writev() longer vectors than sysconf(_SC_IOV_MAX) says

This commit is contained in:
Andreas Öman 2010-09-12 19:23:48 +00:00
parent 81c729cbc8
commit 88c02ef4cf
2 changed files with 19 additions and 9 deletions

View file

@ -38,10 +38,10 @@ int dvr_flags;
int dvr_extra_time_pre;
int dvr_extra_time_post;
char *dvr_postproc;
int dvr_iov_max;
static int de_tally;
struct dvr_entry_list dvrentries;
static void dvr_entry_save(dvr_entry_t *de);
@ -721,6 +721,8 @@ dvr_init(void)
struct stat st;
uint32_t u32;
dvr_iov_max = sysconf(_SC_IOV_MAX);
/* Default settings */
dvr_retention_days = 31;

View file

@ -31,6 +31,8 @@
#include "mkmux.h"
#include "ebml.h"
extern int dvr_iov_max;
TAILQ_HEAD(mk_cue_queue, mk_cue);
#define MATROSKA_TIMESCALE 1000000 // in nS
@ -311,14 +313,20 @@ mk_write_to_fd(mk_mux_t *mkm, htsbuf_queue_t *hq)
iov[i ].iov_base = hd->hd_data + hd->hd_data_off;
iov[i++].iov_len = hd->hd_data_len - hd->hd_data_off;
}
if(writev(mkm->fd, iov, i) != hq->hq_size) {
mkm->error = errno;
tvhlog(LOG_ERR, "MKV", "%s: Unable to write -- %s",
mkm->filename, strerror(errno));
} else {
mkm->fdpos += hq->hq_size;
}
do {
ssize_t r;
int iovcnt = i < dvr_iov_max ? i : dvr_iov_max;
if((r = writev(mkm->fd, iov, iovcnt)) == -1) {
mkm->error = errno;
tvhlog(LOG_ERR, "MKV", "%s: Unable to write -- %s",
mkm->filename, strerror(errno));
return;
}
mkm->fdpos += r;
i -= iovcnt;
iov += iovcnt;
} while(i);
}