aboutsummaryrefslogtreecommitdiffstats
path: root/www
diff options
context:
space:
mode:
authoranders <anders@FreeBSD.org>2002-10-21 08:29:02 +0800
committeranders <anders@FreeBSD.org>2002-10-21 08:29:02 +0800
commit4caab5f8ae09c2bd749190e828634fcd0464d07e (patch)
tree79291149f56b01b2f740938b02a5687c16c583e1 /www
parent13dd3683494f042f203b2e67958dbf75d8c161cf (diff)
downloadfreebsd-ports-gnome-4caab5f8ae09c2bd749190e828634fcd0464d07e.tar.gz
freebsd-ports-gnome-4caab5f8ae09c2bd749190e828634fcd0464d07e.tar.zst
freebsd-ports-gnome-4caab5f8ae09c2bd749190e828634fcd0464d07e.zip
Add Alfred Perlstein's sendfile patches, as an optional knob.
Diffstat (limited to 'www')
-rw-r--r--www/thttpd/files/patch-libhttpd.c12
-rw-r--r--www/thttpd/files/patch-libhttpd.h12
-rw-r--r--www/thttpd/files/patch-mmc.c70
-rw-r--r--www/thttpd/files/patch-thttpd.c56
4 files changed, 150 insertions, 0 deletions
diff --git a/www/thttpd/files/patch-libhttpd.c b/www/thttpd/files/patch-libhttpd.c
new file mode 100644
index 000000000000..01e005440684
--- /dev/null
+++ b/www/thttpd/files/patch-libhttpd.c
@@ -0,0 +1,12 @@
+--- libhttpd.c.orig Mon May 27 01:22:26 2002
++++ libhttpd.c Sun Oct 20 23:49:58 2002
+@@ -3816,6 +3816,9 @@
+ httpd_send_err( hc, 500, err500title, "", err500form, hc->encodedurl );
+ return -1;
+ }
++#ifdef USE_SENDFILE
++ hc->file_fd = *((int *) hc->file_address);
++#endif
+ send_mime(
+ hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size,
+ hc->sb.st_mtime );
diff --git a/www/thttpd/files/patch-libhttpd.h b/www/thttpd/files/patch-libhttpd.h
new file mode 100644
index 000000000000..329fd6ae436b
--- /dev/null
+++ b/www/thttpd/files/patch-libhttpd.h
@@ -0,0 +1,12 @@
+--- libhttpd.h.orig Sun Oct 20 23:50:43 2002
++++ libhttpd.h Sun Oct 20 23:51:10 2002
+@@ -141,6 +141,9 @@
+ struct stat sb;
+ int conn_fd;
+ char* file_address;
++#ifdef USE_SENDFILE
++ int file_fd;
++#endif
+ } httpd_conn;
+
+ /* Methods. */
diff --git a/www/thttpd/files/patch-mmc.c b/www/thttpd/files/patch-mmc.c
new file mode 100644
index 000000000000..bf2c9f6ed641
--- /dev/null
+++ b/www/thttpd/files/patch-mmc.c
@@ -0,0 +1,70 @@
+--- mmc.c.orig Wed May 8 03:35:05 2002
++++ mmc.c Sun Oct 20 23:56:15 2002
+@@ -74,6 +74,9 @@
+ time_t ctime;
+ int refcount;
+ time_t reftime;
++#ifdef USE_SENDFILE
++ int fd;
++#endif
+ void* addr;
+ unsigned int hash;
+ int hash_idx;
+@@ -140,7 +143,11 @@
+ /* Yep. Just return the existing map */
+ ++m->refcount;
+ m->reftime = now;
++#ifdef USE_SENDFILE
++ return (&m->fd);
++#else
+ return m->addr;
++#endif
+ }
+
+ /* Open the file. */
+@@ -186,7 +193,9 @@
+ else
+ {
+ size_t size_size = (size_t) m->size; /* loses on files >2GB */
+-#ifdef HAVE_MMAP
++#ifdef USE_SENDFILE
++ m->fd = fd;
++#elif defined(HAVE_MMAP)
+ /* Map the file into memory. */
+ m->addr = mmap( 0, size_size, PROT_READ, MAP_PRIVATE, fd, 0 );
+ if ( m->addr == (void*) -1 && errno == ENOMEM )
+@@ -240,8 +249,9 @@
+ }
+ #endif /* HAVE_MMAP */
+ }
++#ifndef USE_SENDFILE
+ (void) close( fd );
+-
++#endif /* !USE_SENDFILE */
+ /* Put the Map into the hash table. */
+ if ( add_hash( m ) < 0 )
+ {
+@@ -259,8 +269,12 @@
+ /* Update the total byte count. */
+ mapped_bytes += m->size;
+
++#ifdef USE_SENDFILE
++ return (&m->fd);
++#else
+ /* And return the address. */
+ return m->addr;
++#endif
+ }
+
+
+@@ -369,7 +383,9 @@
+ m = *mm;
+ if ( m->size != 0 )
+ {
+-#ifdef HAVE_MMAP
++#ifdef USE_SENDFILE
++ close(m->fd);
++#elif defined(HAVE_MMAP)
+ if ( munmap( m->addr, m->size ) < 0 )
+ syslog( LOG_ERR, "munmap - %m" );
+ #else /* HAVE_MMAP */
diff --git a/www/thttpd/files/patch-thttpd.c b/www/thttpd/files/patch-thttpd.c
new file mode 100644
index 000000000000..c538dce4b73a
--- /dev/null
+++ b/www/thttpd/files/patch-thttpd.c
@@ -0,0 +1,56 @@
+--- thttpd.c.orig Sat May 25 19:43:13 2002
++++ thttpd.c Sun Oct 20 23:58:44 2002
+@@ -1500,12 +1500,45 @@
+ if ( hc->responselen == 0 )
+ {
+ /* No, just write the file. */
++#ifdef USE_SENDFILE
++ off_t sbytes;
++
++ sz = sendfile(
++ hc->file_fd, hc->conn_fd, c->bytes_sent,
++ MIN( c->bytes_to_send - c->bytes_sent, c->limit ),
++ NULL, &sbytes, 0 );
++ if (sz == -1 && errno == EAGAIN)
++ sz = sbytes > 0 ? sbytes : -1;
++ else if (sz == 0)
++ sz = sbytes;
++#else
+ sz = write(
+ hc->conn_fd, &(hc->file_address[c->bytes_sent]),
+ MIN( c->bytes_to_send - c->bytes_sent, c->limit ) );
++#endif
+ }
+ else
+ {
++#ifdef USE_SENDFILE
++ struct sf_hdtr sf;
++ struct iovec iv;
++ off_t sbytes;
++
++ iv.iov_base = hc->response;
++ iv.iov_len = hc->responselen;
++ sf.headers = &iv;
++ sf.hdr_cnt = 1;
++ sf.trailers = NULL;
++ sf.trl_cnt = 0;
++ sz = sendfile(
++ hc->file_fd, hc->conn_fd, c->bytes_sent,
++ MIN( c->bytes_to_send - c->bytes_sent, c->limit ),
++ &sf, &sbytes, 0 );
++ if (sz == -1 && errno == EAGAIN)
++ sz = sbytes > 0 ? sbytes : -1;
++ else if (sz == 0)
++ sz = sbytes;
++#else
+ /* Yes. We'll combine headers and file into a single writev(),
+ ** hoping that this generates a single packet.
+ */
+@@ -1516,6 +1549,7 @@
+ iv[1].iov_base = &(hc->file_address[c->bytes_sent]);
+ iv[1].iov_len = MIN( c->bytes_to_send - c->bytes_sent, c->limit );
+ sz = writev( hc->conn_fd, iv, 2 );
++#endif
+ }
+
+ if ( sz == 0 ||