sas             Wed Oct 30 14:09:50 2002 EDT

  Modified files:              
    /php4/sapi/thttpd   thttpd.c thttpd_patch 
  Log:
  first step towards asynchronous content body processing
  
  
Index: php4/sapi/thttpd/thttpd.c
diff -u php4/sapi/thttpd/thttpd.c:1.74 php4/sapi/thttpd/thttpd.c:1.75
--- php4/sapi/thttpd/thttpd.c:1.74      Sat Oct 26 17:06:10 2002
+++ php4/sapi/thttpd/thttpd.c   Wed Oct 30 14:09:49 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: thttpd.c,v 1.74 2002/10/26 21:06:10 sas Exp $ */
+/* $Id: thttpd.c,v 1.75 2002/10/30 19:09:49 sas Exp $ */
 
 #include "php.h"
 #include "SAPI.h"
@@ -212,18 +212,22 @@
        return SAPI_HEADER_SENT_SUCCESSFULLY;
 }
 
+/* to understand this, read cgi_interpose_input() in libhttpd.c */
+#define SIZEOF_UNCONSUMED_BYTES() (TG(hc)->read_idx - TG(hc)->checked_idx)
+#define CONSUME_BYTES(n) do { TG(hc)->checked_idx += (n); } while (0)
+
+
 static int sapi_thttpd_read_post(char *buffer, uint count_bytes TSRMLS_DC)
 {
        size_t read_bytes = 0, tmp;
        int c;
        int n;
 
-       /* to understand this, read cgi_interpose_input() in libhttpd.c */
-       c = TG(hc)->read_idx - TG(hc)->checked_idx;
+       c = SIZEOF_UNCONSUMED_BYTES();
        if (c > 0) {
                read_bytes = MIN(c, count_bytes);
                memcpy(buffer, TG(hc)->read_buf + TG(hc)->checked_idx, read_bytes);
-               TG(hc)->checked_idx += read_bytes;
+               CONSUME_BYTES(read_bytes);
                count_bytes -= read_bytes;
        }
        
@@ -644,6 +648,8 @@
 
 #endif
 
+#define CT_LEN_MAX_RAM 8192
+
 static off_t thttpd_real_php_request(httpd_conn *hc, int show_source TSRMLS_DC)
 {
        TG(hc) = hc;
@@ -652,6 +658,18 @@
        TG(read_post_data) = 0;
        if (hc->method == METHOD_POST)
                hc->should_linger = 1;
+       
+       if (hc->contentlength > 0 
+                       && SIZEOF_UNCONSUMED_BYTES() < hc->contentlength) {
+               int missing = hc->contentlength - SIZEOF_UNCONSUMED_BYTES();
+               
+               if (hc->contentlength < CT_LEN_MAX_RAM) {
+                       hc->read_body_into_mem = 1;
+                       return 0;
+               } else {
+                       return -1;
+               }
+       }
        
        thttpd_request_ctor(TSRMLS_C);
 
Index: php4/sapi/thttpd/thttpd_patch
diff -u php4/sapi/thttpd/thttpd_patch:1.25 php4/sapi/thttpd/thttpd_patch:1.26
--- php4/sapi/thttpd/thttpd_patch:1.25  Sat Oct 26 18:22:34 2002
+++ php4/sapi/thttpd/thttpd_patch       Wed Oct 30 14:09:49 2002
@@ -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      Sat Oct 26 23:50:26 2002
++++ thttpd-2.21b-cool/Makefile.in      Wed Oct 30 13:15:49 2002
 @@ -46,13 +46,15 @@
  
  # You shouldn't need to edit anything below here.
@@ -49,7 +49,7 @@
        @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 Sat Oct 26 22:58:06 2002
++++ thttpd-2.21b-cool/config.h Wed Oct 30 13:15:49 2002
 @@ -82,6 +82,11 @@
  */
  #define IDLE_READ_TIMELIMIT 60
@@ -73,7 +73,7 @@
  ** index pages for directories that don't have an explicit index file.
 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        Sat Oct 26 22:58:06 2002
++++ thttpd-2.21b-cool/fdwatch.c        Wed Oct 30 13:15:49 2002
 @@ -460,7 +460,7 @@
  
      ridx = 0;
@@ -96,7 +96,7 @@
      }
 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       Sat Oct 26 23:58:21 2002
++++ thttpd-2.21b-cool/libhttpd.c       Wed Oct 30 20:03:39 2002
 @@ -85,6 +85,12 @@
  #include "match.h"
  #include "tdate_parse.h"
@@ -203,7 +203,7 @@
        if ( extraheads[0] != '\0' )
            add_response( hc, extraheads );
        add_response( hc, "\r\n" );
-@@ -1603,6 +1630,61 @@
+@@ -1603,6 +1630,63 @@
  
  
  int
@@ -258,6 +258,8 @@
 +    hc->do_keep_alive = 0;
 +    hc->should_linger = 0;
 +    hc->file_address = (char*) 0;
++    hc->read_body_into_mem = 0;
++    hc->read_body_into_fd = 0;
 +    return GC_OK;
 +}
 +
