mirror of
https://github.com/steve-m/hsdaoh.git
synced 2025-12-10 07:44:41 +01:00
hsdaoh_file: retry writing in case whole frame couldn't be written at once
This commit is contained in:
parent
e20acf8c15
commit
6c033c60b6
2 changed files with 13 additions and 4 deletions
|
|
@ -79,6 +79,8 @@ static void sighandler(int signum)
|
|||
|
||||
static void hsdaoh_callback(unsigned char *buf, uint32_t len, void *ctx)
|
||||
{
|
||||
size_t nbytes = 0;
|
||||
|
||||
if (ctx) {
|
||||
if (do_exit)
|
||||
return;
|
||||
|
|
@ -89,9 +91,15 @@ static void hsdaoh_callback(unsigned char *buf, uint32_t len, void *ctx)
|
|||
hsdaoh_stop_stream(dev);
|
||||
}
|
||||
|
||||
if (fwrite(buf, 1, len, (FILE*)ctx) != len) {
|
||||
fprintf(stderr, "Short write, samples lost, exiting!\n");
|
||||
hsdaoh_stop_stream(dev);
|
||||
while (nbytes < len) {
|
||||
nbytes += fwrite(buf + nbytes, 1, len - nbytes, (FILE*)ctx);
|
||||
|
||||
if (ferror((FILE*)ctx)) {
|
||||
fprintf(stderr, "Error writing file, samples lost, exiting!\n");
|
||||
hsdaoh_stop_stream(dev);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (bytes_to_read > 0)
|
||||
|
|
|
|||
|
|
@ -624,7 +624,8 @@ void hsdaoh_process_frame(hsdaoh_dev_t *dev, uint8_t *data, int size)
|
|||
payload_len &= 0x0fff;
|
||||
|
||||
if (payload_len > dev->width-1) {
|
||||
fprintf(stderr, "Invalid payload length: %d\n", payload_len);
|
||||
if (dev->stream_synced)
|
||||
fprintf(stderr, "Invalid payload length: %d\n", payload_len);
|
||||
|
||||
/* discard frame */
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue