- use TCP_DEFER_ACCEPT

- don't timeout connections which are managed by IRCG
- don't generate invalid HTTP replies, if the client did not send a
  request line yet
This commit is contained in:
Sascha Schumann 2002-11-06 17:31:03 +00:00
parent 5c7b062d6f
commit 10a861f93c

View File

@ -1,6 +1,6 @@
diff -ur thttpd-2.21b/Makefile.in thttpd-2.21b-cool/Makefile.in
--- thttpd-2.21b/Makefile.in Thu Mar 29 20:36:21 2001
+++ thttpd-2.21b-cool/Makefile.in Fri Nov 1 12:43:16 2002
+++ thttpd-2.21b-cool/Makefile.in Fri Nov 1 13:15:14 2002
@@ -46,13 +46,15 @@
# You shouldn't need to edit anything below here.
@ -49,7 +49,7 @@ diff -ur thttpd-2.21b/Makefile.in thttpd-2.21b-cool/Makefile.in
@name=`sed -n -e '/SERVER_SOFTWARE/!d' -e 's,.*thttpd/,thttpd-,' -e 's, .*,,p' version.h` ; \
diff -ur thttpd-2.21b/config.h thttpd-2.21b-cool/config.h
--- thttpd-2.21b/config.h Mon Apr 9 23:57:36 2001
+++ thttpd-2.21b-cool/config.h Fri Nov 1 12:43:16 2002
+++ thttpd-2.21b-cool/config.h Fri Nov 1 13:15:14 2002
@@ -82,6 +82,11 @@
*/
#define IDLE_READ_TIMELIMIT 60
@ -71,9 +71,33 @@ diff -ur thttpd-2.21b/config.h thttpd-2.21b-cool/config.h
/* CONFIGURE: If this is defined then thttpd will automatically generate
** index pages for directories that don't have an explicit index file.
diff -ur thttpd-2.21b/configure thttpd-2.21b-cool/configure
--- thttpd-2.21b/configure Sat Apr 21 02:07:14 2001
+++ thttpd-2.21b-cool/configure Wed Nov 6 18:28:05 2002
@@ -1021,7 +1021,7 @@
fi
echo "$ac_t""$CPP" 1>&6
-for ac_hdr in fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h
+for ac_hdr in fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h netinet/tcp.h
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
diff -ur thttpd-2.21b/configure.in thttpd-2.21b-cool/configure.in
--- thttpd-2.21b/configure.in Sat Apr 21 02:06:23 2001
+++ thttpd-2.21b-cool/configure.in Wed Nov 6 18:25:00 2002
@@ -64,7 +64,7 @@
AC_MSG_RESULT(no)
fi
-AC_CHECK_HEADERS(fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h)
+AC_CHECK_HEADERS(fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h netinet/tcp.h)
AC_HEADER_TIME
AC_HEADER_DIRENT
diff -ur thttpd-2.21b/fdwatch.c thttpd-2.21b-cool/fdwatch.c
--- thttpd-2.21b/fdwatch.c Fri Apr 13 07:36:08 2001
+++ thttpd-2.21b-cool/fdwatch.c Fri Nov 1 12:43:16 2002
+++ thttpd-2.21b-cool/fdwatch.c Wed Nov 6 18:20:53 2002
@@ -460,7 +460,7 @@
ridx = 0;
@ -96,8 +120,19 @@ diff -ur thttpd-2.21b/fdwatch.c thttpd-2.21b-cool/fdwatch.c
}
diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
--- thttpd-2.21b/libhttpd.c Tue Apr 24 00:42:40 2001
+++ thttpd-2.21b-cool/libhttpd.c Fri Nov 1 12:43:44 2002
@@ -85,6 +85,12 @@
+++ thttpd-2.21b-cool/libhttpd.c Wed Nov 6 18:29:07 2002
@@ -56,6 +56,10 @@
#include <unistd.h>
#include <stdarg.h>
+#ifdef HAVE_NETINET_TCP_H
+#include <netinet/tcp.h>
+#endif
+
#ifdef HAVE_OSRELDATE_H
#include <osreldate.h>
#endif /* HAVE_OSRELDATE_H */
@@ -85,6 +89,12 @@
#include "match.h"
#include "tdate_parse.h"
@ -110,7 +145,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
#ifndef STDIN_FILENO
#define STDIN_FILENO 0
#endif
@@ -242,6 +248,10 @@
@@ -242,6 +252,10 @@
free( (void*) hs->cwd );
if ( hs->cgi_pattern != (char*) 0 )
free( (void*) hs->cgi_pattern );
@ -121,7 +156,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
if ( hs->charset != (char*) 0 )
free( (void*) hs->charset );
if ( hs->url_pattern != (char*) 0 )
@@ -249,6 +259,7 @@
@@ -249,6 +263,7 @@
if ( hs->local_pattern != (char*) 0 )
free( (void*) hs->local_pattern );
free( (void*) hs );
@ -129,7 +164,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
}
@@ -257,7 +268,8 @@
@@ -257,7 +272,8 @@
char* hostname, httpd_sockaddr* sa4P, httpd_sockaddr* sa6P, int port,
char* cgi_pattern, char* charset, char* cwd, int no_log, FILE* logfp,
int no_symlink, int vhost, int global_passwd, char* url_pattern,
@ -139,7 +174,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
{
httpd_server* hs;
static char ghnbuf[256];
@@ -312,6 +324,8 @@
@@ -312,6 +328,8 @@
}
hs->port = port;
@ -148,7 +183,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
if ( cgi_pattern == (char*) 0 )
hs->cgi_pattern = (char*) 0;
else
@@ -329,7 +343,7 @@
@@ -329,7 +347,7 @@
while ( ( cp = strstr( hs->cgi_pattern, "|/" ) ) != (char*) 0 )
(void) strcpy( cp + 1, cp + 2 );
}
@ -157,7 +192,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
hs->cwd = strdup( cwd );
if ( hs->cwd == (char*) 0 )
{
@@ -385,6 +399,8 @@
@@ -385,6 +403,8 @@
return (httpd_server*) 0;
}
@ -166,7 +201,19 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
/* Done initializing. */
if ( hs->binding_hostname == (char*) 0 )
syslog( LOG_INFO, "%.80s starting on port %d", SERVER_SOFTWARE, hs->port );
@@ -582,6 +598,9 @@
@@ -418,6 +438,11 @@
}
(void) fcntl( listen_fd, F_SETFD, 1 );
+#if defined(TCP_DEFER_ACCEPT) && defined(SOL_TCP)
+ on = 30; /* give clients 30s to send first data packet */
+ setsockopt(listen_fd, SOL_TCP, TCP_DEFER_ACCEPT, &on, sizeof(on));
+#endif
+
/* Allow reuse of local addresses. */
on = 1;
if ( setsockopt(
@@ -582,6 +607,9 @@
/* And send it, if necessary. */
if ( hc->responselen > 0 )
{
@ -176,19 +223,20 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
(void) write( hc->conn_fd, hc->response, hc->responselen );
hc->responselen = 0;
}
@@ -657,9 +676,9 @@
@@ -657,9 +685,9 @@
(void) my_snprintf(
fixed_type, sizeof(fixed_type), type, hc->hs->charset );
(void) my_snprintf( buf, sizeof(buf),
- "%.20s %d %s\r\nServer: %s\r\nContent-Type: %s\r\nDate: %s\r\nLast-Modified: %s\r\nAccept-Ranges: bytes\r\nConnection: close\r\n",
+ "%.20s %d %s\r\nServer: %s\r\nContent-Type: %s\r\nDate: %s\r\nLast-Modified: %s\r\nAccept-Ranges: bytes\r\n",
hc->protocol, status, title, EXPOSED_SERVER_SOFTWARE, fixed_type,
- hc->protocol, status, title, EXPOSED_SERVER_SOFTWARE, fixed_type,
- nowbuf, modbuf );
+ "HTTP/1.1 %d %s\r\nServer: %s\r\nContent-Type: %s\r\nDate: %s\r\nLast-Modified: %s\r\nAccept-Ranges: bytes\r\n",
+ status, title, EXPOSED_SERVER_SOFTWARE, fixed_type,
+ nowbuf, modbuf);
add_response( hc, buf );
if ( encodings[0] != '\0' )
{
@@ -681,6 +700,14 @@
@@ -681,6 +709,14 @@
"Content-Length: %d\r\n", length );
add_response( hc, buf );
}
@ -203,7 +251,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
if ( extraheads[0] != '\0' )
add_response( hc, extraheads );
add_response( hc, "\r\n" );
@@ -1603,6 +1630,63 @@
@@ -1603,6 +1639,63 @@
int
@ -267,7 +315,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
httpd_get_conn( httpd_server* hs, int listen_fd, httpd_conn* hc )
{
httpd_sockaddr sa;
@@ -1657,53 +1741,12 @@
@@ -1657,53 +1750,12 @@
hc->hs = hs;
memset( &hc->client_addr, 0, sizeof(hc->client_addr) );
memcpy( &hc->client_addr, &sa, sockaddr_len( &sa ) );
@ -327,7 +375,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
}
@@ -1720,6 +1763,9 @@
@@ -1720,6 +1772,9 @@
{
char c;
@ -337,7 +385,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
for ( ; hc->checked_idx < hc->read_idx; ++hc->checked_idx )
{
c = hc->read_buf[hc->checked_idx];
@@ -1912,8 +1958,11 @@
@@ -1912,8 +1967,11 @@
eol = strpbrk( protocol, " \t\n\r" );
if ( eol != (char*) 0 )
*eol = '\0';
@ -350,7 +398,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
}
}
/* Check for HTTP/1.1 absolute URL. */
@@ -2012,6 +2061,11 @@
@@ -2012,6 +2070,11 @@
cp = strchr( hc->hdrhost, ':' );
if ( cp != (char*) 0 )
*cp = '\0';
@ -362,7 +410,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
}
else if ( strncasecmp( buf, "Accept:", 7 ) == 0 )
{
@@ -2129,6 +2183,7 @@
@@ -2129,6 +2192,7 @@
cp = &buf[11];
cp += strspn( cp, " \t" );
if ( strcasecmp( cp, "keep-alive" ) == 0 )
@ -370,7 +418,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
hc->keep_alive = 1;
}
#ifdef LOG_UNKNOWN_HEADERS
@@ -2168,6 +2223,9 @@
@@ -2168,6 +2232,9 @@
}
}
@ -380,7 +428,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
if ( hc->one_one )
{
/* Check that HTTP/1.1 requests specify a host, as required. */
@@ -2177,14 +2235,14 @@
@@ -2177,14 +2244,14 @@
return -1;
}
@ -402,7 +450,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
}
/* Ok, the request has been parsed. Now we resolve stuff that
@@ -2349,15 +2407,24 @@
@@ -2349,15 +2416,24 @@
void
@ -431,7 +479,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
if ( hc->conn_fd >= 0 )
{
(void) close( hc->conn_fd );
@@ -3026,11 +3093,9 @@
@@ -3026,11 +3102,9 @@
post_post_garbage_hack( httpd_conn* hc )
{
char buf[2];
@ -445,7 +493,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
}
@@ -3313,6 +3378,11 @@
@@ -3313,6 +3387,11 @@
int r;
ClientData client_data;
@ -457,7 +505,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
if ( hc->method == METHOD_GET || hc->method == METHOD_POST )
{
httpd_clear_ndelay( hc->conn_fd );
@@ -3369,6 +3439,7 @@
@@ -3369,6 +3448,7 @@
int expnlen, indxlen;
char* cp;
char* pi;
@ -465,7 +513,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
expnlen = strlen( hc->expnfilename );
@@ -3561,6 +3632,16 @@
@@ -3561,6 +3641,16 @@
match( hc->hs->cgi_pattern, hc->expnfilename ) )
return cgi( hc );
@ -482,7 +530,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
/* It's not CGI. If it's executable or there's pathinfo, someone's
** trying to either serve or run a non-CGI file as CGI. Either case
** is prohibited.
@@ -3594,6 +3675,8 @@
@@ -3594,6 +3684,8 @@
hc->end_byte_loc = hc->sb.st_size - 1;
figure_mime( hc );
@ -491,7 +539,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
if ( hc->method == METHOD_HEAD )
{
@@ -3601,7 +3684,7 @@
@@ -3601,7 +3693,7 @@
hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size,
hc->sb.st_mtime );
}
@ -500,7 +548,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
hc->if_modified_since >= hc->sb.st_mtime )
{
hc->method = METHOD_HEAD;
@@ -3611,14 +3694,25 @@
@@ -3611,14 +3703,25 @@
}
else
{
@ -530,7 +578,7 @@ diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c
diff -ur thttpd-2.21b/libhttpd.h thttpd-2.21b-cool/libhttpd.h
--- thttpd-2.21b/libhttpd.h Tue Apr 24 00:36:50 2001
+++ thttpd-2.21b-cool/libhttpd.h Fri Nov 1 12:43:16 2002
+++ thttpd-2.21b-cool/libhttpd.h Fri Nov 1 13:15:14 2002
@@ -69,6 +69,8 @@
char* server_hostname;
int port;
@ -576,7 +624,7 @@ diff -ur thttpd-2.21b/libhttpd.h thttpd-2.21b-cool/libhttpd.h
** mallocced strings.
diff -ur thttpd-2.21b/mime_encodings.txt thttpd-2.21b-cool/mime_encodings.txt
--- thttpd-2.21b/mime_encodings.txt Wed May 10 03:22:28 2000
+++ thttpd-2.21b-cool/mime_encodings.txt Fri Nov 1 12:43:16 2002
+++ thttpd-2.21b-cool/mime_encodings.txt Fri Nov 1 13:15:14 2002
@@ -3,6 +3,6 @@
# A list of file extensions followed by the corresponding MIME encoding.
# Extensions not found in the table proceed to the mime_types table.
@ -588,7 +636,7 @@ diff -ur thttpd-2.21b/mime_encodings.txt thttpd-2.21b-cool/mime_encodings.txt
uu x-uuencode
diff -ur thttpd-2.21b/mime_types.txt thttpd-2.21b-cool/mime_types.txt
--- thttpd-2.21b/mime_types.txt Sat Apr 14 04:53:30 2001
+++ thttpd-2.21b-cool/mime_types.txt Fri Nov 1 12:43:16 2002
+++ thttpd-2.21b-cool/mime_types.txt Fri Nov 1 13:15:14 2002
@@ -1,135 +1,138 @@
-# mime_types.txt
-#
@ -839,7 +887,7 @@ diff -ur thttpd-2.21b/mime_types.txt thttpd-2.21b-cool/mime_types.txt
+ice x-conference/x-cooltalk
diff -ur thttpd-2.21b/mmc.c thttpd-2.21b-cool/mmc.c
--- thttpd-2.21b/mmc.c Fri Apr 13 23:02:15 2001
+++ thttpd-2.21b-cool/mmc.c Fri Nov 1 12:43:17 2002
+++ thttpd-2.21b-cool/mmc.c Fri Nov 1 13:15:14 2002
@@ -70,6 +70,7 @@
unsigned int hash;
int hash_idx;
@ -911,7 +959,7 @@ diff -ur thttpd-2.21b/mmc.c thttpd-2.21b-cool/mmc.c
else
diff -ur thttpd-2.21b/mmc.h thttpd-2.21b-cool/mmc.h
--- thttpd-2.21b/mmc.h Fri Apr 13 07:36:54 2001
+++ thttpd-2.21b-cool/mmc.h Fri Nov 1 12:43:17 2002
+++ thttpd-2.21b-cool/mmc.h Fri Nov 1 13:15:14 2002
@@ -31,8 +31,9 @@
/* Returns an mmap()ed area for the given file, or (void*) 0 on errors.
** If you have a stat buffer on the file, pass it in, otherwise pass 0.
@ -925,7 +973,7 @@ diff -ur thttpd-2.21b/mmc.h thttpd-2.21b-cool/mmc.h
** If you have a stat buffer on the file, pass it in, otherwise pass 0.
diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c
--- thttpd-2.21b/thttpd.c Tue Apr 24 00:41:57 2001
+++ thttpd-2.21b-cool/thttpd.c Fri Nov 1 12:48:04 2002
+++ thttpd-2.21b-cool/thttpd.c Wed Nov 6 18:20:53 2002
@@ -66,6 +66,8 @@
static char* dir;
static int do_chroot, no_log, no_symlink, do_vhost, do_global_passwd;
@ -1370,7 +1418,7 @@ diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c
/* Fill in bytes_to_send. */
if ( hc->got_range )
{
@@ -1384,37 +1494,24 @@
@@ -1384,37 +1494,25 @@
{
/* No file address means someone else is handling it. */
c->bytes_sent = hc->bytes_sent;
@ -1379,6 +1427,7 @@ diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c
return;
}
+ if (hc->file_address == (char *) 1) {
+ c->last_io = (time_t) LONG_MAX;
+ c->wouldblock_delay = 0;
+ return;
+ }
@ -1415,7 +1464,7 @@ diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c
static void
handle_send( connecttab* c, struct timeval* tvP )
{
@@ -1443,6 +1540,9 @@
@@ -1443,6 +1541,9 @@
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 );
@ -1425,7 +1474,7 @@ diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c
}
if ( sz == 0 ||
@@ -1486,12 +1586,12 @@
@@ -1486,12 +1587,12 @@
*/
if ( errno != EPIPE && errno != EINVAL && errno != ECONNRESET )
syslog( LOG_ERR, "write - %m sending %.80s", hc->encodedurl );
@ -1440,7 +1489,7 @@ diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c
/* Was this a headers + file writev()? */
if ( hc->responselen > 0 )
{
@@ -1500,7 +1600,7 @@
@@ -1500,7 +1601,7 @@
{
/* Yes; move the unwritten part to the front of the buffer. */
int newlen = hc->responselen - sz;
@ -1449,7 +1498,7 @@ diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c
hc->responselen = newlen;
sz = 0;
}
@@ -1519,7 +1619,7 @@
@@ -1519,7 +1620,7 @@
if ( c->bytes_sent >= c->bytes_to_send )
{
/* This conection is finished! */
@ -1458,7 +1507,7 @@ diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c
return;
}
@@ -1560,6 +1660,9 @@
@@ -1560,6 +1661,9 @@
char buf[1024];
int r;
@ -1468,7 +1517,7 @@ diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c
/* In lingering-close mode we just read and ignore bytes. An error
** or EOF ends things, otherwise we go until a timeout.
*/
@@ -1569,6 +1672,61 @@
@@ -1569,6 +1673,61 @@
}
@ -1530,7 +1579,7 @@ diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c
static int
check_throttles( connecttab* c )
{
@@ -1635,23 +1793,18 @@
@@ -1635,23 +1794,18 @@
static void
@ -1560,7 +1609,7 @@ diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c
if ( c->wakeup_timer != (Timer*) 0 )
{
tmr_cancel( c->wakeup_timer );
@@ -1669,13 +1822,36 @@
@@ -1669,13 +1823,36 @@
** circumstances that make a lingering close necessary. If the flag
** isn't set we do the real close now.
*/
@ -1599,7 +1648,7 @@ diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c
client_data.p = c;
c->linger_timer = tmr_create(
tvP, linger_clear_connection, client_data, LINGER_TIME * 1000L, 0 );
@@ -1684,9 +1860,19 @@
@@ -1684,9 +1861,19 @@
syslog( LOG_CRIT, "tmr_create(linger_clear_connection) failed" );
exit( 1 );
}
@ -1620,7 +1669,7 @@ diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c
}
@@ -1702,45 +1888,12 @@
@@ -1702,45 +1889,12 @@
tmr_cancel( c->linger_timer );
c->linger_timer = 0;
}
@ -1667,7 +1716,7 @@ diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c
static void
wakeup_connection( ClientData client_data, struct timeval* nowP )
@@ -1826,3 +1979,41 @@
@@ -1826,3 +1980,41 @@
stats_connections = stats_bytes = 0L;
stats_simultaneous = 0;
}