[MAJOR] convert all expiration timers from timeval to ticks

This is the first attempt at moving all internal parts from
using struct timeval to integer ticks. Those provides simpler
and faster code due to simplified operations, and this change
also saved about 64 bytes per session.

A new header file has been added : include/common/ticks.h.

It is possible that some functions should finally not be inlined
because they're used quite a lot (eg: tick_first, tick_add_ifset
and tick_is_expired). More measurements are required in order to
decide whether this is interesting or not.

Some function and variable names are still subject to change for
a better overall logics.
diff --git a/include/types/buffers.h b/include/types/buffers.h
index 583c517..a9de965 100644
--- a/include/types/buffers.h
+++ b/include/types/buffers.h
@@ -2,7 +2,7 @@
   include/types/buffers.h
   Buffer management definitions, macros and inline functions.
 
-  Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
+  Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
   
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -25,9 +25,6 @@
 #include <common/config.h>
 #include <common/memory.h>
 
-#include <sys/time.h>
-#include <sys/types.h>
-
 /* The BF_* macros designate Buffer Flags, which may be ORed in the bit field
  * member 'flags' in struct buffer.
  */
@@ -65,12 +62,12 @@
 
 struct buffer {
 	unsigned int flags;             /* BF_* */
-	struct timeval rex;             /* expiration date for a read  */
-	struct timeval wex;             /* expiration date for a write */
-	struct timeval cex;             /* expiration date for a connect */
-	struct timeval rto;             /* read timeout */
-	struct timeval wto;             /* write timeout */
-	struct timeval cto;             /* connect timeout */
+	int rex;                        /* expiration date for a read, in ticks */
+	int wex;                        /* expiration date for a write, in ticks */
+	int cex;                        /* expiration date for a connect, in ticks */
+	int rto;                        /* read timeout, in ticks */
+	int wto;                        /* write timeout, in ticks */
+	int cto;                        /* connect timeout, in ticks */
 	unsigned int l;                 /* data length */
 	char *r, *w, *lr;               /* read ptr, write ptr, last read */
 	char *rlim;                     /* read limit, used for header rewriting */
diff --git a/include/types/fd.h b/include/types/fd.h
index 1f1b3b4..7d746f0 100644
--- a/include/types/fd.h
+++ b/include/types/fd.h
@@ -2,7 +2,7 @@
   include/types/fd.h
   File descriptors states.
 
-  Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
+  Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
   
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -100,7 +100,7 @@
 	int  REGPRM2 (*cond_c)(const int fd, int dir);       /* clear polling on <fd> for <dir> if set */
 	void REGPRM1    (*rem)(const int fd);                /* remove any polling on <fd> */
 	void REGPRM1    (*clo)(const int fd);                /* mark <fd> as closed */
-    	void REGPRM2   (*poll)(struct poller *p, struct timeval *exp); /* the poller itself */
+    	void REGPRM2   (*poll)(struct poller *p, int exp);   /* the poller itself */
 	int  REGPRM1   (*init)(struct poller *p);            /* poller initialization */
 	void REGPRM1   (*term)(struct poller *p);            /* termination of this poller */
 	int  REGPRM1   (*test)(struct poller *p);            /* pre-init check of the poller */
diff --git a/include/types/global.h b/include/types/global.h
index 1636954..38b194c 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -66,7 +66,7 @@
 		int maxaccept;     /* max number of consecutive accept() */
 	} tune;
 	struct listener stats_sock; /* unix socket listener for statistics */
-	struct timeval stats_timeout;
+	int stats_timeout;          /* in ticks */
 };
 
 extern struct global global;
diff --git a/include/types/proto_http.h b/include/types/proto_http.h
index 5b0914f..cc647a6 100644
--- a/include/types/proto_http.h
+++ b/include/types/proto_http.h
@@ -2,7 +2,7 @@
   include/types/proto_http.h
   This file contains HTTP protocol definitions.
 
-  Copyright (C) 2000-2006 Willy Tarreau - w@1wt.eu
+  Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
   
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -240,7 +240,7 @@
 	char *srv_cookie;		/* cookie presented by the server, in capture mode */
 	int status;			/* HTTP status from the server, negative if from proxy */
 	unsigned int flags;             /* transaction flags */