@@ -265,7 +267,7 @@
  httpd_get_conn( httpd_server* hs, int listen_fd, httpd_conn* hc )
      {
      httpd_sockaddr sa;
-@@ -1657,53 +1739,12 @@
+@@ -1657,53 +1741,12 @@
      hc->hs = hs;
      memset( &hc->client_addr, 0, sizeof(hc->client_addr) );
      memcpy( &hc->client_addr, &sa, sockaddr_len( &sa ) );
@@ -325,7 +327,7 @@
      }
  
  
-@@ -1720,6 +1761,9 @@
+@@ -1720,6 +1763,9 @@
      {
      char c;
  
@@ -335,7 +337,7 @@
      for ( ; hc->checked_idx < hc->read_idx; ++hc->checked_idx )
        {
        c = hc->read_buf[hc->checked_idx];
-@@ -1912,8 +1956,11 @@
+@@ -1912,8 +1958,11 @@
            eol = strpbrk( protocol, " \t\n\r" );
            if ( eol != (char*) 0 )
                *eol = '\0';
@@ -348,7 +350,7 @@
            }
        }
      /* Check for HTTP/1.1 absolute URL. */
-@@ -2129,6 +2176,7 @@
+@@ -2129,6 +2178,7 @@
                cp = &buf[11];
                cp += strspn( cp, " \t" );
                if ( strcasecmp( cp, "keep-alive" ) == 0 )
@@ -356,7 +358,7 @@
                    hc->keep_alive = 1;
                }
  #ifdef LOG_UNKNOWN_HEADERS
-@@ -2168,6 +2216,9 @@
+@@ -2168,6 +2218,9 @@
            }
        }
  
@@ -366,7 +368,7 @@
      if ( hc->one_one )
        {
        /* Check that HTTP/1.1 requests specify a host, as required. */
-@@ -2177,14 +2228,14 @@
+@@ -2177,14 +2230,14 @@
            return -1;
            }
  
@@ -388,7 +390,7 @@
        }
  
      /* Ok, the request has been parsed.  Now we resolve stuff that
-@@ -2349,15 +2400,24 @@
+@@ -2349,15 +2402,24 @@
  
  
  void
@@ -417,7 +419,7 @@
      if ( hc->conn_fd >= 0 )
        {
        (void) close( hc->conn_fd );
-@@ -3026,11 +3086,9 @@
+@@ -3026,11 +3088,9 @@
  post_post_garbage_hack( httpd_conn* hc )
      {
      char buf[2];
@@ -431,7 +433,7 @@
      }
  
  
-@@ -3313,6 +3371,11 @@
+@@ -3313,6 +3373,11 @@
      int r;
      ClientData client_data;
  
@@ -443,7 +445,7 @@
      if ( hc->method == METHOD_GET || hc->method == METHOD_POST )
        {
        httpd_clear_ndelay( hc->conn_fd );
-@@ -3369,6 +3432,7 @@
+@@ -3369,6 +3434,7 @@
      int expnlen, indxlen;
      char* cp;
      char* pi;
@@ -451,7 +453,7 @@
  
      expnlen = strlen( hc->expnfilename );
  
-@@ -3561,6 +3625,16 @@
+@@ -3561,6 +3627,16 @@
         match( hc->hs->cgi_pattern, hc->expnfilename ) )
        return cgi( hc );
  
@@ -468,7 +470,7 @@
      /* 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 +3668,8 @@
+@@ -3594,6 +3670,8 @@
        hc->end_byte_loc = hc->sb.st_size - 1;
  
      figure_mime( hc );
@@ -477,7 +479,7 @@
  
      if ( hc->method == METHOD_HEAD )
        {
-@@ -3601,7 +3677,7 @@
+@@ -3601,7 +3679,7 @@
            hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size,
            hc->sb.st_mtime );
        }
@@ -486,7 +488,7 @@
         hc->if_modified_since >= hc->sb.st_mtime )
        {
        hc->method = METHOD_HEAD;
-@@ -3611,14 +3687,25 @@
+@@ -3611,14 +3689,25 @@
        }
      else
        {
@@ -516,7 +518,7 @@
  
 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       Sat Oct 26 23:33:32 2002
++++ thttpd-2.21b-cool/libhttpd.h       Wed Oct 30 20:03:53 2002
 @@ -69,6 +69,8 @@
      char* server_hostname;
      int port;
@@ -526,7 +528,7 @@
      char* charset;
      char* cwd;
      int listen4_fd, listen6_fd;
-@@ -132,7 +134,7 @@
+@@ -132,11 +134,13 @@
      int got_range;
      int tildemapped;  /* this connection got tilde-mapped */
      off_t init_byte_loc, end_byte_loc;
