applied cls' follow up fix

This commit is contained in:
garbeam@gmail.com 2011-06-26 10:57:34 +01:00
parent 3a9701d828
commit 22b5b3cfa6

25
quark.c
View file

@ -2,24 +2,24 @@
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pwd.h>
#include <grp.h> #include <grp.h>
#include <netdb.h>
#include <pwd.h>
#include <signal.h> #include <signal.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/sendfile.h> #include <time.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#define LENGTH(x) (sizeof x / sizeof x[0]) #define LENGTH(x) (sizeof x / sizeof x[0])
#define MAXBUFLEN 1024 #define MAXBUFLEN 1024
#define MIN(x,y) ((x) < (y) ? (x) : (y))
enum { enum {
GET = 4, GET = 4,
@ -202,13 +202,14 @@ responsecontenttype(const char *mimetype) {
void void
responsefiledata(int fd, off_t size) { responsefiledata(int fd, off_t size) {
off_t offset = 0; char buf[BUFSIZ];
size_t n;
while(offset < size) for(; (n = read(fd, buf, MIN(size, sizeof buf))) > 0; size -= n)
if(sendfile(req.fd, fd, &offset, size - offset) == -1) { if(write(req.fd, buf, n) != n)
logerrmsg("sendfile failed on client %s: %s\n", host, strerror(errno)); logerrmsg("error writing to client %s: %s\n", host, strerror(errno));
return; if(n == -1)
} logerrmsg("error reading from file: %s\n", strerror(errno));
} }
void void