/*
  File:  close_connection.c

  Description:  shut down a connection somewhere 
*/

#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include "proxy_protos.h"



void
close_connection ( struct mdata *md, int fd )
{
  float          r;
  float          w;
  int            who;

  close(fd);
  md->r[fd].status = FD_CLOSE;

  /* record the time */

  r = diff_timeval(&md->r[fd].ti_read,&md->r[fd].tf_read);
  w = diff_timeval(&md->r[fd].ti_write,&md->r[fd].tf_write);

  who = md->r[fd].type;
  md->time_reading[who] += r;
  md->time_writing[who] += w;

  /* log client connections. */
  
  if ( who == CLIENT ) {
    log_msg(md,"closing CLIENT: [%s] read [%d] [%.4f] wrote [%d] [%.4f]",
	    md->r[fd].ip, 
	    md->r[fd].bytes_read, r,	    
	    md->r[fd].bytes_written, w);
    md->num_clients--;
  }
  
  md->r[fd].bytes_read    = 0;
  md->r[fd].bytes_written = 0;
}
  


syntax highlighted by Code2HTML, v. 0.9.1