@@ -535,7 +537,13 @@
      int should_linger;
      struct stat sb;
      int conn_fd;
-@@ -168,7 +170,8 @@
+     char* file_address;
++    char read_body_into_mem;
++    int read_body_into_fd;
+     } httpd_conn;
+ 
+ /* Methods. */
+@@ -168,7 +172,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,
@@ -545,7 +553,7 @@
  
  /* Change the log file. */
  extern void httpd_set_logfp( httpd_server* hs, FILE* logfp );
-@@ -229,6 +232,8 @@
+@@ -229,6 +234,8 @@
  ** If you don't have a current timeval handy just pass in 0.
  */
  extern void httpd_close_conn( httpd_conn* hc, struct timeval* nowP );
@@ -556,7 +564,7 @@
  ** 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       Sat Oct 26 22:58:06 2002
++++ thttpd-2.21b-cool/mime_encodings.txt       Wed Oct 30 13:15:49 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.
@@ -568,7 +576,7 @@
  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   Sat Oct 26 22:58:06 2002
++++ thttpd-2.21b-cool/mime_types.txt   Wed Oct 30 13:15:49 2002
 @@ -1,135 +1,138 @@
 -# mime_types.txt
 -#
@@ -819,7 +827,7 @@
 +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    Sun Oct 27 00:01:08 2002
++++ thttpd-2.21b-cool/mmc.c    Wed Oct 30 13:15:49 2002
 @@ -70,6 +70,7 @@
      unsigned int hash;
      int hash_idx;
@@ -891,7 +899,7 @@
        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    Sat Oct 26 22:58:06 2002
++++ thttpd-2.21b-cool/mmc.h    Wed Oct 30 13:15:49 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.
@@ -905,7 +913,7 @@
  ** 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 Sun Oct 27 00:03:52 2002
++++ thttpd-2.21b-cool/thttpd.c Wed Oct 30 20:04:27 2002
 @@ -66,6 +66,8 @@
  static char* dir;
  static int do_chroot, no_log, no_symlink, do_vhost, do_global_passwd;
@@ -928,7 +936,7 @@
      Timer* wakeup_timer;
      Timer* linger_timer;
      long wouldblock_delay;
-@@ -106,17 +108,21 @@
+@@ -106,17 +108,22 @@
      off_t bytes_sent;
      off_t bytes_to_send;
      } connecttab;
@@ -952,16 +960,18 @@
 +      CNST_PAUSING,
 +      CNST_LINGERING,
 +      CNST_SENDING_RESP,
++      CNST_READING_BODY,
 +      CNST_TOTAL_NR
 +};
  
  static httpd_server* hs = (httpd_server*) 0;
  int terminate = 0;
-@@ -140,14 +146,14 @@
+@@ -140,14 +147,15 @@
  static int handle_newconnect( struct timeval* tvP, int listen_fd );
  static void handle_read( connecttab* c, struct timeval* tvP );
  static void handle_send( connecttab* c, struct timeval* tvP );
 +static void handle_send_resp( connecttab* c, struct timeval* tvP );
++static void handle_read_body( connecttab* c, struct timeval* tvP );
  static void handle_linger( connecttab* c, struct timeval* tvP );
  static int check_throttles( connecttab* c );
 +static void timeout_conns( ClientData client_data, struct timeval* nowP );
@@ -975,20 +985,22 @@
  static void wakeup_connection( ClientData client_data, struct timeval* nowP );
  static void linger_clear_connection( ClientData client_data, struct timeval* nowP );
  static void occasional( ClientData client_data, struct timeval* nowP );
