diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-03-09 06:21:10 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-03-09 06:21:10 +0100 |
commit | 037040ebcc26a75cc6e9a29610e1683dc5acbe24 (patch) | |
tree | d8c6538d3a6be70119c0299daf82ed69908e4ac8 /src | |
parent | 15d06abbc5a8752631288441131b3ebf9124f25b (diff) |
youtube proxy: dont make write to client with data blocking
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/youtube/YoutubeMediaProxy.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/plugins/youtube/YoutubeMediaProxy.cpp b/src/plugins/youtube/YoutubeMediaProxy.cpp index 4d84674..e51e3d9 100644 --- a/src/plugins/youtube/YoutubeMediaProxy.cpp +++ b/src/plugins/youtube/YoutubeMediaProxy.cpp @@ -30,6 +30,20 @@ static ssize_t read_eintr(int fd, void *buffer, size_t size) { } } +static ssize_t write_all(int fd, const void *buffer, size_t size) { + ssize_t bytes_written = 0; + while((size_t)bytes_written < size) { + ssize_t written = write(fd, (char*)buffer + bytes_written, size - bytes_written); + if(written == -1) { + if(errno != EINTR) + return -1; + } else { + bytes_written += written; + } + } + return bytes_written; +} + static ssize_t write_all_blocking(int fd, const void *buffer, size_t size) { ssize_t bytes_written = 0; while((size_t)bytes_written < size) { @@ -433,7 +447,7 @@ namespace QuickMedia { return Error::OK; } - const ssize_t num_bytes_written = write_all_blocking(client_fd, buffer_start + buffer_offset, num_bytes_to_write); + const ssize_t num_bytes_written = write_all(client_fd, buffer_start + buffer_offset, num_bytes_to_write); if(num_bytes_written == -1) { const int err = errno; if(err == EAGAIN || err == EWOULDBLOCK) { |