quark

quark web server
git clone git://git.suckless.org/quark
Log | Files | Refs | LICENSE

commit a1fa707eec08a573392d6921a527b52b4e2c53d0
parent a0a2b864a69acca492e8e78ff2c246d37ed42346
Author: FRIGN <dev@frign.de>
Date:   Thu, 14 Aug 2014 09:47:23 +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.

Diffstat:
Mquark.c | 9+++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/quark.c b/quark.c @@ -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\n", - 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\n", host, strerror(errno)); if (n == -1) logerrmsg("error reading from file: %s\n", strerror(errno)); }