-@@ -157,6 +163,12 @@
+@@ -156,7 +164,14 @@
+ #endif /* STATS_TIME */
  static void logstats( struct timeval* nowP );
  static void thttpd_logstats( long secs );
- 
++static void boot_request(connecttab *c, struct timeval *tvP);
++
 +typedef void (*handler_func)(connecttab*, struct timeval *);
 +
 +handler_func handler_array[CNST_TOTAL_NR] =
-+{NULL, handle_read, handle_send, NULL, handle_linger, handle_send_resp};
-+
++{NULL, handle_read, handle_send, NULL, handle_linger, handle_send_resp, 
+handle_read_body};
+ 
 +#define RUN_HANDLER(type, c) handler_array[type](c, &tv)
  
  static void
  handle_term( int sig )
-@@ -198,6 +210,8 @@
+@@ -198,6 +213,8 @@
      }
  
  
@@ -997,7 +1009,7 @@
  static void
  handle_usr2( int sig )
      {
-@@ -420,7 +434,8 @@
+@@ -420,7 +437,8 @@
        hostname,
        gotv4 ? &sa4 : (httpd_sockaddr*) 0, gotv6 ? &sa6 : (httpd_sockaddr*) 0,
        port, cgi_pattern, charset, cwd, no_log, logfp, no_symlink, do_vhost,
@@ -1007,7 +1019,7 @@
      if ( hs == (httpd_server*) 0 )
        exit( 1 );
  
-@@ -430,6 +445,12 @@
+@@ -430,6 +448,12 @@
        syslog( LOG_CRIT, "tmr_create(occasional) failed" );
        exit( 1 );
        }
@@ -1020,7 +1032,7 @@
      if ( numthrottles > 0 )
        {
        /* Set up the throttles timer. */
-@@ -454,12 +475,14 @@
+@@ -454,12 +478,14 @@
      /* If we're root, try to become someone else. */
      if ( getuid() == 0 )
        {
@@ -1035,7 +1047,7 @@
        /* Set primary group. */
        if ( setgid( gid ) < 0 )
            {
-@@ -495,13 +518,17 @@
+@@ -495,13 +521,17 @@
        }
      maxconnects -= SPARE_FDS;
      connects = NEW( connecttab, maxconnects );
@@ -1053,7 +1065,7 @@
        connects[cnum].conn_state = CNST_FREE;
        connects[cnum].hc = (httpd_conn*) 0;
        }
-@@ -518,6 +545,8 @@
+@@ -518,6 +548,8 @@
  
      /* Main loop. */
      (void) gettimeofday( &tv, (struct timezone*) 0 );
@@ -1062,7 +1074,7 @@
      while ( ( ! terminate ) || numconnects > 0 )
        {
        /* Do the fd watch. */
-@@ -566,15 +595,17 @@
+@@ -566,15 +598,18 @@
            if ( c == (connecttab*) 0 )
                continue;
            hc = c->hc;
@@ -1080,6 +1092,7 @@
 +                      case CNST_SENDING:
 +                      case CNST_LINGERING:
 +                      case CNST_SENDING_RESP:
++                      case CNST_READING_BODY:
 +                              fdwatch_check_fd(hc->conn_fd);
 +                              RUN_HANDLER(c->conn_state, c);
 +                              break;
@@ -1089,7 +1102,7 @@
            }
        tmr_run( &tv );
  
-@@ -627,6 +658,8 @@
+@@ -627,6 +662,8 @@
  #else /* CGI_PATTERN */
      cgi_pattern = (char*) 0;
  #endif /* CGI_PATTERN */
@@ -1098,7 +1111,7 @@
      url_pattern = (char*) 0;
      no_empty_referers = 0;
      local_pattern = (char*) 0;
-@@ -833,6 +866,16 @@
+@@ -833,6 +870,16 @@
                value_required( name, value );
                cgi_pattern = e_strdup( value );
                }
