Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 Apr 2002 16:18:03 -0700 (PDT)
From:      Nick Johnson <freebsd@spatula.net>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/37439: Alfred's Patches to thttpd port to use sendfile
Message-ID:  <20020424231803.904A1A923@turing.morons.org>

next in thread | raw e-mail | index | archive | help

>Number:         37439
>Category:       ports
>Synopsis:       Alfred's Patches to thttpd port to use sendfile
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 24 20:20:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Nick Johnson
>Release:        FreeBSD 4.5-RELEASE-p2 i386
>Organization:
Spatula Systems 
>Environment:
System: FreeBSD turing.morons.org 4.5-RELEASE-p2 FreeBSD 4.5-RELEASE-p2 #4: Wed Apr 10 10:27:18 PDT 2002 root@turing.morons.org:/usr/src/sys/compile/TURING i386


	
>Description:
Patches to add alfred@freebsd.org's thttpd patches to make it use 
sendfile, integrated into the port.  Maintainer or committer may
want to tweak the way the USE_SENDFILE macro gets defined. I couldn't
think of a better way than what I ended up doing, but then I didn't
give it much thought either.

	
>How-To-Repeat:
n/a
	
>Fix:

	

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	Makefile.patch
#	files/patch-ae
#	files/patch-af
#	files/patch-ag
#	files/patch-ah
#	files/patch-ai
#
echo x - Makefile.patch
sed 's/^X//' >Makefile.patch << 'END-of-Makefile.patch'
X--- Makefile.orig	Wed Apr 24 22:39:26 2002
X+++ Makefile	Wed Apr 24 22:36:18 2002
X@@ -15,6 +15,8 @@
X DIST_SUBDIR=	${PORTNAME}
X EXTRACT_ONLY=	${DISTNAME}${EXTRACT_SUFX}
X 
X+CFLAGS:=	${CFLAGS} -DUSE_SENDFILE=1
X+
X MAINTAINER=	anders@FreeBSD.org
X 
X IGNOREFILES=	notes.html
END-of-Makefile.patch
echo x - files/patch-ae
sed 's/^X//' >files/patch-ae << 'END-of-files/patch-ae'
X--- libhttpd.c.orig	Wed Nov 14 22:32:12 2001
X+++ libhttpd.c	Wed Apr 24 22:24:27 2002
X@@ -3692,6 +3692,9 @@
X 	    httpd_send_err( hc, 500, err500title, "", err500form, hc->encodedurl );
X 	    return -1;
X 	    }
X+#ifdef USE_SENDFILE
X+        hc->file_fd = *((int *) hc->file_address);
X+#endif
X 	send_mime(
X 	    hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size,
X 	    hc->sb.st_mtime );
END-of-files/patch-ae
echo x - files/patch-af
sed 's/^X//' >files/patch-af << 'END-of-files/patch-af'
X--- ./libhttpd.h	Tue Jun 13 11:48:56 2000
X+++ /usr/ports/www/thttpd/work/thttpd-2.20b/libhttpd.h	Fri Apr 20 03:50:30 2001
X@@ -133,6 +133,9 @@
X     struct stat sb;
X     int conn_fd;
X     char* file_address;
X+#ifdef USE_SENDFILE
X+    int file_fd;
X+#endif    
X     } httpd_conn;
X 
X /* Methods. */
END-of-files/patch-af
echo x - files/patch-ag
sed 's/^X//' >files/patch-ag << 'END-of-files/patch-ag'
X--- mmc.c.orig	Fri Apr 13 21:02:15 2001
X+++ mmc.c	Wed Apr 24 22:28:57 2002
X@@ -66,6 +66,9 @@
X     time_t ctime;
X     int refcount;
X     time_t reftime;
X+#ifdef USE_SENDFILE
X+    int fd;
X+#endif
X     void* addr;
X     unsigned int hash;
X     int hash_idx;
X@@ -130,7 +133,11 @@
X 	/* Yep.  Just return the existing map */
X 	++m->refcount;
X 	m->reftime = now;
X+#ifdef USE_SENDFILE
X+        return(&m->fd);
X+#else
X 	return m->addr;
X+#endif
X 	}
X 
X     /* Open the file. */
X@@ -175,7 +182,9 @@
X 	m->addr = (void*) 1;	/* arbitrary non-NULL address */
X     else
X 	{
X-#ifdef HAVE_MMAP
X+#ifdef USE_SENDFILE
X+	m->fd = fd;
X+#elif defined(HAVE_MMAP)
X 	/* Map the file into memory. */
X 	m->addr = mmap( 0, m->size, PROT_READ, MAP_SHARED, fd, 0 );
X 	if ( m->addr == (void*) -1 )
X@@ -207,8 +216,9 @@
X 	    }
X #endif /* HAVE_MMAP */
X 	}
X+#ifndef USE_SENDFILE
X     (void) close( fd );
X-
X+#endif /* !USE_SENDFILE */
X     /* Put the Map into the hash table. */
X     if ( add_hash( m ) < 0 )
X 	{
X@@ -223,8 +233,12 @@
X     maps = m;
X     ++map_count;
X 
X+#ifdef USE_SENDFILE
X+    return (&m->fd);
X+#else
X     /* And return the address. */
X     return m->addr;
X+#endif
X     }
X 
X 
X@@ -309,7 +323,9 @@
X     m = *mm;
X     if ( m->size != 0 )
X 	{
X-#ifdef HAVE_MMAP
X+#ifdef USE_SENDFILE
X+	close(m->fd);	    
X+#elif defined(HAVE_MMAP)
X 	if ( munmap( m->addr, m->size ) < 0 )
X 	    syslog( LOG_ERR, "munmap - %m" );
X #else /* HAVE_MMAP */
END-of-files/patch-ag
echo x - files/patch-ah
sed 's/^X//' >files/patch-ah << 'END-of-files/patch-ah'
X--- ./thttpd.c	Wed Sep 27 12:31:48 2000
X+++ /usr/ports/www/thttpd/work/thttpd-2.20b/thttpd.c	Fri Apr 20 03:50:30 2001
X@@ -1366,12 +1366,45 @@
X     if ( hc->responselen == 0 )
X 	{
X 	/* No, just write the file. */
X+#ifdef USE_SENDFILE
X+	off_t sbytes;
X+	
X+	sz = sendfile(
X+	     hc->file_fd, hc->conn_fd, c->bytes_sent,
X+	     MIN( c->bytes_to_send - c->bytes_sent, c->limit ),
X+	     NULL, &sbytes, 0 );
X+	if (sz == -1 && errno == EAGAIN)
X+	    sz = sbytes > 0 ? sbytes : -1;
X+	else if (sz == 0)
X+	    sz = sbytes;
X+#else		      
X 	sz = write(
X 	    hc->conn_fd, &(hc->file_address[c->bytes_sent]),
X 	    MIN( c->bytes_to_send - c->bytes_sent, c->limit ) );
X+#endif
X 	}
X     else
X 	{
X+#ifdef USE_SENDFILE
X+	struct sf_hdtr sf;
X+	struct iovec iv;
X+	off_t sbytes;
X+
X+	iv.iov_base = hc->response;
X+	iv.iov_len = hc->responselen;
X+	sf.headers = &iv;
X+	sf.hdr_cnt = 1;
X+	sf.trailers = NULL;
X+	sf.trl_cnt = 0;
X+	sz = sendfile(
X+	     hc->file_fd, hc->conn_fd, c->bytes_sent,
X+	     MIN( c->bytes_to_send - c->bytes_sent, c->limit ),
X+	     &sf, &sbytes, 0 );
X+	if (sz == -1 && errno == EAGAIN)
X+	    sz = sbytes > 0 ? sbytes : -1;
X+	else if (sz == 0)
X+	    sz = sbytes;
X+#else		      
X 	/* Yes.  We'll combine headers and file into a single writev(),
X 	** hoping that this generates a single packet.
X 	*/
X@@ -1382,6 +1415,7 @@
X 	iv[1].iov_base = &(hc->file_address[c->bytes_sent]);
X 	iv[1].iov_len = MIN( c->bytes_to_send - c->bytes_sent, c->limit );
X 	sz = writev( hc->conn_fd, iv, 2 );
X+#endif
X 	}
X 
X     if ( sz == 0 ||
END-of-files/patch-ah
echo x - files/patch-ai
sed 's/^X//' >files/patch-ai << 'END-of-files/patch-ai'
X--- version.h.orig	Wed Nov 14 20:27:41 2001
X+++ version.h	Wed Apr 24 22:33:23 2002
X@@ -3,7 +3,14 @@
X #ifndef _VERSION_H_
X #define _VERSION_H_
X 
X-#define SERVER_SOFTWARE "thttpd/2.22beta4 14nov2001"
X+#define SERVER_SOFTWARE_BASE "thttpd/2.22beta4 14nov2001"
X+
X+#ifdef USE_SENDFILE
X+#define SERVER_SOFTWARE SERVER_SOFTWARE_BASE " (+FreeBSD sendfile)"
X+#else /* USE_SENDFILE */
X+#define SERVER_SOFTWARE SERVER_SOFTWARE_BASE
X+#endif
X+
X #define SERVER_ADDRESS "http://www.acme.com/software/thttpd/"
X 
X #endif /* _VERSION_H_ */
END-of-files/patch-ai
exit


>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020424231803.904A1A923>