-	struct timeval exp;             /* expiration date for the transaction (generally a request) */
+	int exp;                        /* expiration date for the transaction (generally a request), int ticks */
 };
 
 /* This structure is used by http_find_header() to return values of headers.
diff --git a/include/types/protocols.h b/include/types/protocols.h
index 971a2a6..745b440 100644
--- a/include/types/protocols.h
+++ b/include/types/protocols.h
@@ -83,8 +83,8 @@
 	struct listener *next;		/* next address for the same proxy, or NULL */
 	struct list proto_list;         /* list in the protocol header */
 	int (*accept)(int fd);		/* accept() function passed to fdtab[] */
-	void (*handler)(struct task *t, struct timeval *next); /* protocol handler */
-	struct timeval *timeout;	/* pointer to client-side timeout */
+	void (*handler)(struct task *t, int *next); /* protocol handler */
+	int  *timeout;                  /* pointer to client-side timeout */
 	void *private;			/* any private data which may be used by accept() */
 	union {				/* protocol-dependant access restrictions */
 		struct {		/* UNIX socket permissions */
diff --git a/include/types/proxy.h b/include/types/proxy.h
index 10a69b5..2a84aaf 100644
--- a/include/types/proxy.h
+++ b/include/types/proxy.h
@@ -182,14 +182,14 @@
 	int monitor_uri_len;			/* length of the string above. 0 if unused */
 	struct list mon_fail_cond;              /* list of conditions to fail monitoring requests (chained) */
 	struct {				/* WARNING! check proxy_reset_timeouts() in proxy.h !!! */
-		struct timeval client;		/* client I/O timeout (in milliseconds) */
-		struct timeval tarpit;          /* tarpit timeout, defaults to connect if unspecified */
-		struct timeval queue;           /* queue timeout, defaults to connect if unspecified */
-		struct timeval connect;		/* connect timeout (in milliseconds) */
-		struct timeval server;		/* server I/O timeout (in milliseconds) */
-		struct timeval appsession;	/* appsession cookie expiration */
-		struct timeval httpreq;		/* maximum time for complete HTTP request */
-		struct timeval check;		/* maximum time for complete check */
+		int client;                     /* client I/O timeout (in ticks) */
+		int tarpit;                     /* tarpit timeout, defaults to connect if unspecified */
+		int queue;                      /* queue timeout, defaults to connect if unspecified */
+		int connect;                    /* connect timeout (in ticks) */
+		int server;                     /* server I/O timeout (in ticks) */
+		int appsession;                 /* appsession cookie expiration */
+		int httpreq;                    /* maximum time for complete HTTP request */
+		int check;                      /* maximum time for complete check */
 	} timeout;
 	char *id;				/* proxy id */
 	struct list pendconns;			/* pending connections with no server assigned yet */
@@ -224,7 +224,7 @@
 	signed char logfac1, logfac2;		/* log facility for both servers. -1 = disabled */
 	int loglev1, loglev2;			/* log level for each server, 7 by default */
 	int to_log;				/* things to be logged (LW_*) */
-	struct timeval stop_time;		/* date to stop listening, when stopping != 0 */
+	int stop_time;                          /* date to stop listening, when stopping != 0 (int ticks) */
 	int nb_reqadd, nb_rspadd;
 	struct hdr_exp *req_exp;		/* regular expressions for request headers */
 	struct hdr_exp *rsp_exp;		/* regular expressions for response headers */
diff --git a/include/types/task.h b/include/types/task.h
index 4e579c1..ae9166e 100644
--- a/include/types/task.h
+++ b/include/types/task.h
@@ -36,8 +36,8 @@
 struct task {
 	struct eb32_node eb;		/* ebtree node used to hold the task in the wait queue */
 	int state;			/* task state : IDLE or RUNNING */
-	struct timeval expire;		/* next expiration time for this task, use only for fast sorting */
-	void (*process)(struct task *t, struct timeval *next);	/* the function which processes the task */
+	unsigned int expire;		/* next expiration time for this task */
+	void (*process)(struct task *t, int *next);  /* the function which processes the task */
 	void *context;			/* the task's context */
 	int nice;			/* the task's current nice value from -1024 to +1024 */
 };