aboutsummaryrefslogtreecommitdiff
path: root/src/Downloader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Downloader.cpp')
-rw-r--r--src/Downloader.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/Downloader.cpp b/src/Downloader.cpp
index cb9f448..57a0349 100644
--- a/src/Downloader.cpp
+++ b/src/Downloader.cpp
@@ -310,8 +310,20 @@ namespace QuickMedia {
return offset;
}
+ static ssize_t read_eintr(int fd, void *buffer, size_t size) {
+ while(true) {
+ ssize_t bytes_read = read(fd, buffer, size);
+ if(bytes_read == -1) {
+ if(errno != EINTR)
+ return -1;
+ } else {
+ return bytes_read;
+ }
+ }
+ }
+
static int64_t read_fn(YoutubeReadProgram *program, char *buf, uint64_t nbytes) {
- ssize_t bytes_read = read(program->read_program.read_fd, buf, nbytes);
+ ssize_t bytes_read = read_eintr(program->read_program.read_fd, buf, nbytes);
if(bytes_read > 0) {
program->offset += bytes_read;
program->bytes_downloaded += bytes_read;
@@ -319,15 +331,12 @@ namespace QuickMedia {
// End of current range, progress to next range
bytes_read = seek_fn(program, program->offset);
if(bytes_read >= 0) {
- bytes_read = read(program->read_program.read_fd, buf, nbytes);
+ bytes_read = read_eintr(program->read_program.read_fd, buf, nbytes);
if(bytes_read > 0) {
program->offset += bytes_read;
program->bytes_downloaded += bytes_read;
}
}
- } else if(bytes_read < 0) {
- if(errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN)
- return 0;
}
return bytes_read;
}