@@ -1115,7 +1128,7 @@
            else if ( strcasecmp( name, "urlpat" ) == 0 )
                {
                value_required( name, value );
-@@ -1196,8 +1239,10 @@
+@@ -1196,8 +1243,10 @@
      logstats( &tv );
      for ( cnum = 0; cnum < maxconnects; ++cnum )
        {
@@ -1127,7 +1140,7 @@
        if ( connects[cnum].hc != (httpd_conn*) 0 )
            {
            httpd_destroy_conn( connects[cnum].hc );
-@@ -1214,6 +1259,7 @@
+@@ -1214,6 +1263,7 @@
        }
      mmc_destroy();
      tmr_destroy();
@@ -1135,7 +1148,7 @@
      free( (void*) connects );
      if ( throttles != (throttletab*) 0 )
        free( (void*) throttles );
-@@ -1234,7 +1280,7 @@
+@@ -1234,7 +1284,7 @@
      for (;;)
        {
        /* Is there room in the connection table? */
@@ -1144,7 +1157,7 @@
            {
            /* Out of connection slots.  Run the timers, then the
            ** existing connections, and maybe we'll free up a slot
-@@ -1245,10 +1291,10 @@
+@@ -1245,10 +1295,10 @@
            return 0;
            }
        /* Find a free connection entry. */
@@ -1159,7 +1172,7 @@
        /* Make the httpd_conn if necessary. */
        if ( c->hc == (httpd_conn*) 0 )
            {
-@@ -1267,24 +1313,18 @@
+@@ -1267,24 +1317,18 @@
            {
            case GC_FAIL:
            case GC_NO_MORE:
@@ -1187,11 +1200,32 @@
  
        /* Set the connection file descriptor to no-delay mode. */
        httpd_set_ndelay( c->hc->conn_fd );
-@@ -1297,12 +1337,28 @@
+@@ -1297,12 +1341,49 @@
        }
      }
  
 +static void
++setup_read_body(connecttab *c, struct timeval *tvP) 
++{
++      httpd_conn *hc = c->hc;
++      int already, missing, unused, nalloc;
++      
++      c->conn_state = CNST_READING_BODY;
++
++      hc->read_body_into_mem = 0;
++      
++      already = hc->read_idx - hc->checked_idx;
++      missing = hc->contentlength - already;
++      unused = hc->read_size - hc->read_idx;
++      nalloc = missing - unused;
++      
++      httpd_realloc_str(&hc->read_buf, &hc->read_size, hc->checked_idx + 
+hc->contentlength + 10);
++
++    fdwatch_del_fd( hc->conn_fd );
++    fdwatch_add_fd( hc->conn_fd, c, FDW_READ );
++}
++
++static void
 +setup_sending(connecttab *c, int state, struct timeval *tvP)
 +{
 +    httpd_conn *hc = c->hc;
@@ -1217,7 +1251,7 @@
      httpd_conn* hc = c->hc;
  
      /* Is there room in our buffer to read more bytes? */
-@@ -1311,7 +1367,7 @@
+@@ -1311,7 +1392,7 @@
        if ( hc->read_size > 5000 )
            {
            httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" );
@@ -1226,7 +1260,7 @@
            return;
            }
        httpd_realloc_str(
-@@ -1327,14 +1383,42 @@
+@@ -1327,14 +1408,43 @@
      ** EWOULDBLOCK; however, this apparently can happen if a packet gets
      ** garbled.
      */
@@ -1266,6 +1300,7 @@
        }
 -    hc->read_idx += sz;
  
++
 +static void
 +handle_request( connecttab *c, struct timeval *tvP)
 +{
@@ -1274,7 +1309,7 @@
      /* Do we have a complete request yet? */
      switch ( httpd_got_request( hc ) )
        {
-@@ -1342,14 +1426,14 @@
+@@ -1342,14 +1452,14 @@
        return;
        case GR_BAD_REQUEST:
        httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" );
@@ -1291,7 +1326,7 @@
        return;
        }
  
-@@ -1358,7 +1442,7 @@
+@@ -1358,18 +1468,28 @@
        {
        httpd_send_err(
            hc, 503, httpd_err503title, "", httpd_err503form, hc->encodedurl );
@@ -1299,8 +1334,13 @@
 +      clear_connection( c, tvP, 0 );
        return;
        }
++      boot_request(c, tvP);
++}
  
-@@ -1366,7 +1450,7 @@
++static void boot_request(connecttab *c, struct timeval *tvP)
++{
++      httpd_conn *hc = c->hc;
+     /* Start the connection going. */
      if ( httpd_start_request( hc, tvP ) < 0 )
        {
        /* Something went wrong.  Close down the connection. */
@@ -1309,7 +1349,15 @@
        return;
        }
  
-@@ -1384,37 +1468,24 @@
++    if ( hc->read_body_into_mem ) {
++      setup_read_body( c, tvP );
++      return;
++      }
++      
+     /* Fill in bytes_to_send. */
+     if ( hc->got_range )
+       {
+@@ -1384,37 +1504,24 @@
        {
        /* No file address means someone else is handling it. */
        c->bytes_sent = hc->bytes_sent;
@@ -1354,7 +1402,7 @@
  static void
  handle_send( connecttab* c, struct timeval* tvP )
      {
-@@ -1443,6 +1514,9 @@
+@@ -1443,6 +1550,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 );
@@ -1364,7 +1412,7 @@
        }
  
      if ( sz == 0 ||
-@@ -1486,12 +1560,12 @@
+@@ -1486,12 +1596,12 @@
        */
        if ( errno != EPIPE && errno != EINVAL && errno != ECONNRESET )
            syslog( LOG_ERR, "write - %m sending %.80s", hc->encodedurl );
@@ -1379,7 +1427,7 @@
      /* Was this a headers + file writev()? */
      if ( hc->responselen > 0 )
        {
-@@ -1500,7 +1574,7 @@
+@@ -1500,7 +1610,7 @@
            {
            /* Yes; move the unwritten part to the front of the buffer. */
            int newlen = hc->responselen - sz;
@@ -1388,7 +1436,7 @@
            hc->responselen = newlen;
            sz = 0;
            }
-@@ -1519,7 +1593,7 @@
+@@ -1519,7 +1629,7 @@
      if ( c->bytes_sent >= c->bytes_to_send )
        {
        /* This conection is finished! */
@@ -1397,7 +1445,7 @@
        return;
        }
  
-@@ -1560,6 +1634,9 @@
+@@ -1560,6 +1670,9 @@
      char buf[1024];
      int r;
  
@@ -1407,11 +1455,35 @@
      /* In lingering-close mode we just read and ignore bytes.  An error
      ** or EOF ends things, otherwise we go until a timeout.
      */
-@@ -1569,6 +1646,37 @@
+@@ -1569,6 +1682,61 @@
      }
  
  
 +static void
++handle_read_body(connecttab *c, struct timeval *tvP)
++{
++      httpd_conn *hc = c->hc;
++      int n;
++      
++      n = read(hc->conn_fd, hc->read_buf + hc->read_idx, 
++                      hc->contentlength - (hc->read_idx - hc->checked_idx));
++      
++      if (n <= 0) {
++              if (errno == EAGAIN)
++                      return;
++              clear_connection(c, tvP, 0);
++              return;
++      }
++
++      hc->read_idx += n;
++
++      if (hc->contentlength == hc->read_idx - hc->checked_idx) {
++              boot_request(c, tvP);
++              return;
++      }
++}
++
++static void
 +handle_send_resp(connecttab *c, struct timeval *tvP)
 +{
 +      httpd_conn* hc = c->hc;
@@ -1445,7 +1517,7 @@
  static int
  check_throttles( connecttab* c )
      {
-@@ -1635,23 +1743,18 @@
+@@ -1635,23 +1803,18 @@
  
  
  static void
@@ -1475,7 +1547,7 @@
      if ( c->wakeup_timer != (Timer*) 0 )
        {
        tmr_cancel( c->wakeup_timer );
-@@ -1669,13 +1772,36 @@
+@@ -1669,13 +1832,36 @@
      ** circumstances that make a lingering close necessary.  If the flag
      ** isn't set we do the real close now.
      */
@@ -1514,7 +1586,7 @@
        client_data.p = c;
        c->linger_timer = tmr_create(
            tvP, linger_clear_connection, client_data, LINGER_TIME * 1000L, 0 );
-@@ -1684,9 +1810,19 @@
+@@ -1684,9 +1870,19 @@
            syslog( LOG_CRIT, "tmr_create(linger_clear_connection) failed" );
            exit( 1 );
            }
@@ -1535,7 +1607,7 @@
      }
  
  
-@@ -1702,45 +1838,12 @@
+@@ -1702,45 +1898,12 @@
        tmr_cancel( c->linger_timer );
        c->linger_timer = 0;
        }
@@ -1582,7 +1654,7 @@
  
  static void
  wakeup_connection( ClientData client_data, struct timeval* nowP )
-@@ -1826,3 +1929,41 @@
+@@ -1826,3 +1989,41 @@
      stats_connections = stats_bytes = 0L;
      stats_simultaneous = 0;
      }

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to