On Friday 10 August 2007 20:41, Pierre Métras wrote:
> Hi,
>
> Here is a small patch to enable the use of the linux kernel function
> sendfile() in the httpd server (the last remaining TODO in
> network/httpd.c). This is enabled by a configuration option, disabled by
> default.
It's not totally flawless but not that bad either.
f = open(url, O_RDONLY);
if (f >= 0) {
+ sendHeaders(HTTP_OK);
+ int fd = accepted_socket;
You mix up statements and declarations. Busybox build system issues warnings.
+ if (fd == 0) fd++; /* write to fd #1 in inetd mode */
+#if ENABLE_FEATURE_HTTPD_USE_SENDFILE
+ struct stat f_stat;
+ if (fstat(f, &f_stat)) {
+ bb_perror_msg("cannot stat file '%s'", url);
+ }
+ off_t offset = 0;
+ sendfile(fd, f, &offset, f_stat.st_size);
What will happen if f_stat.st_size > INT_MAX (2 gb) ?
+#else
int count;
char *buf = iobuf;
-
- sendHeaders(HTTP_OK);
- /* TODO: sendfile() */
while ((count = full_read(f, buf, MAX_MEMORY_BUFF)) > 0) {
- int fd = accepted_socket;
- if (fd == 0) fd++; /* write to fd# 1 in inetd mode */
if (full_write(fd, buf, count) != count)
break;
}
+#endif
close(f);
I applied it with some changes, please test current svn.
Thanks!
--
vda
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox