From f8ad0dced37cb3b2b4402d12ac654bc27beaa8e4 Mon Sep 17 00:00:00 2001 From: Robert James Kaes Date: Thu, 25 Oct 2001 16:58:09 +0000 Subject: Moved the connection creation/destruction and definition into it's own files. --- src/conns.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/conns.h | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/conns.c create mode 100644 src/conns.h diff --git a/src/conns.c b/src/conns.c new file mode 100644 index 0000000..daf5ad3 --- /dev/null +++ b/src/conns.c @@ -0,0 +1,58 @@ +/* $Id: conns.c,v 1.3 2001-10-25 16:58:09 rjkaes Exp $ + * + * Create and free the connection structure. One day there could be + * other connnection related tasks put here, but for now the header + * file and this file are only used for create/free functions and the + * connection structure definition. + * + * Copyright (C) 2001 Robert James Kaes (rjkaes@flarenet.com) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include "tinyproxy.h" + +#include "buffer.h" +#include "conns.h" +#include "stats.h" +#include "utils.h" + +void initialize_conn(struct conn_s *connptr) +{ + connptr->client_fd = connptr->server_fd = -1; + connptr->cbuffer = new_buffer(); + connptr->sbuffer = new_buffer(); + + connptr->send_message = FALSE; + connptr->simple_req = FALSE; + + connptr->ssl = FALSE; + connptr->upstream = FALSE; + + update_stats(STAT_OPEN); +} + +void destroy_conn(struct conn_s *connptr) +{ + if (connptr->client_fd != -1) + close(connptr->client_fd); + if (connptr->server_fd != -1) + close(connptr->server_fd); + + if (connptr->cbuffer) + delete_buffer(connptr->cbuffer); + if (connptr->sbuffer) + delete_buffer(connptr->sbuffer); + + safefree(connptr); + + update_stats(STAT_CLOSE); +} diff --git a/src/conns.h b/src/conns.h new file mode 100644 index 0000000..123a075 --- /dev/null +++ b/src/conns.h @@ -0,0 +1,41 @@ +/* $Id: conns.h,v 1.3 2001-10-25 16:58:09 rjkaes Exp $ + * + * See 'conns.c' for a detailed description. + * + * Copyright (C) 2001 Robert James Kaes (rjkaes@flarenet.com) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#ifndef TINYPROXY_CONNS_H +#define TINYPROXY_CONNS_H + +/* + * Connection Definition + */ +struct conn_s { + int client_fd; + int server_fd; + struct buffer_s *cbuffer; + struct buffer_s *sbuffer; + bool_t simple_req; + bool_t ssl; + bool_t upstream; + bool_t send_message; +}; + +/* + * Functions for the creation and destruction of a connection structure. + */ +extern void initialize_conn(struct conn_s *connptr); +extern void destroy_conn(struct conn_s *connptr); + +#endif -- cgit v1.2.3