mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
send_from_file(): Use sendfile() on Linux.
This commit is contained in:
parent
8f4a5e6b60
commit
df4f6910de
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#ifdef __linux
|
#ifdef __linux
|
||||||
#define _GNU_SOURCE /* for strsignal() and vasprintf() */
|
#define _GNU_SOURCE /* for strsignal() and vasprintf() */
|
||||||
|
#include <sys/sendfile.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -1683,6 +1684,9 @@ static ssize_t send_from_file(int s, FILE *fp, long ofs, size_t size)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else return size;
|
else return size;
|
||||||
|
#else
|
||||||
|
#ifdef __linux
|
||||||
|
return sendfile(s, fileno(fp), &ofs, size);
|
||||||
#else
|
#else
|
||||||
#define BUFSIZE 20000
|
#define BUFSIZE 20000
|
||||||
char buf[BUFSIZE];
|
char buf[BUFSIZE];
|
||||||
@ -1693,6 +1697,7 @@ static ssize_t send_from_file(int s, FILE *fp, long ofs, size_t size)
|
|||||||
if (fread(buf, amount, 1, fp) != 1) return -2;
|
if (fread(buf, amount, 1, fp) != 1) return -2;
|
||||||
return send(s, buf, amount, 0);
|
return send(s, buf, amount, 0);
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user