From 6dab29fb11bec8cecb5fc8ae5013cb88f31701b3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 22 Aug 2007 10:34:20 -0700 Subject: make configuration constants dynamically assignable This will eventually allow us to tweak things easily w/o recompiling --- david.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/david.c b/david.c index 5c8c43d..bda4624 100644 --- a/david.c +++ b/david.c @@ -10,25 +10,25 @@ * * NR_CONN needs to be <= (FD_SETSIZE - 4) */ -#define MAX_CHILDREN 1 -#define NR_CONN 1000 +static int MAX_CHILDREN = 1; +static int NR_CONN = 1000; /* * the delay between subsequent send/recv() calls to each socket, * assuming the socket is write/readable */ -#define DELAY_SECONDS 1 +static int DELAY_SECONDS = 1; /* the maximum number of bytes we write at once */ -#define WR_BYTES 8 +static int WR_BYTES = 8; /* the maximum number of bytes we read at once */ -#define RD_BYTES 8 +static int RD_BYTES = 8; /* * set this to 1 to enable printing of requests and responses to stdout */ -#define DEBUG 1 +static int DEBUG = 0; /* -------- end of configuration section --------- */ @@ -77,8 +77,8 @@ struct interface { time_t last; }; -struct interface interfaces[NR_CONN]; -static pid_t children_pids[MAX_CHILDREN]; +static struct interface *interfaces; +static pid_t *children_pids; static void die(const char *fmt, ...) { @@ -187,6 +187,8 @@ static void init_interface(const int i) static void open_interfaces(void) { int i; + + interfaces = malloc(sizeof(struct interface) * NR_CONN); for (i = 0; i < NR_CONN; ++i) init_interface(i); } @@ -304,6 +306,7 @@ int main(int argc, const char *argv[]) mmap_request(argv[1]); setup_addrinfo(); + children_pids = malloc(sizeof(pid_t) * MAX_CHILDREN); for (i = 0; i < MAX_CHILDREN; ++i) { fflush(NULL); -- cgit v1.2.3-24-ge0c7