libspark/record: always fill read buffer

This commit is contained in:
martii
2014-06-28 09:33:47 +02:00
parent ac92e6a38e
commit f77184cb68

View File

@@ -244,29 +244,37 @@ void cRecord::RecordThread()
while (exit_flag == RECORD_RUNNING) while (exit_flag == RECORD_RUNNING)
{ {
ssize_t s = dmx->Read(io_buf[chunk], readsize, 50); uint8_t *bufstart = io_buf[chunk];
lt_debug("%s: Read chunk=%d size=%d\n", __func__, chunk, s); int left = readsize;
if (s < 0) ssize_t len = 0;
{ while ((exit_flag == RECORD_RUNNING) && (left > 0)) {
if (errno != EAGAIN && (errno != EOVERFLOW || overflow_count > 63 /* arbitrary */)) int s = dmx->Read(bufstart, left, 50);
lt_debug("%s: Read chunk=%d size=%d\n", __func__, chunk, s);
if (s < 0)
{ {
lt_info("%s: read failed: %m\n", __func__); if (errno != EAGAIN && (errno != EOVERFLOW || overflow_count > 63 /* arbitrary */))
exit_flag = RECORD_FAILED_READ; {
break; lt_info("%s: read failed: %m\n", __func__);
exit_flag = RECORD_FAILED_READ;
break;
}
if (!overflow_count)
lt_info("%s: dmx->Read(): %m\n", __func__);
overflow_count++;
continue;
}
len += s;
left -= s;
bufstart += s;
if (overflow_count) {
lt_info("%s: Overflow cleared after %d iterations\n", __func__, overflow_count);
overflow_count = 0;
} }
if (!overflow_count)
lt_info("%s: dmx->Read(): %m\n", __func__);
overflow_count++;
continue;
} }
if (overflow_count) { if (!len)
lt_info("%s: Overflow cleared after %d iterations\n", __func__, overflow_count);
overflow_count = 0;
}
if (!s)
continue; continue;
io_len[chunk] = s; io_len[chunk] = len;
sem_post(&sem); sem_post(&sem);
chunk++; chunk++;
chunk %= RECORD_WRITER_CHUNKS; chunk %= RECORD_WRITER_CHUNKS;