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.
This commit is contained in:
FRIGN 2014-08-14 09:47:23 +02:00
parent a0a2b864a6
commit a1fa707eec

View file

@ -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));
}