You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Nathan W. Schrenk" <ns...@neog.com> on 1996/01/22 00:24:22 UTC

Timeout patch

Here is my timeout fix in patch form.  Various people have expressed 
displeasure with this fix because it makes timeout_name a global.  If 
anyone has a good suggestion as to how to achieve the same affect without 
making this a global, let me know, and I'll try and submit a new patch. 

This patch fixes the problem exhibited at some sites where large transfers
from Apache were getting interrupted after the default timeout number of
seconds.  For example, if a user tries to download a 5 megabyte file over
a 28.8 PPP connection from a server running Apache, and the default 400
second timeout is in effect, the user will only get the first 400 seconds
worth of the file. This happens because Apache does not reset the timeout
timer when there is a successful write to the network.  This patch
addresses this problem. 

I have tested this at my site and the interrupted transfer problems 
cleared up, and nothing else seemed to break.

Here's the patch:

--
From: nschrenk@neog.com (Nathan Schrenk)
Subject: Timeout code fix
Affects: http_protocol.c, http_main.c
ChangeLog: Reset timeout timer after each successful fwrite() to the network.
           This patch makes timeout_name a global, and modifies the send_fd()
           procedure to check for an existing timeout by looking at
           timeout_name.  If a timeout is set, send_fd() resets the alarm timer
           to the default timeout every time fwrite() successfully sends data.

*** http_protocol.c.orig	Tue Jan  2 22:28:37 1996
--- http_protocol.c	Tue Jan  2 22:30:52 1996
***************
*** 537,543 ****
      long total_bytes_sent;
      register int n,o,w;
      conn_rec *c = r->connection;
!     
      total_bytes_sent = 0;
      while (!r->connection->aborted) {
          while ((n= fread(buf, sizeof(char), IOBUFSIZE, f)) < 1
--- 537,544 ----
      long total_bytes_sent;
      register int n,o,w;
      conn_rec *c = r->connection;
!     extern char *timeout_name;
!  
      total_bytes_sent = 0;
      while (!r->connection->aborted) {
          while ((n= fread(buf, sizeof(char), IOBUFSIZE, f)) < 1
***************
*** 550,557 ****
          o=0;
          if (r->bytes_sent != -1) r->bytes_sent += n;
  	total_bytes_sent += n;
! 	
!         while(n && !r->connection->aborted) {
              w=fwrite(&buf[o],sizeof(char),n,c->client);
              n-=w;
              o+=w;
--- 551,567 ----
          o=0;
          if (r->bytes_sent != -1) r->bytes_sent += n;
  	total_bytes_sent += n;
!         
!         if (timeout_name)  /* there is a timeout pending */
! 	  while(n && !r->connection->aborted) {
! 	    w=fwrite(&buf[o],sizeof(char),n,c->client);
! 	    if (w)
! 	      alarm(r->server->timeout);  /* reset timeout timer */
!             n-=w;
!             o+=w;
! 	  }
! 	else	
!           while(n && !r->connection->aborted) {
              w=fwrite(&buf[o],sizeof(char),n,c->client);
              n-=w;
              o+=w;

*** http_main.c.orig	Tue Jan  2 22:28:47 1996
--- http_main.c	Tue Jan  2 22:28:57 1996
***************
*** 211,217 ****
  
  static conn_rec *current_conn;
  static request_rec *timeout_req;
! static char *timeout_name;
  static int alarms_blocked = 0;
  static int alarm_pending = 0;
  
--- 211,217 ----
  
  static conn_rec *current_conn;
  static request_rec *timeout_req;
! char *timeout_name;
  static int alarms_blocked = 0;
  static int alarm_pending = 0;