[hackers] [quark] Fix streaming errors || FRIGN

From: <git_AT_suckless.org>
Date: Thu, 14 Aug 2014 09:48:32 +0200

commit a1fa707eec08a573392d6921a527b52b4e2c53d0
Author: FRIGN <dev_AT_frign.de>
Date: Thu Aug 14 09:47:23 2014 +0200

    Fix streaming errors
    
    Streaming a file (through mplayer for instance), the socket would
    block, because mplayer fills its buffer sequentially.
    We would've never gotten to a write(.., n) == n.
    
    Instead, do it like we read from files and accept the fact clients
    can accept data chunk-wise, too.
    
    The reason why this error went unnoticed is that I added a faulty
    printf-directive (%ls for ssize_t), which silently produced
    no output.
    Thanks to sin for fixing the %ls -> %zd error, as it made me look
    at the code again.

diff --git a/quark.c b/quark.c
index 831564b..43e976b 100644
--- a/quark.c
+++ b/quark.c
_AT_@ -184,12 +184,13 @@ putresentry(int type, ...) {
 void
 responsefiledata(int fd, off_t size) {
         char buf[BUFSIZ];
- ssize_t n;
+ ssize_t n, m, size_in;
 
         for (; (n = read(fd, buf, MIN(size, sizeof buf))) > 0; size -= n)
- if (write(req.fd, buf, n) != n)
- logerrmsg("error writing to client %s at %ls: %s
",
- host, n, strerror(errno));
+ for(size_in = n; (m = write(req.fd, buf, size_in)) > 0; size_in -= m);
+
+ if (m == -1)
+ logerrmsg("error writing to client %s: %s
", host, strerror(errno));
         if (n == -1)
                 logerrmsg("error reading from file: %s
", strerror(errno));
 }
Received on Thu Aug 14 2014 - 09:48:32 CEST

This archive was generated by hypermail 2.3.0 : Thu Aug 14 2014 - 10:00:12 CEST