From e562837c0b5ed77ea7f556ea9365cdeda789cd68 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 11 Nov 2018 21:26:48 +0100 Subject: [PATCH] Avoid partial header reads Use net_recv_all() to avoid partial reads for the "meta" header (this would break the whole stream). --- app/src/decoder.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/decoder.c b/app/src/decoder.c index 309ddce2..655ed9eb 100644 --- a/app/src/decoder.c +++ b/app/src/decoder.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -30,11 +31,13 @@ static int read_packet(void *opaque, uint8_t *buf, int buf_size) { // the previous PTS read is now for the current frame decoder->pts = decoder->next_pts; - // FIXME what if only part of the header is available? - ret = net_recv(decoder->video_socket, header, HEADER_SIZE); + ret = net_recv_all(decoder->video_socket, header, HEADER_SIZE); if (ret <= 0) return ret; + // no partial read (net_recv_all()) + SDL_assert_release(ret == HEADER_SIZE); + // read the PTS for the next frame decoder->next_pts = buffer_read64be(header); remaining = buffer_read32be(&header[8]);