mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 23:56:57 +02:00
[MEDIUM] many cleanups in the time functions
Now, functions whose name begins with '__tv_' are inlined. Also, 'tv_ms' is used as a prefix for functions using milliseconds.
This commit is contained in:
parent
f41d4b15ee
commit
42aae5c7cf
@ -2,7 +2,7 @@
|
|||||||
include/common/time.h
|
include/common/time.h
|
||||||
Time calculation functions and macros.
|
Time calculation functions and macros.
|
||||||
|
|
||||||
Copyright (C) 2000-2006 Willy Tarreau - w@1wt.eu
|
Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
@ -25,6 +25,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
|
#include <common/standard.h>
|
||||||
|
|
||||||
/* eternity when exprimed in timeval */
|
/* eternity when exprimed in timeval */
|
||||||
#ifndef TV_ETERNITY
|
#ifndef TV_ETERNITY
|
||||||
@ -47,114 +48,36 @@ extern struct timeval now; /* the current date at any moment */
|
|||||||
extern struct timeval start_date; /* the process's start date */
|
extern struct timeval start_date; /* the process's start date */
|
||||||
|
|
||||||
|
|
||||||
|
/**** exported functions *************************************************/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* adds <ms> ms to <from>, set the result to <tv> and returns a pointer <tv>
|
* adds <ms> ms to <from>, set the result to <tv> and returns a pointer <tv>
|
||||||
*/
|
*/
|
||||||
REGPRM3 struct timeval *tv_delayfrom(struct timeval *tv, const struct timeval *from, int ms);
|
REGPRM3 struct timeval *tv_ms_add(struct timeval *tv, const struct timeval *from, int ms);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* compares <tv1> and <tv2> modulo 1ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2
|
* compares <tv1> and <tv2> modulo 1ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2
|
||||||
* Must not be used when either argument is eternity. Use tv_cmp2_ms() for that.
|
* Must not be used when either argument is eternity. Use tv_ms_cmp2() for that.
|
||||||
*/
|
*/
|
||||||
REGPRM2 int tv_cmp_ms(const struct timeval *tv1, const struct timeval *tv2);
|
REGPRM2 int tv_ms_cmp(const struct timeval *tv1, const struct timeval *tv2);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* compares <tv1> and <tv2> modulo 1 ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2,
|
* compares <tv1> and <tv2> modulo 1 ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2,
|
||||||
* assuming that TV_ETERNITY is greater than everything.
|
* assuming that TV_ETERNITY is greater than everything.
|
||||||
*/
|
*/
|
||||||
REGPRM2 int tv_cmp2_ms(const struct timeval *tv1, const struct timeval *tv2);
|
REGPRM2 int tv_ms_cmp2(const struct timeval *tv1, const struct timeval *tv2);
|
||||||
|
|
||||||
/*
|
/**** general purpose functions and macros *******************************/
|
||||||
* compares <tv1> and <tv2> modulo 1 ms: returns 1 if tv1 <= tv2, 0 if tv1 > tv2,
|
|
||||||
* assuming that TV_ETERNITY is greater than everything. Returns 0 if tv1 is
|
|
||||||
* TV_ETERNITY, and always assumes that tv2 != TV_ETERNITY. Designed to replace
|
|
||||||
* occurrences of (tv_cmp2_ms(tv,now) <= 0).
|
|
||||||
*/
|
|
||||||
REGPRM2 int tv_cmp2_le(const struct timeval *tv1, const struct timeval *tv2);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* returns the remaining time between tv1=now and event=tv2
|
|
||||||
* if tv2 is passed, 0 is returned.
|
|
||||||
* Returns TIME_ETERNITY if tv2 is eternity.
|
|
||||||
*/
|
|
||||||
REGPRM2 unsigned long tv_remain2(const struct timeval *tv1, const struct timeval *tv2);
|
|
||||||
|
|
||||||
/* sets <tv> to the current time */
|
/* tv_now: sets <tv> to the current time */
|
||||||
REGPRM1 static inline struct timeval *tv_now(struct timeval *tv)
|
REGPRM1 static inline struct timeval *tv_now(struct timeval *tv)
|
||||||
{
|
{
|
||||||
if (tv)
|
|
||||||
gettimeofday(tv, NULL);
|
gettimeofday(tv, NULL);
|
||||||
return tv;
|
return tv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* compares <tv1> and <tv2> : returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2
|
|
||||||
*/
|
|
||||||
REGPRM2 static inline int tv_cmp(const struct timeval *tv1, const struct timeval *tv2)
|
|
||||||
{
|
|
||||||
if ((unsigned)tv1->tv_sec < (unsigned)tv2->tv_sec)
|
|
||||||
return -1;
|
|
||||||
else if ((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec)
|
|
||||||
return 1;
|
|
||||||
else if ((unsigned)tv1->tv_usec < (unsigned)tv2->tv_usec)
|
|
||||||
return -1;
|
|
||||||
else if ((unsigned)tv1->tv_usec > (unsigned)tv2->tv_usec)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* compares <tv1> and <tv2> : returns 0 if tv1 < tv2, 1 if tv1 >= tv2
|
|
||||||
*/
|
|
||||||
REGPRM2 static inline int tv_cmp_ge(const struct timeval *tv1, const struct timeval *tv2)
|
|
||||||
{
|
|
||||||
if ((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec)
|
|
||||||
return 1;
|
|
||||||
if ((unsigned)tv1->tv_sec < (unsigned)tv2->tv_sec)
|
|
||||||
return 0;
|
|
||||||
if ((unsigned)tv1->tv_usec >= (unsigned)tv2->tv_usec)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* returns the difference, in ms, between tv1 and tv2
|
|
||||||
* Must not be used when either argument is eternity.
|
|
||||||
*/
|
|
||||||
REGPRM2 static inline unsigned long tv_diff(const struct timeval *tv1, const struct timeval *tv2)
|
|
||||||
{
|
|
||||||
unsigned long ret;
|
|
||||||
|
|
||||||
ret = (tv2->tv_sec - tv1->tv_sec) * 1000;
|
|
||||||
if ((unsigned)tv2->tv_usec > (unsigned)tv1->tv_usec)
|
|
||||||
ret += (tv2->tv_usec - tv1->tv_usec) / 1000;
|
|
||||||
else
|
|
||||||
ret -= (tv1->tv_usec - tv2->tv_usec) / 1000;
|
|
||||||
return (unsigned long) ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* returns the remaining time between tv1=now and event=tv2
|
|
||||||
* if tv2 is passed, 0 is returned.
|
|
||||||
* Must not be used when either argument is eternity.
|
|
||||||
*/
|
|
||||||
REGPRM2 static inline unsigned long tv_remain(const struct timeval *tv1, const struct timeval *tv2)
|
|
||||||
{
|
|
||||||
unsigned long ret;
|
|
||||||
|
|
||||||
if (tv_cmp_ms(tv1, tv2) >= 0)
|
|
||||||
return 0; /* event elapsed */
|
|
||||||
|
|
||||||
ret = (tv2->tv_sec - tv1->tv_sec) * 1000;
|
|
||||||
if ((unsigned)tv2->tv_usec > (unsigned)tv1->tv_usec)
|
|
||||||
ret += (tv2->tv_usec - tv1->tv_usec) / 1000;
|
|
||||||
else
|
|
||||||
ret -= (tv1->tv_usec - tv2->tv_usec) / 1000;
|
|
||||||
return (unsigned long) ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* sets a struct timeval to its highest value so that it can never happen
|
* sets a struct timeval to its highest value so that it can never happen
|
||||||
* note that only tv_usec is necessary to detect it since a tv_usec > 999999
|
* note that only tv_usec is necessary to detect it since a tv_usec > 999999
|
||||||
@ -187,6 +110,211 @@ REGPRM1 static inline struct timeval *tv_zero(struct timeval *tv) {
|
|||||||
*/
|
*/
|
||||||
#define tv_iszero(tv) (((tv)->tv_sec | (tv)->tv_usec) == 0)
|
#define tv_iszero(tv) (((tv)->tv_sec | (tv)->tv_usec) == 0)
|
||||||
|
|
||||||
|
|
||||||
|
/**** comparision functions and macros ***********************************/
|
||||||
|
|
||||||
|
|
||||||
|
/* tv_cmp: compares <tv1> and <tv2> : returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2. */
|
||||||
|
REGPRM2 static inline int __tv_cmp(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
|
{
|
||||||
|
if ((unsigned)tv1->tv_sec < (unsigned)tv2->tv_sec)
|
||||||
|
return -1;
|
||||||
|
else if ((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec)
|
||||||
|
return 1;
|
||||||
|
else if ((unsigned)tv1->tv_usec < (unsigned)tv2->tv_usec)
|
||||||
|
return -1;
|
||||||
|
else if ((unsigned)tv1->tv_usec > (unsigned)tv2->tv_usec)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* tv_iseq: compares <tv1> and <tv2> : returns 1 if tv1 == tv2, otherwise 0 */
|
||||||
|
REGPRM2 static inline int __tv_iseq(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
|
{
|
||||||
|
return ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) &&
|
||||||
|
((unsigned)tv1->tv_usec == (unsigned)tv2->tv_usec);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* tv_isgt: compares <tv1> and <tv2> : returns 1 if tv1 > tv2, otherwise 0 */
|
||||||
|
REGPRM2 static inline int __tv_isgt(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) ?
|
||||||
|
((unsigned)tv1->tv_usec > (unsigned)tv2->tv_usec) :
|
||||||
|
((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* tv_isge: compares <tv1> and <tv2> : returns 1 if tv1 >= tv2, otherwise 0 */
|
||||||
|
REGPRM2 static inline int __tv_isge(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) ?
|
||||||
|
((unsigned)tv1->tv_usec >= (unsigned)tv2->tv_usec) :
|
||||||
|
((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* tv_islt: compares <tv1> and <tv2> : returns 1 if tv1 < tv2, otherwise 0 */
|
||||||
|
REGPRM2 static inline int __tv_islt(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) ?
|
||||||
|
((unsigned)tv1->tv_usec < (unsigned)tv2->tv_usec) :
|
||||||
|
((unsigned)tv1->tv_sec < (unsigned)tv2->tv_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* tv_isle: compares <tv1> and <tv2> : returns 1 if tv1 <= tv2, otherwise 0 */
|
||||||
|
REGPRM2 static inline int __tv_isle(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) ?
|
||||||
|
((unsigned)tv1->tv_usec <= (unsigned)tv2->tv_usec) :
|
||||||
|
((unsigned)tv1->tv_sec < (unsigned)tv2->tv_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* compares <tv1> and <tv2> modulo 1ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2
|
||||||
|
* Must not be used when either argument is eternity. Use tv_ms_cmp2() for that.
|
||||||
|
*/
|
||||||
|
#define tv_ms_cmp _tv_ms_cmp
|
||||||
|
REGPRM2 int _tv_ms_cmp(const struct timeval *tv1, const struct timeval *tv2);
|
||||||
|
REGPRM2 static inline int __tv_ms_cmp(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
|
{
|
||||||
|
if ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) {
|
||||||
|
if ((unsigned)tv2->tv_usec >= (unsigned)tv1->tv_usec + 1000)
|
||||||
|
return -1;
|
||||||
|
else if ((unsigned)tv1->tv_usec >= (unsigned)tv2->tv_usec + 1000)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (((unsigned)tv2->tv_sec > (unsigned)tv1->tv_sec + 1) ||
|
||||||
|
(((unsigned)tv2->tv_sec == (unsigned)tv1->tv_sec + 1) &&
|
||||||
|
((unsigned)tv2->tv_usec + 1000000 >= (unsigned)tv1->tv_usec + 1000)))
|
||||||
|
return -1;
|
||||||
|
else if (((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec + 1) ||
|
||||||
|
(((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec + 1) &&
|
||||||
|
((unsigned)tv1->tv_usec + 1000000 >= (unsigned)tv2->tv_usec + 1000)))
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* compares <tv1> and <tv2> modulo 1 ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2,
|
||||||
|
* assuming that TV_ETERNITY is greater than everything.
|
||||||
|
*/
|
||||||
|
#define tv_ms_cmp2 _tv_ms_cmp2
|
||||||
|
REGPRM2 int _tv_ms_cmp2(const struct timeval *tv1, const struct timeval *tv2);
|
||||||
|
REGPRM2 static inline int __tv_ms_cmp2(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
|
{
|
||||||
|
if (tv_iseternity(tv1))
|
||||||
|
if (tv_iseternity(tv2))
|
||||||
|
return 0; /* same */
|
||||||
|
else
|
||||||
|
return 1; /* tv1 later than tv2 */
|
||||||
|
else if (tv_iseternity(tv2))
|
||||||
|
return -1; /* tv2 later than tv1 */
|
||||||
|
return tv_ms_cmp(tv1, tv2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* compares <tv1> and <tv2> modulo 1 ms: returns 1 if tv1 <= tv2, 0 if tv1 > tv2,
|
||||||
|
* assuming that TV_ETERNITY is greater than everything. Returns 0 if tv1 is
|
||||||
|
* TV_ETERNITY, and always assumes that tv2 != TV_ETERNITY. Designed to replace
|
||||||
|
* occurrences of (tv_ms_cmp2(tv,now) <= 0).
|
||||||
|
*/
|
||||||
|
#define tv_ms_le2 _tv_ms_le2
|
||||||
|
REGPRM2 int _tv_ms_le2(const struct timeval *tv1, const struct timeval *tv2);
|
||||||
|
REGPRM2 static inline int __tv_ms_le2(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
|
{
|
||||||
|
if (likely((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec + 1))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (likely((unsigned)tv1->tv_sec < (unsigned)tv2->tv_sec))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (likely((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec)) {
|
||||||
|
if ((unsigned)tv2->tv_usec >= (unsigned)tv1->tv_usec + 1000)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unlikely(((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec + 1) &&
|
||||||
|
((unsigned)tv1->tv_usec + 1000000 >= (unsigned)tv2->tv_usec + 1000)))
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**** operators **********************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the time in ms elapsed between tv1 and tv2, assuming that tv1<=tv2.
|
||||||
|
* Must not be used when either argument is eternity.
|
||||||
|
*/
|
||||||
|
#define tv_ms_elapsed __tv_ms_elapsed
|
||||||
|
REGPRM2 unsigned long _tv_ms_elapsed(const struct timeval *tv1, const struct timeval *tv2);
|
||||||
|
REGPRM2 static inline unsigned long __tv_ms_elapsed(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
|
{
|
||||||
|
unsigned long ret;
|
||||||
|
|
||||||
|
ret = ((signed long)(tv2->tv_sec - tv1->tv_sec)) * 1000;
|
||||||
|
ret += ((signed long)(tv2->tv_usec - tv1->tv_usec)) / 1000;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returns the remaining time between tv1=now and event=tv2
|
||||||
|
* if tv2 is passed, 0 is returned.
|
||||||
|
* Must not be used when either argument is eternity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define tv_ms_remain __tv_ms_remain
|
||||||
|
REGPRM2 unsigned long _tv_ms_remain(const struct timeval *tv1, const struct timeval *tv2);
|
||||||
|
REGPRM2 static inline unsigned long __tv_ms_remain(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
|
{
|
||||||
|
if (tv_ms_cmp(tv1, tv2) >= 0)
|
||||||
|
return 0; /* event elapsed */
|
||||||
|
|
||||||
|
return __tv_ms_elapsed(tv1, tv2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returns the remaining time between tv1=now and event=tv2
|
||||||
|
* if tv2 is passed, 0 is returned.
|
||||||
|
* Returns TIME_ETERNITY if tv2 is eternity.
|
||||||
|
*/
|
||||||
|
#define tv_ms_remain2 _tv_ms_remain2
|
||||||
|
REGPRM2 unsigned long _tv_ms_remain2(const struct timeval *tv1, const struct timeval *tv2);
|
||||||
|
REGPRM2 static inline unsigned long __tv_ms_remain2(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
|
{
|
||||||
|
if (tv_iseternity(tv2))
|
||||||
|
return TIME_ETERNITY;
|
||||||
|
|
||||||
|
return tv_ms_remain(tv1, tv2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* adds <ms> ms to <from>, set the result to <tv> and returns a pointer <tv>
|
||||||
|
*/
|
||||||
|
#define tv_ms_add _tv_ms_add
|
||||||
|
REGPRM3 struct timeval *_tv_ms_add(struct timeval *tv, const struct timeval *from, int ms);
|
||||||
|
REGPRM3 static inline struct timeval *__tv_ms_add(struct timeval *tv, const struct timeval *from, int ms)
|
||||||
|
{
|
||||||
|
tv->tv_usec = from->tv_usec + (ms % 1000) * 1000;
|
||||||
|
tv->tv_sec = from->tv_sec + (ms / 1000);
|
||||||
|
while (tv->tv_usec >= 1000000) {
|
||||||
|
tv->tv_usec -= 1000000;
|
||||||
|
tv->tv_sec++;
|
||||||
|
}
|
||||||
|
return tv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* compares <tv1> and <tv2> : returns 1 if <tv1> is before <tv2>, otherwise 0.
|
* compares <tv1> and <tv2> : returns 1 if <tv1> is before <tv2>, otherwise 0.
|
||||||
* This should be very fast because it's used in schedulers.
|
* This should be very fast because it's used in schedulers.
|
||||||
|
@ -117,7 +117,7 @@ int appsession_task_init(void)
|
|||||||
t->qlist.p = NULL;
|
t->qlist.p = NULL;
|
||||||
t->state = TASK_IDLE;
|
t->state = TASK_IDLE;
|
||||||
t->context = NULL;
|
t->context = NULL;
|
||||||
tv_delayfrom(&t->expire, &now, TBLCHKINT);
|
tv_ms_add(&t->expire, &now, TBLCHKINT);
|
||||||
task_queue(t);
|
task_queue(t);
|
||||||
t->process = appsession_refresh;
|
t->process = appsession_refresh;
|
||||||
initialized ++;
|
initialized ++;
|
||||||
@ -143,7 +143,7 @@ int appsession_refresh(struct task *t)
|
|||||||
for (element = list_head(&htbl->table[i]);
|
for (element = list_head(&htbl->table[i]);
|
||||||
element != NULL; element = list_next(element)) {
|
element != NULL; element = list_next(element)) {
|
||||||
asession = (appsess *)list_data(element);
|
asession = (appsess *)list_data(element);
|
||||||
if (tv_cmp2_ms(&asession->expire, &now) <= 0) {
|
if (tv_ms_le2(&asession->expire, &now)) {
|
||||||
if ((global.mode & MODE_DEBUG) &&
|
if ((global.mode & MODE_DEBUG) &&
|
||||||
(!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))) {
|
(!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))) {
|
||||||
int len;
|
int len;
|
||||||
@ -165,7 +165,7 @@ int appsession_refresh(struct task *t)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
element = last;
|
element = last;
|
||||||
}/* end if (tv_cmp2_ms(&asession->expire, &now) <= 0) */
|
}/* end if (tv_ms_le2(&asession->expire, &now)) */
|
||||||
else
|
else
|
||||||
last = element;
|
last = element;
|
||||||
}/* end for (element = list_head(&htbl->table[i]); element != NULL; element = list_next(element)) */
|
}/* end for (element = list_head(&htbl->table[i]); element != NULL; element = list_next(element)) */
|
||||||
@ -173,7 +173,7 @@ int appsession_refresh(struct task *t)
|
|||||||
}
|
}
|
||||||
p = p->next;
|
p = p->next;
|
||||||
}
|
}
|
||||||
tv_delayfrom(&t->expire, &now, TBLCHKINT); /* check expiration every 5 seconds */
|
tv_ms_add(&t->expire, &now, TBLCHKINT); /* check expiration every 5 seconds */
|
||||||
return TBLCHKINT;
|
return TBLCHKINT;
|
||||||
} /* end appsession_refresh */
|
} /* end appsession_refresh */
|
||||||
|
|
||||||
|
@ -542,7 +542,7 @@ int connect_server(struct session *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (s->be->contimeout)
|
if (s->be->contimeout)
|
||||||
tv_delayfrom(&s->req->cex, &now, s->be->contimeout);
|
tv_ms_add(&s->req->cex, &now, s->be->contimeout);
|
||||||
else
|
else
|
||||||
tv_eternity(&s->req->cex);
|
tv_eternity(&s->req->cex);
|
||||||
return SN_ERR_NONE; /* connection is OK */
|
return SN_ERR_NONE; /* connection is OK */
|
||||||
@ -672,7 +672,7 @@ int srv_redispatch_connect(struct session *t)
|
|||||||
case SRV_STATUS_QUEUED:
|
case SRV_STATUS_QUEUED:
|
||||||
/* FIXME-20060503 : we should use the queue timeout instead */
|
/* FIXME-20060503 : we should use the queue timeout instead */
|
||||||
if (t->be->contimeout)
|
if (t->be->contimeout)
|
||||||
tv_delayfrom(&t->req->cex, &now, t->be->contimeout);
|
tv_ms_add(&t->req->cex, &now, t->be->contimeout);
|
||||||
else
|
else
|
||||||
tv_eternity(&t->req->cex);
|
tv_eternity(&t->req->cex);
|
||||||
t->srv_state = SV_STIDLE;
|
t->srv_state = SV_STIDLE;
|
||||||
|
@ -2469,7 +2469,7 @@ int readcfgfile(const char *file)
|
|||||||
t->context = newsrv;
|
t->context = newsrv;
|
||||||
|
|
||||||
/* check this every ms */
|
/* check this every ms */
|
||||||
tv_delayfrom(&t->expire, &now,
|
tv_ms_add(&t->expire, &now,
|
||||||
newsrv->inter + mininter * srvpos / nbchk);
|
newsrv->inter + mininter * srvpos / nbchk);
|
||||||
task_queue(t);
|
task_queue(t);
|
||||||
//task_wakeup(&rq, t);
|
//task_wakeup(&rq, t);
|
||||||
|
34
src/checks.c
34
src/checks.c
@ -258,19 +258,19 @@ int process_chk(struct task *t)
|
|||||||
fd = s->curfd;
|
fd = s->curfd;
|
||||||
if (fd < 0) { /* no check currently running */
|
if (fd < 0) { /* no check currently running */
|
||||||
//fprintf(stderr, "process_chk: 2\n");
|
//fprintf(stderr, "process_chk: 2\n");
|
||||||
if (tv_cmp2_ms(&t->expire, &now) > 0) { /* not good time yet */
|
if (!tv_ms_le2(&t->expire, &now)) { /* not good time yet */
|
||||||
task_queue(t); /* restore t to its place in the task list */
|
task_queue(t); /* restore t to its place in the task list */
|
||||||
return tv_remain2(&now, &t->expire);
|
return tv_ms_remain2(&now, &t->expire);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we don't send any health-checks when the proxy is stopped or when
|
/* we don't send any health-checks when the proxy is stopped or when
|
||||||
* the server should not be checked.
|
* the server should not be checked.
|
||||||
*/
|
*/
|
||||||
if (!(s->state & SRV_CHECKED) || s->proxy->state == PR_STSTOPPED) {
|
if (!(s->state & SRV_CHECKED) || s->proxy->state == PR_STSTOPPED) {
|
||||||
while (tv_cmp2_ms(&t->expire, &now) <= 0)
|
while (tv_ms_le2(&t->expire, &now))
|
||||||
tv_delayfrom(&t->expire, &t->expire, s->inter);
|
tv_ms_add(&t->expire, &t->expire, s->inter);
|
||||||
task_queue(t); /* restore t to its place in the task list */
|
task_queue(t); /* restore t to its place in the task list */
|
||||||
return tv_remain2(&now, &t->expire);
|
return tv_ms_remain2(&now, &t->expire);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we'll initiate a new check */
|
/* we'll initiate a new check */
|
||||||
@ -375,9 +375,9 @@ int process_chk(struct task *t)
|
|||||||
assert (!EV_FD_ISSET(fd, DIR_RD));
|
assert (!EV_FD_ISSET(fd, DIR_RD));
|
||||||
#endif
|
#endif
|
||||||
/* FIXME: we allow up to <inter> for a connection to establish, but we should use another parameter */
|
/* FIXME: we allow up to <inter> for a connection to establish, but we should use another parameter */
|
||||||
tv_delayfrom(&t->expire, &now, s->inter);
|
tv_ms_add(&t->expire, &now, s->inter);
|
||||||
task_queue(t); /* restore t to its place in the task list */
|
task_queue(t); /* restore t to its place in the task list */
|
||||||
return tv_remain(&now, &t->expire);
|
return tv_ms_remain(&now, &t->expire);
|
||||||
}
|
}
|
||||||
else if (errno != EALREADY && errno != EISCONN && errno != EAGAIN) {
|
else if (errno != EALREADY && errno != EISCONN && errno != EAGAIN) {
|
||||||
s->result = -1; /* a real error */
|
s->result = -1; /* a real error */
|
||||||
@ -389,8 +389,8 @@ int process_chk(struct task *t)
|
|||||||
|
|
||||||
if (!s->result) { /* nothing done */
|
if (!s->result) { /* nothing done */
|
||||||
//fprintf(stderr, "process_chk: 6\n");
|
//fprintf(stderr, "process_chk: 6\n");
|
||||||
while (tv_cmp2_ms(&t->expire, &now) <= 0)
|
while (tv_ms_le2(&t->expire, &now))
|
||||||
tv_delayfrom(&t->expire, &t->expire, s->inter);
|
tv_ms_add(&t->expire, &t->expire, s->inter);
|
||||||
goto new_chk; /* may be we should initialize a new check */
|
goto new_chk; /* may be we should initialize a new check */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,8 +404,8 @@ int process_chk(struct task *t)
|
|||||||
|
|
||||||
//fprintf(stderr, "process_chk: 7\n");
|
//fprintf(stderr, "process_chk: 7\n");
|
||||||
/* FIXME: we allow up to <inter> for a connection to establish, but we should use another parameter */
|
/* FIXME: we allow up to <inter> for a connection to establish, but we should use another parameter */
|
||||||
while (tv_cmp2_ms(&t->expire, &now) <= 0)
|
while (tv_ms_le2(&t->expire, &now))
|
||||||
tv_delayfrom(&t->expire, &t->expire, s->inter);
|
tv_ms_add(&t->expire, &t->expire, s->inter);
|
||||||
goto new_chk;
|
goto new_chk;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -455,11 +455,11 @@ int process_chk(struct task *t)
|
|||||||
}
|
}
|
||||||
s->curfd = -1; /* no check running anymore */
|
s->curfd = -1; /* no check running anymore */
|
||||||
fd_delete(fd);
|
fd_delete(fd);
|
||||||
while (tv_cmp2_ms(&t->expire, &now) <= 0)
|
while (tv_ms_le2(&t->expire, &now))
|
||||||
tv_delayfrom(&t->expire, &t->expire, s->inter);
|
tv_ms_add(&t->expire, &t->expire, s->inter);
|
||||||
goto new_chk;
|
goto new_chk;
|
||||||
}
|
}
|
||||||
else if (s->result < 0 || tv_cmp2_ms(&t->expire, &now) <= 0) {
|
else if (s->result < 0 || tv_ms_le2(&t->expire, &now)) {
|
||||||
//fprintf(stderr, "process_chk: 10\n");
|
//fprintf(stderr, "process_chk: 10\n");
|
||||||
/* failure or timeout detected */
|
/* failure or timeout detected */
|
||||||
if (s->health > s->rise) {
|
if (s->health > s->rise) {
|
||||||
@ -470,8 +470,8 @@ int process_chk(struct task *t)
|
|||||||
set_server_down(s);
|
set_server_down(s);
|
||||||
s->curfd = -1;
|
s->curfd = -1;
|
||||||
fd_delete(fd);
|
fd_delete(fd);
|
||||||
while (tv_cmp2_ms(&t->expire, &now) <= 0)
|
while (tv_ms_le2(&t->expire, &now))
|
||||||
tv_delayfrom(&t->expire, &t->expire, s->inter);
|
tv_ms_add(&t->expire, &t->expire, s->inter);
|
||||||
goto new_chk;
|
goto new_chk;
|
||||||
}
|
}
|
||||||
/* if result is 0 and there's no timeout, we have to wait again */
|
/* if result is 0 and there's no timeout, we have to wait again */
|
||||||
@ -479,7 +479,7 @@ int process_chk(struct task *t)
|
|||||||
//fprintf(stderr, "process_chk: 11\n");
|
//fprintf(stderr, "process_chk: 11\n");
|
||||||
s->result = 0;
|
s->result = 0;
|
||||||
task_queue(t); /* restore t to its place in the task list */
|
task_queue(t); /* restore t to its place in the task list */
|
||||||
return tv_remain2(&now, &t->expire);
|
return tv_ms_remain2(&now, &t->expire);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -412,9 +412,9 @@ int event_accept(int fd) {
|
|||||||
|
|
||||||
if (s->fe->clitimeout) {
|
if (s->fe->clitimeout) {
|
||||||
if (EV_FD_ISSET(cfd, DIR_RD))
|
if (EV_FD_ISSET(cfd, DIR_RD))
|
||||||
tv_delayfrom(&s->req->rex, &now, s->fe->clitimeout);
|
tv_ms_add(&s->req->rex, &now, s->fe->clitimeout);
|
||||||
if (EV_FD_ISSET(cfd, DIR_WR))
|
if (EV_FD_ISSET(cfd, DIR_WR))
|
||||||
tv_delayfrom(&s->rep->wex, &now, s->fe->clitimeout);
|
tv_ms_add(&s->rep->wex, &now, s->fe->clitimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
tv_min(&t->expire, &s->req->rex, &s->rep->wex);
|
tv_min(&t->expire, &s->req->rex, &s->rep->wex);
|
||||||
|
@ -281,7 +281,7 @@ void dump(int sig)
|
|||||||
qfprintf(stderr,"[dump] wq: task %p, still %ld ms, "
|
qfprintf(stderr,"[dump] wq: task %p, still %ld ms, "
|
||||||
"cli=%d, srv=%d, cr=%d, cw=%d, sr=%d, sw=%d, "
|
"cli=%d, srv=%d, cr=%d, cw=%d, sr=%d, sw=%d, "
|
||||||
"req=%d, rep=%d, clifd=%d\n",
|
"req=%d, rep=%d, clifd=%d\n",
|
||||||
s, tv_remain(&now, &t->expire),
|
s, tv_ms_remain(&now, &t->expire),
|
||||||
s->cli_state,
|
s->cli_state,
|
||||||
s->srv_state,
|
s->srv_state,
|
||||||
EV_FD_ISSET(s->cli_fd, DIR_RD),
|
EV_FD_ISSET(s->cli_fd, DIR_RD),
|
||||||
|
104
src/proto_http.c
104
src/proto_http.c
@ -441,7 +441,7 @@ void client_retnclose(struct session *s, const struct chunk *msg)
|
|||||||
EV_FD_SET(s->cli_fd, DIR_WR);
|
EV_FD_SET(s->cli_fd, DIR_WR);
|
||||||
tv_eternity(&s->req->rex);
|
tv_eternity(&s->req->rex);
|
||||||
if (s->fe->clitimeout)
|
if (s->fe->clitimeout)
|
||||||
tv_delayfrom(&s->rep->wex, &now, s->fe->clitimeout);
|
tv_ms_add(&s->rep->wex, &now, s->fe->clitimeout);
|
||||||
else
|
else
|
||||||
tv_eternity(&s->rep->wex);
|
tv_eternity(&s->rep->wex);
|
||||||
s->cli_state = CL_STSHUTR;
|
s->cli_state = CL_STSHUTR;
|
||||||
@ -561,11 +561,11 @@ int process_session(struct task *t)
|
|||||||
/* DEBUG code : this should never ever happen, otherwise it indicates
|
/* DEBUG code : this should never ever happen, otherwise it indicates
|
||||||
* that a task still has something to do and will provoke a quick loop.
|
* that a task still has something to do and will provoke a quick loop.
|
||||||
*/
|
*/
|
||||||
if (tv_remain2(&now, &t->expire) <= 0)
|
if (tv_ms_remain2(&now, &t->expire) <= 0)
|
||||||
exit(100);
|
exit(100);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return tv_remain2(&now, &t->expire); /* nothing more to do */
|
return tv_ms_remain2(&now, &t->expire); /* nothing more to do */
|
||||||
}
|
}
|
||||||
|
|
||||||
s->fe->feconn--;
|
s->fe->feconn--;
|
||||||
@ -582,7 +582,7 @@ int process_session(struct task *t)
|
|||||||
write(1, trash, len);
|
write(1, trash, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
s->logs.t_close = tv_diff(&s->logs.tv_accept, &now);
|
s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now);
|
||||||
if (s->req != NULL)
|
if (s->req != NULL)
|
||||||
s->logs.bytes_in = s->req->total;
|
s->logs.bytes_in = s->req->total;
|
||||||
if (s->rep != NULL)
|
if (s->rep != NULL)
|
||||||
@ -1526,7 +1526,7 @@ int process_cli(struct session *t)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 3: has the read timeout expired ? */
|
/* 3: has the read timeout expired ? */
|
||||||
else if (unlikely(tv_cmp2_le(&req->rex, &now))) {
|
else if (unlikely(tv_ms_le2(&req->rex, &now))) {
|
||||||
/* read timeout : give up with an error message. */
|
/* read timeout : give up with an error message. */
|
||||||
txn->status = 408;
|
txn->status = 408;
|
||||||
client_retnclose(t, error_message(t, HTTP_ERR_408));
|
client_retnclose(t, error_message(t, HTTP_ERR_408));
|
||||||
@ -1545,7 +1545,7 @@ int process_cli(struct session *t)
|
|||||||
* req->l == rlim-data
|
* req->l == rlim-data
|
||||||
*/
|
*/
|
||||||
if (t->fe->clitimeout)
|
if (t->fe->clitimeout)
|
||||||
tv_delayfrom(&req->rex, &now, t->fe->clitimeout);
|
tv_ms_add(&req->rex, &now, t->fe->clitimeout);
|
||||||
else
|
else
|
||||||
tv_eternity(&req->rex);
|
tv_eternity(&req->rex);
|
||||||
}
|
}
|
||||||
@ -1694,7 +1694,7 @@ int process_cli(struct session *t)
|
|||||||
/* no need to go further */
|
/* no need to go further */
|
||||||
txn->status = 403;
|
txn->status = 403;
|
||||||
/* let's log the request time */
|
/* let's log the request time */
|
||||||
t->logs.t_request = tv_diff(&t->logs.tv_accept, &now);
|
t->logs.t_request = tv_ms_elapsed(&t->logs.tv_accept, &now);
|
||||||
client_retnclose(t, error_message(t, HTTP_ERR_403));
|
client_retnclose(t, error_message(t, HTTP_ERR_403));
|
||||||
goto return_prx_cond;
|
goto return_prx_cond;
|
||||||
}
|
}
|
||||||
@ -1888,7 +1888,7 @@ int process_cli(struct session *t)
|
|||||||
t->cli_state = CL_STDATA;
|
t->cli_state = CL_STDATA;
|
||||||
req->rlim = req->data + BUFSIZE; /* no more rewrite needed */
|
req->rlim = req->data + BUFSIZE; /* no more rewrite needed */
|
||||||
|
|
||||||
t->logs.t_request = tv_diff(&t->logs.tv_accept, &now);
|
t->logs.t_request = tv_ms_elapsed(&t->logs.tv_accept, &now);
|
||||||
|
|
||||||
if (!t->fe->clitimeout ||
|
if (!t->fe->clitimeout ||
|
||||||
(t->srv_state < SV_STDATA && t->be->srvtimeout)) {
|
(t->srv_state < SV_STDATA && t->be->srvtimeout)) {
|
||||||
@ -1914,7 +1914,7 @@ int process_cli(struct session *t)
|
|||||||
/* flush the request so that we can drop the connection early
|
/* flush the request so that we can drop the connection early
|
||||||
* if the client closes first.
|
* if the client closes first.
|
||||||
*/
|
*/
|
||||||
tv_delayfrom(&req->cex, &now,
|
tv_ms_add(&req->cex, &now,
|
||||||
t->be->contimeout ? t->be->contimeout : 0);
|
t->be->contimeout ? t->be->contimeout : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1975,13 +1975,13 @@ int process_cli(struct session *t)
|
|||||||
* to shutw */
|
* to shutw */
|
||||||
EV_FD_SET(t->cli_fd, DIR_RD);
|
EV_FD_SET(t->cli_fd, DIR_RD);
|
||||||
if (t->fe->clitimeout)
|
if (t->fe->clitimeout)
|
||||||
tv_delayfrom(&req->rex, &now, t->fe->clitimeout);
|
tv_ms_add(&req->rex, &now, t->fe->clitimeout);
|
||||||
t->cli_state = CL_STSHUTW;
|
t->cli_state = CL_STSHUTW;
|
||||||
//fprintf(stderr,"%p:%s(%d), c=%d, s=%d\n", t, __FUNCTION__, __LINE__, t->cli_state, t->cli_state);
|
//fprintf(stderr,"%p:%s(%d), c=%d, s=%d\n", t, __FUNCTION__, __LINE__, t->cli_state, t->cli_state);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* read timeout */
|
/* read timeout */
|
||||||
else if (tv_cmp2_le(&req->rex, &now)) {
|
else if (tv_ms_le2(&req->rex, &now)) {
|
||||||
EV_FD_CLR(t->cli_fd, DIR_RD);
|
EV_FD_CLR(t->cli_fd, DIR_RD);
|
||||||
tv_eternity(&req->rex);
|
tv_eternity(&req->rex);
|
||||||
t->cli_state = CL_STSHUTR;
|
t->cli_state = CL_STSHUTR;
|
||||||
@ -1998,7 +1998,7 @@ int process_cli(struct session *t)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* write timeout */
|
/* write timeout */
|
||||||
else if (tv_cmp2_le(&rep->wex, &now)) {
|
else if (tv_ms_le2(&rep->wex, &now)) {
|
||||||
EV_FD_CLR(t->cli_fd, DIR_WR);
|
EV_FD_CLR(t->cli_fd, DIR_WR);
|
||||||
tv_eternity(&rep->wex);
|
tv_eternity(&rep->wex);
|
||||||
shutdown(t->cli_fd, SHUT_WR);
|
shutdown(t->cli_fd, SHUT_WR);
|
||||||
@ -2006,7 +2006,7 @@ int process_cli(struct session *t)
|
|||||||
* to shutw */
|
* to shutw */
|
||||||
EV_FD_SET(t->cli_fd, DIR_RD);
|
EV_FD_SET(t->cli_fd, DIR_RD);
|
||||||
if (t->fe->clitimeout)
|
if (t->fe->clitimeout)
|
||||||
tv_delayfrom(&req->rex, &now, t->fe->clitimeout);
|
tv_ms_add(&req->rex, &now, t->fe->clitimeout);
|
||||||
|
|
||||||
t->cli_state = CL_STSHUTW;
|
t->cli_state = CL_STSHUTW;
|
||||||
if (!(t->flags & SN_ERR_MASK))
|
if (!(t->flags & SN_ERR_MASK))
|
||||||
@ -2040,7 +2040,7 @@ int process_cli(struct session *t)
|
|||||||
*/
|
*/
|
||||||
tv_eternity(&req->rex);
|
tv_eternity(&req->rex);
|
||||||
else
|
else
|
||||||
tv_delayfrom(&req->rex, &now, t->fe->clitimeout);
|
tv_ms_add(&req->rex, &now, t->fe->clitimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2055,7 +2055,7 @@ int process_cli(struct session *t)
|
|||||||
if (EV_FD_COND_S(t->cli_fd, DIR_WR)) {
|
if (EV_FD_COND_S(t->cli_fd, DIR_WR)) {
|
||||||
/* restart writing */
|
/* restart writing */
|
||||||
if (t->fe->clitimeout) {
|
if (t->fe->clitimeout) {
|
||||||
tv_delayfrom(&rep->wex, &now, t->fe->clitimeout);
|
tv_ms_add(&rep->wex, &now, t->fe->clitimeout);
|
||||||
/* FIXME: to prevent the client from expiring read timeouts during writes,
|
/* FIXME: to prevent the client from expiring read timeouts during writes,
|
||||||
* we refresh it. */
|
* we refresh it. */
|
||||||
req->rex = rep->wex;
|
req->rex = rep->wex;
|
||||||
@ -2090,7 +2090,7 @@ int process_cli(struct session *t)
|
|||||||
t->cli_state = CL_STCLOSE;
|
t->cli_state = CL_STCLOSE;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (tv_cmp2_le(&rep->wex, &now)) {
|
else if (tv_ms_le2(&rep->wex, &now)) {
|
||||||
tv_eternity(&rep->wex);
|
tv_eternity(&rep->wex);
|
||||||
fd_delete(t->cli_fd);
|
fd_delete(t->cli_fd);
|
||||||
t->cli_state = CL_STCLOSE;
|
t->cli_state = CL_STCLOSE;
|
||||||
@ -2128,7 +2128,7 @@ int process_cli(struct session *t)
|
|||||||
if (EV_FD_COND_S(t->cli_fd, DIR_WR)) {
|
if (EV_FD_COND_S(t->cli_fd, DIR_WR)) {
|
||||||
/* restart writing */
|
/* restart writing */
|
||||||
if (t->fe->clitimeout) {
|
if (t->fe->clitimeout) {
|
||||||
tv_delayfrom(&rep->wex, &now, t->fe->clitimeout);
|
tv_ms_add(&rep->wex, &now, t->fe->clitimeout);
|
||||||
/* FIXME: to prevent the client from expiring read timeouts during writes,
|
/* FIXME: to prevent the client from expiring read timeouts during writes,
|
||||||
* we refresh it. */
|
* we refresh it. */
|
||||||
req->rex = rep->wex;
|
req->rex = rep->wex;
|
||||||
@ -2162,7 +2162,7 @@ int process_cli(struct session *t)
|
|||||||
t->cli_state = CL_STCLOSE;
|
t->cli_state = CL_STCLOSE;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (tv_cmp2_le(&req->rex, &now)) {
|
else if (tv_ms_le2(&req->rex, &now)) {
|
||||||
tv_eternity(&req->rex);
|
tv_eternity(&req->rex);
|
||||||
fd_delete(t->cli_fd);
|
fd_delete(t->cli_fd);
|
||||||
t->cli_state = CL_STCLOSE;
|
t->cli_state = CL_STCLOSE;
|
||||||
@ -2194,7 +2194,7 @@ int process_cli(struct session *t)
|
|||||||
/* there's still some space in the buffer */
|
/* there's still some space in the buffer */
|
||||||
if (EV_FD_COND_S(t->cli_fd, DIR_RD)) {
|
if (EV_FD_COND_S(t->cli_fd, DIR_RD)) {
|
||||||
if (t->fe->clitimeout)
|
if (t->fe->clitimeout)
|
||||||
tv_delayfrom(&req->rex, &now, t->fe->clitimeout);
|
tv_ms_add(&req->rex, &now, t->fe->clitimeout);
|
||||||
else
|
else
|
||||||
tv_eternity(&req->rex);
|
tv_eternity(&req->rex);
|
||||||
//fprintf(stderr,"%p:%s(%d), c=%d, s=%d\n", t, __FUNCTION__, __LINE__, t->cli_state, t->cli_state);
|
//fprintf(stderr,"%p:%s(%d), c=%d, s=%d\n", t, __FUNCTION__, __LINE__, t->cli_state, t->cli_state);
|
||||||
@ -2242,7 +2242,7 @@ int process_srv(struct session *t)
|
|||||||
(t->req->l == 0 || t->be->options & PR_O_ABRT_CLOSE))) { /* give up */
|
(t->req->l == 0 || t->be->options & PR_O_ABRT_CLOSE))) { /* give up */
|
||||||
tv_eternity(&req->cex);
|
tv_eternity(&req->cex);
|
||||||
if (t->pend_pos)
|
if (t->pend_pos)
|
||||||
t->logs.t_queue = tv_diff(&t->logs.tv_accept, &now);
|
t->logs.t_queue = tv_ms_elapsed(&t->logs.tv_accept, &now);
|
||||||
/* note that this must not return any error because it would be able to
|
/* note that this must not return any error because it would be able to
|
||||||
* overwrite the client_retnclose() output.
|
* overwrite the client_retnclose() output.
|
||||||
*/
|
*/
|
||||||
@ -2259,7 +2259,7 @@ int process_srv(struct session *t)
|
|||||||
* already set the connect expiration date to the right
|
* already set the connect expiration date to the right
|
||||||
* timeout. We just have to check that it has not expired.
|
* timeout. We just have to check that it has not expired.
|
||||||
*/
|
*/
|
||||||
if (!tv_cmp2_le(&req->cex, &now))
|
if (!tv_ms_le2(&req->cex, &now))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* We will set the queue timer to the time spent, just for
|
/* We will set the queue timer to the time spent, just for
|
||||||
@ -2269,7 +2269,7 @@ int process_srv(struct session *t)
|
|||||||
* the tarpitted connections by filtering on the 'PT' status flags.
|
* the tarpitted connections by filtering on the 'PT' status flags.
|
||||||
*/
|
*/
|
||||||
tv_eternity(&req->cex);
|
tv_eternity(&req->cex);
|
||||||
t->logs.t_queue = tv_diff(&t->logs.tv_accept, &now);
|
t->logs.t_queue = tv_ms_elapsed(&t->logs.tv_accept, &now);
|
||||||
srv_close_with_err(t, SN_ERR_PRXCOND, SN_FINST_T,
|
srv_close_with_err(t, SN_ERR_PRXCOND, SN_FINST_T,
|
||||||
500, error_message(t, HTTP_ERR_500));
|
500, error_message(t, HTTP_ERR_500));
|
||||||
return 1;
|
return 1;
|
||||||
@ -2281,12 +2281,12 @@ int process_srv(struct session *t)
|
|||||||
* to any other session to release it and wake us up again.
|
* to any other session to release it and wake us up again.
|
||||||
*/
|
*/
|
||||||
if (t->pend_pos) {
|
if (t->pend_pos) {
|
||||||
if (!tv_cmp2_le(&req->cex, &now))
|
if (!tv_ms_le2(&req->cex, &now))
|
||||||
return 0;
|
return 0;
|
||||||
else {
|
else {
|
||||||
/* we've been waiting too long here */
|
/* we've been waiting too long here */
|
||||||
tv_eternity(&req->cex);
|
tv_eternity(&req->cex);
|
||||||
t->logs.t_queue = tv_diff(&t->logs.tv_accept, &now);
|
t->logs.t_queue = tv_ms_elapsed(&t->logs.tv_accept, &now);
|
||||||
srv_close_with_err(t, SN_ERR_SRVTO, SN_FINST_Q,
|
srv_close_with_err(t, SN_ERR_SRVTO, SN_FINST_Q,
|
||||||
503, error_message(t, HTTP_ERR_503));
|
503, error_message(t, HTTP_ERR_503));
|
||||||
if (t->srv)
|
if (t->srv)
|
||||||
@ -2305,7 +2305,7 @@ int process_srv(struct session *t)
|
|||||||
* number of retries.
|
* number of retries.
|
||||||
*/
|
*/
|
||||||
if (srv_retryable_connect(t)) {
|
if (srv_retryable_connect(t)) {
|
||||||
t->logs.t_queue = tv_diff(&t->logs.tv_accept, &now);
|
t->logs.t_queue = tv_ms_elapsed(&t->logs.tv_accept, &now);
|
||||||
return t->srv_state != SV_STIDLE;
|
return t->srv_state != SV_STIDLE;
|
||||||
}
|
}
|
||||||
} while (1);
|
} while (1);
|
||||||
@ -2326,7 +2326,7 @@ int process_srv(struct session *t)
|
|||||||
srv_close_with_err(t, SN_ERR_CLICL, SN_FINST_C, 0, NULL);
|
srv_close_with_err(t, SN_ERR_CLICL, SN_FINST_C, 0, NULL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!(req->flags & BF_WRITE_STATUS) && !tv_cmp2_le(&req->cex, &now)) {
|
if (!(req->flags & BF_WRITE_STATUS) && !tv_ms_le2(&req->cex, &now)) {
|
||||||
//fprintf(stderr,"1: c=%d, s=%d, now=%d.%06d, exp=%d.%06d\n", c, s, now.tv_sec, now.tv_usec, req->cex.tv_sec, req->cex.tv_usec);
|
//fprintf(stderr,"1: c=%d, s=%d, now=%d.%06d, exp=%d.%06d\n", c, s, now.tv_sec, now.tv_usec, req->cex.tv_sec, req->cex.tv_usec);
|
||||||
return 0; /* nothing changed */
|
return 0; /* nothing changed */
|
||||||
}
|
}
|
||||||
@ -2375,7 +2375,7 @@ int process_srv(struct session *t)
|
|||||||
* the SV_STIDLE state.
|
* the SV_STIDLE state.
|
||||||
*/
|
*/
|
||||||
if (srv_retryable_connect(t)) {
|
if (srv_retryable_connect(t)) {
|
||||||
t->logs.t_queue = tv_diff(&t->logs.tv_accept, &now);
|
t->logs.t_queue = tv_ms_elapsed(&t->logs.tv_accept, &now);
|
||||||
return t->srv_state != SV_STCONN;
|
return t->srv_state != SV_STCONN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2385,7 +2385,7 @@ int process_srv(struct session *t)
|
|||||||
} while (1);
|
} while (1);
|
||||||
}
|
}
|
||||||
else { /* no error or write 0 */
|
else { /* no error or write 0 */
|
||||||
t->logs.t_connect = tv_diff(&t->logs.tv_accept, &now);
|
t->logs.t_connect = tv_ms_elapsed(&t->logs.tv_accept, &now);
|
||||||
|
|
||||||
//fprintf(stderr,"3: c=%d, s=%d\n", c, s);
|
//fprintf(stderr,"3: c=%d, s=%d\n", c, s);
|
||||||
if (req->l == 0) /* nothing to write */ {
|
if (req->l == 0) /* nothing to write */ {
|
||||||
@ -2394,7 +2394,7 @@ int process_srv(struct session *t)
|
|||||||
} else /* need the right to write */ {
|
} else /* need the right to write */ {
|
||||||
EV_FD_SET(t->srv_fd, DIR_WR);
|
EV_FD_SET(t->srv_fd, DIR_WR);
|
||||||
if (t->be->srvtimeout) {
|
if (t->be->srvtimeout) {
|
||||||
tv_delayfrom(&req->wex, &now, t->be->srvtimeout);
|
tv_ms_add(&req->wex, &now, t->be->srvtimeout);
|
||||||
/* FIXME: to prevent the server from expiring read timeouts during writes,
|
/* FIXME: to prevent the server from expiring read timeouts during writes,
|
||||||
* we refresh it. */
|
* we refresh it. */
|
||||||
rep->rex = req->wex;
|
rep->rex = req->wex;
|
||||||
@ -2406,7 +2406,7 @@ int process_srv(struct session *t)
|
|||||||
if (t->be->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */
|
if (t->be->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */
|
||||||
EV_FD_SET(t->srv_fd, DIR_RD);
|
EV_FD_SET(t->srv_fd, DIR_RD);
|
||||||
if (t->be->srvtimeout)
|
if (t->be->srvtimeout)
|
||||||
tv_delayfrom(&rep->rex, &now, t->be->srvtimeout);
|
tv_ms_add(&rep->rex, &now, t->be->srvtimeout);
|
||||||
else
|
else
|
||||||
tv_eternity(&rep->rex);
|
tv_eternity(&rep->rex);
|
||||||
|
|
||||||
@ -2495,7 +2495,7 @@ int process_srv(struct session *t)
|
|||||||
* rep->l == rlim-data
|
* rep->l == rlim-data
|
||||||
*/
|
*/
|
||||||
if (t->be->srvtimeout)
|
if (t->be->srvtimeout)
|
||||||
tv_delayfrom(&rep->rex, &now, t->be->srvtimeout);
|
tv_ms_add(&rep->rex, &now, t->be->srvtimeout);
|
||||||
else
|
else
|
||||||
tv_eternity(&rep->rex);
|
tv_eternity(&rep->rex);
|
||||||
}
|
}
|
||||||
@ -2561,7 +2561,7 @@ int process_srv(struct session *t)
|
|||||||
/* read timeout : return a 504 to the client.
|
/* read timeout : return a 504 to the client.
|
||||||
*/
|
*/
|
||||||
else if (unlikely(EV_FD_ISSET(t->srv_fd, DIR_RD) &&
|
else if (unlikely(EV_FD_ISSET(t->srv_fd, DIR_RD) &&
|
||||||
tv_cmp2_le(&rep->rex, &now))) {
|
tv_ms_le2(&rep->rex, &now))) {
|
||||||
tv_eternity(&rep->rex);
|
tv_eternity(&rep->rex);
|
||||||
tv_eternity(&req->wex);
|
tv_eternity(&req->wex);
|
||||||
fd_delete(t->srv_fd);
|
fd_delete(t->srv_fd);
|
||||||
@ -2602,7 +2602,7 @@ int process_srv(struct session *t)
|
|||||||
* alive when switching to shutw */
|
* alive when switching to shutw */
|
||||||
EV_FD_SET(t->srv_fd, DIR_RD);
|
EV_FD_SET(t->srv_fd, DIR_RD);
|
||||||
if (t->be->srvtimeout)
|
if (t->be->srvtimeout)
|
||||||
tv_delayfrom(&rep->rex, &now, t->be->srvtimeout);
|
tv_ms_add(&rep->rex, &now, t->be->srvtimeout);
|
||||||
|
|
||||||
shutdown(t->srv_fd, SHUT_WR);
|
shutdown(t->srv_fd, SHUT_WR);
|
||||||
t->srv_state = SV_STSHUTW;
|
t->srv_state = SV_STSHUTW;
|
||||||
@ -2615,7 +2615,7 @@ int process_srv(struct session *t)
|
|||||||
* some work to do on the headers.
|
* some work to do on the headers.
|
||||||
*/
|
*/
|
||||||
else if (unlikely(EV_FD_ISSET(t->srv_fd, DIR_WR) &&
|
else if (unlikely(EV_FD_ISSET(t->srv_fd, DIR_WR) &&
|
||||||
tv_cmp2_le(&req->wex, &now))) {
|
tv_ms_le2(&req->wex, &now))) {
|
||||||
EV_FD_CLR(t->srv_fd, DIR_WR);
|
EV_FD_CLR(t->srv_fd, DIR_WR);
|
||||||
tv_eternity(&req->wex);
|
tv_eternity(&req->wex);
|
||||||
shutdown(t->srv_fd, SHUT_WR);
|
shutdown(t->srv_fd, SHUT_WR);
|
||||||
@ -2623,7 +2623,7 @@ int process_srv(struct session *t)
|
|||||||
* when switching to shutw */
|
* when switching to shutw */
|
||||||
EV_FD_SET(t->srv_fd, DIR_RD);
|
EV_FD_SET(t->srv_fd, DIR_RD);
|
||||||
if (t->be->srvtimeout)
|
if (t->be->srvtimeout)
|
||||||
tv_delayfrom(&rep->rex, &now, t->be->srvtimeout);
|
tv_ms_add(&rep->rex, &now, t->be->srvtimeout);
|
||||||
|
|
||||||
t->srv_state = SV_STSHUTW;
|
t->srv_state = SV_STSHUTW;
|
||||||
if (!(t->flags & SN_ERR_MASK))
|
if (!(t->flags & SN_ERR_MASK))
|
||||||
@ -2645,7 +2645,7 @@ int process_srv(struct session *t)
|
|||||||
if (EV_FD_COND_S(t->srv_fd, DIR_WR)) {
|
if (EV_FD_COND_S(t->srv_fd, DIR_WR)) {
|
||||||
/* restart writing */
|
/* restart writing */
|
||||||
if (t->be->srvtimeout) {
|
if (t->be->srvtimeout) {
|
||||||
tv_delayfrom(&req->wex, &now, t->be->srvtimeout);
|
tv_ms_add(&req->wex, &now, t->be->srvtimeout);
|
||||||
/* FIXME: to prevent the server from expiring read timeouts during writes,
|
/* FIXME: to prevent the server from expiring read timeouts during writes,
|
||||||
* we refresh it. */
|
* we refresh it. */
|
||||||
rep->rex = req->wex;
|
rep->rex = req->wex;
|
||||||
@ -2925,7 +2925,7 @@ int process_srv(struct session *t)
|
|||||||
|
|
||||||
t->srv_state = SV_STDATA;
|
t->srv_state = SV_STDATA;
|
||||||
rep->rlim = rep->data + BUFSIZE; /* no more rewrite needed */
|
rep->rlim = rep->data + BUFSIZE; /* no more rewrite needed */
|
||||||
t->logs.t_data = tv_diff(&t->logs.tv_accept, &now);
|
t->logs.t_data = tv_ms_elapsed(&t->logs.tv_accept, &now);
|
||||||
|
|
||||||
/* client connection already closed or option 'forceclose' required :
|
/* client connection already closed or option 'forceclose' required :
|
||||||
* we close the server's outgoing connection right now.
|
* we close the server's outgoing connection right now.
|
||||||
@ -2939,7 +2939,7 @@ int process_srv(struct session *t)
|
|||||||
* to shutw */
|
* to shutw */
|
||||||
EV_FD_SET(t->srv_fd, DIR_RD);
|
EV_FD_SET(t->srv_fd, DIR_RD);
|
||||||
if (t->be->srvtimeout)
|
if (t->be->srvtimeout)
|
||||||
tv_delayfrom(&rep->rex, &now, t->be->srvtimeout);
|
tv_ms_add(&rep->rex, &now, t->be->srvtimeout);
|
||||||
|
|
||||||
shutdown(t->srv_fd, SHUT_WR);
|
shutdown(t->srv_fd, SHUT_WR);
|
||||||
t->srv_state = SV_STSHUTW;
|
t->srv_state = SV_STSHUTW;
|
||||||
@ -3009,13 +3009,13 @@ int process_srv(struct session *t)
|
|||||||
* to shutw */
|
* to shutw */
|
||||||
EV_FD_SET(t->srv_fd, DIR_RD);
|
EV_FD_SET(t->srv_fd, DIR_RD);
|
||||||
if (t->be->srvtimeout)
|
if (t->be->srvtimeout)
|
||||||
tv_delayfrom(&rep->rex, &now, t->be->srvtimeout);
|
tv_ms_add(&rep->rex, &now, t->be->srvtimeout);
|
||||||
|
|
||||||
t->srv_state = SV_STSHUTW;
|
t->srv_state = SV_STSHUTW;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* read timeout */
|
/* read timeout */
|
||||||
else if (tv_cmp2_le(&rep->rex, &now)) {
|
else if (tv_ms_le2(&rep->rex, &now)) {
|
||||||
EV_FD_CLR(t->srv_fd, DIR_RD);
|
EV_FD_CLR(t->srv_fd, DIR_RD);
|
||||||
tv_eternity(&rep->rex);
|
tv_eternity(&rep->rex);
|
||||||
t->srv_state = SV_STSHUTR;
|
t->srv_state = SV_STSHUTR;
|
||||||
@ -3026,7 +3026,7 @@ int process_srv(struct session *t)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* write timeout */
|
/* write timeout */
|
||||||
else if (tv_cmp2_le(&req->wex, &now)) {
|
else if (tv_ms_le2(&req->wex, &now)) {
|
||||||
EV_FD_CLR(t->srv_fd, DIR_WR);
|
EV_FD_CLR(t->srv_fd, DIR_WR);
|
||||||
tv_eternity(&req->wex);
|
tv_eternity(&req->wex);
|
||||||
shutdown(t->srv_fd, SHUT_WR);
|
shutdown(t->srv_fd, SHUT_WR);
|
||||||
@ -3034,7 +3034,7 @@ int process_srv(struct session *t)
|
|||||||
* to shutw */
|
* to shutw */
|
||||||
EV_FD_SET(t->srv_fd, DIR_RD);
|
EV_FD_SET(t->srv_fd, DIR_RD);
|
||||||
if (t->be->srvtimeout)
|
if (t->be->srvtimeout)
|
||||||
tv_delayfrom(&rep->rex, &now, t->be->srvtimeout);
|
tv_ms_add(&rep->rex, &now, t->be->srvtimeout);
|
||||||
t->srv_state = SV_STSHUTW;
|
t->srv_state = SV_STSHUTW;
|
||||||
if (!(t->flags & SN_ERR_MASK))
|
if (!(t->flags & SN_ERR_MASK))
|
||||||
t->flags |= SN_ERR_SRVTO;
|
t->flags |= SN_ERR_SRVTO;
|
||||||
@ -3054,7 +3054,7 @@ int process_srv(struct session *t)
|
|||||||
if (EV_FD_COND_S(t->srv_fd, DIR_WR)) {
|
if (EV_FD_COND_S(t->srv_fd, DIR_WR)) {
|
||||||
/* restart writing */
|
/* restart writing */
|
||||||
if (t->be->srvtimeout) {
|
if (t->be->srvtimeout) {
|
||||||
tv_delayfrom(&req->wex, &now, t->be->srvtimeout);
|
tv_ms_add(&req->wex, &now, t->be->srvtimeout);
|
||||||
/* FIXME: to prevent the server from expiring read timeouts during writes,
|
/* FIXME: to prevent the server from expiring read timeouts during writes,
|
||||||
* we refresh it. */
|
* we refresh it. */
|
||||||
rep->rex = req->wex;
|
rep->rex = req->wex;
|
||||||
@ -3073,7 +3073,7 @@ int process_srv(struct session *t)
|
|||||||
else {
|
else {
|
||||||
if (EV_FD_COND_S(t->srv_fd, DIR_RD)) {
|
if (EV_FD_COND_S(t->srv_fd, DIR_RD)) {
|
||||||
if (t->be->srvtimeout)
|
if (t->be->srvtimeout)
|
||||||
tv_delayfrom(&rep->rex, &now, t->be->srvtimeout);
|
tv_ms_add(&rep->rex, &now, t->be->srvtimeout);
|
||||||
else
|
else
|
||||||
tv_eternity(&rep->rex);
|
tv_eternity(&rep->rex);
|
||||||
}
|
}
|
||||||
@ -3121,7 +3121,7 @@ int process_srv(struct session *t)
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (tv_cmp2_le(&req->wex, &now)) {
|
else if (tv_ms_le2(&req->wex, &now)) {
|
||||||
//EV_FD_CLR(t->srv_fd, DIR_WR);
|
//EV_FD_CLR(t->srv_fd, DIR_WR);
|
||||||
tv_eternity(&req->wex);
|
tv_eternity(&req->wex);
|
||||||
fd_delete(t->srv_fd);
|
fd_delete(t->srv_fd);
|
||||||
@ -3151,7 +3151,7 @@ int process_srv(struct session *t)
|
|||||||
if (EV_FD_COND_S(t->srv_fd, DIR_WR)) {
|
if (EV_FD_COND_S(t->srv_fd, DIR_WR)) {
|
||||||
/* restart writing */
|
/* restart writing */
|
||||||
if (t->be->srvtimeout) {
|
if (t->be->srvtimeout) {
|
||||||
tv_delayfrom(&req->wex, &now, t->be->srvtimeout);
|
tv_ms_add(&req->wex, &now, t->be->srvtimeout);
|
||||||
/* FIXME: to prevent the server from expiring read timeouts during writes,
|
/* FIXME: to prevent the server from expiring read timeouts during writes,
|
||||||
* we refresh it. */
|
* we refresh it. */
|
||||||
rep->rex = req->wex;
|
rep->rex = req->wex;
|
||||||
@ -3202,7 +3202,7 @@ int process_srv(struct session *t)
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (tv_cmp2_le(&rep->rex, &now)) {
|
else if (tv_ms_le2(&rep->rex, &now)) {
|
||||||
//EV_FD_CLR(t->srv_fd, DIR_RD);
|
//EV_FD_CLR(t->srv_fd, DIR_RD);
|
||||||
tv_eternity(&rep->rex);
|
tv_eternity(&rep->rex);
|
||||||
fd_delete(t->srv_fd);
|
fd_delete(t->srv_fd);
|
||||||
@ -3230,7 +3230,7 @@ int process_srv(struct session *t)
|
|||||||
else {
|
else {
|
||||||
if (EV_FD_COND_S(t->srv_fd, DIR_RD)) {
|
if (EV_FD_COND_S(t->srv_fd, DIR_RD)) {
|
||||||
if (t->be->srvtimeout)
|
if (t->be->srvtimeout)
|
||||||
tv_delayfrom(&rep->rex, &now, t->be->srvtimeout);
|
tv_ms_add(&rep->rex, &now, t->be->srvtimeout);
|
||||||
else
|
else
|
||||||
tv_eternity(&rep->rex);
|
tv_eternity(&rep->rex);
|
||||||
}
|
}
|
||||||
@ -4349,7 +4349,7 @@ void manage_client_side_cookies(struct session *t, struct buffer *req)
|
|||||||
}/* end while(srv) */
|
}/* end while(srv) */
|
||||||
}/* end else if server == NULL */
|
}/* end else if server == NULL */
|
||||||
|
|
||||||
tv_delayfrom(&asession_temp->expire, &now, t->be->appsession_timeout);
|
tv_ms_add(&asession_temp->expire, &now, t->be->appsession_timeout);
|
||||||
}/* end if ((t->proxy->appsession_name != NULL) ... */
|
}/* end if ((t->proxy->appsession_name != NULL) ... */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4809,7 +4809,7 @@ void manage_server_side_cookies(struct session *t, struct buffer *rtr)
|
|||||||
if (asession_temp->serverid[0] == '\0')
|
if (asession_temp->serverid[0] == '\0')
|
||||||
memcpy(asession_temp->serverid, t->srv->id, server_id_len);
|
memcpy(asession_temp->serverid, t->srv->id, server_id_len);
|
||||||
|
|
||||||
tv_delayfrom(&asession_temp->expire, &now, t->be->appsession_timeout);
|
tv_ms_add(&asession_temp->expire, &now, t->be->appsession_timeout);
|
||||||
|
|
||||||
#if defined(DEBUG_HASH)
|
#if defined(DEBUG_HASH)
|
||||||
print_table(&(t->be->htbl_proxy));
|
print_table(&(t->be->htbl_proxy));
|
||||||
@ -4971,7 +4971,7 @@ void get_srv_from_appsession(struct session *t, const char *begin, int len)
|
|||||||
pool_free_to(apools.sessid, local_asession.sessid);
|
pool_free_to(apools.sessid, local_asession.sessid);
|
||||||
}
|
}
|
||||||
|
|
||||||
tv_delayfrom(&asession_temp->expire, &now, t->be->appsession_timeout);
|
tv_ms_add(&asession_temp->expire, &now, t->be->appsession_timeout);
|
||||||
asession_temp->request_count++;
|
asession_temp->request_count++;
|
||||||
|
|
||||||
#if defined(DEBUG_HASH)
|
#if defined(DEBUG_HASH)
|
||||||
@ -5092,7 +5092,7 @@ int stats_check_uri_auth(struct session *t, struct proxy *backend)
|
|||||||
*/
|
*/
|
||||||
t->cli_state = CL_STSHUTR;
|
t->cli_state = CL_STSHUTR;
|
||||||
t->req->rlim = t->req->data + BUFSIZE; /* no more rewrite needed */
|
t->req->rlim = t->req->data + BUFSIZE; /* no more rewrite needed */
|
||||||
t->logs.t_request = tv_diff(&t->logs.tv_accept, &now);
|
t->logs.t_request = tv_ms_elapsed(&t->logs.tv_accept, &now);
|
||||||
t->data_source = DATA_SRC_STATS;
|
t->data_source = DATA_SRC_STATS;
|
||||||
t->data_state = DATA_ST_INIT;
|
t->data_state = DATA_ST_INIT;
|
||||||
produce_content(t);
|
produce_content(t);
|
||||||
|
@ -221,7 +221,7 @@ int maintain_proxies(void)
|
|||||||
while (p) {
|
while (p) {
|
||||||
if (p->state != PR_STSTOPPED) {
|
if (p->state != PR_STSTOPPED) {
|
||||||
int t;
|
int t;
|
||||||
t = tv_remain2(&now, &p->stop_time);
|
t = tv_ms_remain2(&now, &p->stop_time);
|
||||||
if (t == 0) {
|
if (t == 0) {
|
||||||
Warning("Proxy %s stopped.\n", p->id);
|
Warning("Proxy %s stopped.\n", p->id);
|
||||||
send_log(p, LOG_WARNING, "Proxy %s stopped.\n", p->id);
|
send_log(p, LOG_WARNING, "Proxy %s stopped.\n", p->id);
|
||||||
@ -259,7 +259,7 @@ void soft_stop(void)
|
|||||||
if (p->state != PR_STSTOPPED) {
|
if (p->state != PR_STSTOPPED) {
|
||||||
Warning("Stopping proxy %s in %d ms.\n", p->id, p->grace);
|
Warning("Stopping proxy %s in %d ms.\n", p->id, p->grace);
|
||||||
send_log(p, LOG_WARNING, "Stopping proxy %s in %d ms.\n", p->id, p->grace);
|
send_log(p, LOG_WARNING, "Stopping proxy %s in %d ms.\n", p->id, p->grace);
|
||||||
tv_delayfrom(&p->stop_time, &now, p->grace);
|
tv_ms_add(&p->stop_time, &now, p->grace);
|
||||||
}
|
}
|
||||||
p = p->next;
|
p = p->next;
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ int stream_sock_read(int fd) {
|
|||||||
if (b->flags & BF_READ_STATUS) {
|
if (b->flags & BF_READ_STATUS) {
|
||||||
out_wakeup:
|
out_wakeup:
|
||||||
if (b->rto && EV_FD_ISSET(fd, DIR_RD))
|
if (b->rto && EV_FD_ISSET(fd, DIR_RD))
|
||||||
tv_delayfrom(&b->rex, &now, b->rto);
|
tv_ms_add(&b->rex, &now, b->rto);
|
||||||
else
|
else
|
||||||
tv_eternity(&b->rex);
|
tv_eternity(&b->rex);
|
||||||
|
|
||||||
@ -278,7 +278,7 @@ int stream_sock_write(int fd) {
|
|||||||
|
|
||||||
if (b->flags & BF_WRITE_STATUS) {
|
if (b->flags & BF_WRITE_STATUS) {
|
||||||
if (b->wto) {
|
if (b->wto) {
|
||||||
tv_delayfrom(&b->wex, &now, b->wto);
|
tv_ms_add(&b->wex, &now, b->wto);
|
||||||
/* FIXME: to prevent the client from expiring read timeouts during writes,
|
/* FIXME: to prevent the client from expiring read timeouts during writes,
|
||||||
* we refresh it. A solution would be to merge read+write timeouts into a
|
* we refresh it. A solution would be to merge read+write timeouts into a
|
||||||
* unique one, although that needs some study particularly on full-duplex
|
* unique one, although that needs some study particularly on full-duplex
|
||||||
|
@ -96,8 +96,8 @@ int wake_expired_tasks()
|
|||||||
|
|
||||||
if (likely(timer_wq.data != NULL)) {
|
if (likely(timer_wq.data != NULL)) {
|
||||||
task = LIST_ELEM(timer_wq.data, struct task *, qlist);
|
task = LIST_ELEM(timer_wq.data, struct task *, qlist);
|
||||||
if (likely(tv_cmp_ge(&task->expire, &now) > 0))
|
if (likely(__tv_isge(&task->expire, &now) > 0))
|
||||||
return tv_remain(&now, &task->expire);
|
return tv_ms_remain(&now, &task->expire);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* OK we lose. Let's scan the tree then. */
|
/* OK we lose. Let's scan the tree then. */
|
||||||
@ -106,8 +106,8 @@ int wake_expired_tasks()
|
|||||||
tree64_foreach(&timer_wq, data, stack, slen) {
|
tree64_foreach(&timer_wq, data, stack, slen) {
|
||||||
task = LIST_ELEM(data, struct task *, qlist);
|
task = LIST_ELEM(data, struct task *, qlist);
|
||||||
|
|
||||||
if (!tv_isbefore(&task->expire, &now)) {
|
if (__tv_isgt(&task->expire, &now)) {
|
||||||
next_time = tv_remain(&now, &task->expire);
|
next_time = tv_ms_remain(&now, &task->expire);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
125
src/time.c
125
src/time.c
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Time calculation functions.
|
* Time calculation functions.
|
||||||
*
|
*
|
||||||
* Copyright 2000-2006 Willy Tarreau <w@1wt.eu>
|
* Copyright 2000-2007 Willy Tarreau <w@1wt.eu>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
@ -22,10 +22,8 @@ struct timeval start_date; /* the process's start date */
|
|||||||
/*
|
/*
|
||||||
* adds <ms> ms to <from>, set the result to <tv> and returns a pointer <tv>
|
* adds <ms> ms to <from>, set the result to <tv> and returns a pointer <tv>
|
||||||
*/
|
*/
|
||||||
REGPRM3 struct timeval *tv_delayfrom(struct timeval *tv, const struct timeval *from, int ms)
|
REGPRM3 struct timeval *_tv_ms_add(struct timeval *tv, const struct timeval *from, int ms)
|
||||||
{
|
{
|
||||||
if (!tv || !from)
|
|
||||||
return NULL;
|
|
||||||
tv->tv_usec = from->tv_usec + (ms % 1000) * 1000;
|
tv->tv_usec = from->tv_usec + (ms % 1000) * 1000;
|
||||||
tv->tv_sec = from->tv_sec + (ms / 1000);
|
tv->tv_sec = from->tv_sec + (ms / 1000);
|
||||||
while (tv->tv_usec >= 1000000) {
|
while (tv->tv_usec >= 1000000) {
|
||||||
@ -37,90 +35,41 @@ REGPRM3 struct timeval *tv_delayfrom(struct timeval *tv, const struct timeval *f
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* compares <tv1> and <tv2> modulo 1ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2
|
* compares <tv1> and <tv2> modulo 1ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2
|
||||||
* Must not be used when either argument is eternity. Use tv_cmp2_ms() for that.
|
* Must not be used when either argument is eternity. Use tv_ms_cmp2() for that.
|
||||||
*/
|
*/
|
||||||
REGPRM2 int tv_cmp_ms(const struct timeval *tv1, const struct timeval *tv2)
|
REGPRM2 int _tv_ms_cmp(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
{
|
{
|
||||||
if ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) {
|
return __tv_ms_cmp(tv1, tv2);
|
||||||
if ((unsigned)tv2->tv_usec >= (unsigned)tv1->tv_usec + 1000)
|
|
||||||
return -1;
|
|
||||||
else if ((unsigned)tv1->tv_usec >= (unsigned)tv2->tv_usec + 1000)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if (((unsigned)tv2->tv_sec > (unsigned)tv1->tv_sec + 1) ||
|
|
||||||
(((unsigned)tv2->tv_sec == (unsigned)tv1->tv_sec + 1) &&
|
|
||||||
((unsigned)tv2->tv_usec + 1000000 >= (unsigned)tv1->tv_usec + 1000)))
|
|
||||||
return -1;
|
|
||||||
else if (((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec + 1) ||
|
|
||||||
(((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec + 1) &&
|
|
||||||
((unsigned)tv1->tv_usec + 1000000 >= (unsigned)tv2->tv_usec + 1000)))
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* compares <tv1> and <tv2> modulo 1 ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2,
|
* compares <tv1> and <tv2> modulo 1 ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2,
|
||||||
* assuming that TV_ETERNITY is greater than everything.
|
* assuming that TV_ETERNITY is greater than everything.
|
||||||
*/
|
*/
|
||||||
REGPRM2 int tv_cmp2_ms(const struct timeval *tv1, const struct timeval *tv2)
|
REGPRM2 int _tv_ms_cmp2(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
{
|
{
|
||||||
if (tv_iseternity(tv1))
|
return __tv_ms_cmp2(tv1, tv2);
|
||||||
if (tv_iseternity(tv2))
|
|
||||||
return 0; /* same */
|
|
||||||
else
|
|
||||||
return 1; /* tv1 later than tv2 */
|
|
||||||
else if (tv_iseternity(tv2))
|
|
||||||
return -1; /* tv2 later than tv1 */
|
|
||||||
|
|
||||||
if ((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec) {
|
|
||||||
if ((unsigned)tv1->tv_usec >= (unsigned)tv2->tv_usec + 1000)
|
|
||||||
return 1;
|
|
||||||
else if ((unsigned)tv2->tv_usec >= (unsigned)tv1->tv_usec + 1000)
|
|
||||||
return -1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if (((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec + 1) ||
|
|
||||||
(((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec + 1) &&
|
|
||||||
((unsigned)tv1->tv_usec + 1000000 >= (unsigned)tv2->tv_usec + 1000)))
|
|
||||||
return 1;
|
|
||||||
else if (((unsigned)tv2->tv_sec > (unsigned)tv1->tv_sec + 1) ||
|
|
||||||
(((unsigned)tv2->tv_sec == (unsigned)tv1->tv_sec + 1) &&
|
|
||||||
((unsigned)tv2->tv_usec + 1000000 >= (unsigned)tv1->tv_usec + 1000)))
|
|
||||||
return -1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* compares <tv1> and <tv2> modulo 1 ms: returns 1 if tv1 <= tv2, 0 if tv1 > tv2,
|
* compares <tv1> and <tv2> modulo 1 ms: returns 1 if tv1 <= tv2, 0 if tv1 > tv2,
|
||||||
* assuming that TV_ETERNITY is greater than everything. Returns 0 if tv1 is
|
* assuming that TV_ETERNITY is greater than everything. Returns 0 if tv1 is
|
||||||
* TV_ETERNITY, and always assumes that tv2 != TV_ETERNITY. Designed to replace
|
* TV_ETERNITY, and always assumes that tv2 != TV_ETERNITY. Designed to replace
|
||||||
* occurrences of (tv_cmp2_ms(tv,now) <= 0).
|
* occurrences of (tv_ms_cmp2(tv,now) <= 0).
|
||||||
*/
|
*/
|
||||||
REGPRM2 int tv_cmp2_le(const struct timeval *tv1, const struct timeval *tv2)
|
REGPRM2 int _tv_ms_le2(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
{
|
{
|
||||||
if (likely((unsigned)tv1->tv_sec > (unsigned)tv2->tv_sec + 1))
|
return __tv_ms_le2(tv1, tv2);
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (likely((unsigned)tv1->tv_sec < (unsigned)tv2->tv_sec))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (likely((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec)) {
|
|
||||||
if ((unsigned)tv2->tv_usec >= (unsigned)tv1->tv_usec + 1000)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(((unsigned)tv1->tv_sec == (unsigned)tv2->tv_sec + 1) &&
|
/*
|
||||||
((unsigned)tv1->tv_usec + 1000000 >= (unsigned)tv2->tv_usec + 1000)))
|
* returns the remaining time between tv1=now and event=tv2
|
||||||
return 0;
|
* if tv2 is passed, 0 is returned.
|
||||||
else
|
* Must not be used when either argument is eternity.
|
||||||
return 1;
|
*/
|
||||||
|
REGPRM2 unsigned long _tv_ms_remain(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
|
{
|
||||||
|
return __tv_ms_remain(tv1, tv2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -128,49 +77,21 @@ REGPRM2 int tv_cmp2_le(const struct timeval *tv1, const struct timeval *tv2)
|
|||||||
* if tv2 is passed, 0 is returned.
|
* if tv2 is passed, 0 is returned.
|
||||||
* Returns TIME_ETERNITY if tv2 is eternity.
|
* Returns TIME_ETERNITY if tv2 is eternity.
|
||||||
*/
|
*/
|
||||||
REGPRM2 unsigned long tv_remain2(const struct timeval *tv1, const struct timeval *tv2)
|
REGPRM2 unsigned long _tv_ms_remain2(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
{
|
{
|
||||||
unsigned long ret;
|
|
||||||
|
|
||||||
if (tv_iseternity(tv2))
|
if (tv_iseternity(tv2))
|
||||||
return TIME_ETERNITY;
|
return TIME_ETERNITY;
|
||||||
|
|
||||||
if (tv_cmp_ms(tv1, tv2) >= 0)
|
return __tv_ms_remain(tv1, tv2);
|
||||||
return 0; /* event elapsed */
|
|
||||||
|
|
||||||
ret = (tv2->tv_sec - tv1->tv_sec) * 1000;
|
|
||||||
if ((unsigned)tv2->tv_usec > (unsigned)tv1->tv_usec)
|
|
||||||
ret += (tv2->tv_usec - tv1->tv_usec) / 1000;
|
|
||||||
else
|
|
||||||
ret -= (tv1->tv_usec - tv2->tv_usec) / 1000;
|
|
||||||
return (unsigned long) ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* returns the absolute difference, in ms, between tv1 and tv2
|
* Returns the time in ms elapsed between tv1 and tv2, assuming that tv1<=tv2.
|
||||||
* Must not be used when either argument is eternity.
|
* Must not be used when either argument is eternity.
|
||||||
*/
|
*/
|
||||||
REGPRM2 unsigned long tv_delta(const struct timeval *tv1, const struct timeval *tv2)
|
REGPRM2 unsigned long _tv_ms_elapsed(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
{
|
{
|
||||||
int cmp;
|
return __tv_ms_elapsed(tv1, tv2);
|
||||||
unsigned long ret;
|
|
||||||
|
|
||||||
|
|
||||||
cmp = tv_cmp(tv1, tv2);
|
|
||||||
if (!cmp)
|
|
||||||
return 0; /* same dates, null diff */
|
|
||||||
else if (cmp < 0) {
|
|
||||||
const struct timeval *tmp = tv1;
|
|
||||||
tv1 = tv2;
|
|
||||||
tv2 = tmp;
|
|
||||||
}
|
|
||||||
ret = (tv1->tv_sec - tv2->tv_sec) * 1000;
|
|
||||||
if ((unsigned)tv1->tv_usec > (unsigned)tv2->tv_usec)
|
|
||||||
ret += (tv1->tv_usec - tv2->tv_usec) / 1000;
|
|
||||||
else
|
|
||||||
ret -= (tv2->tv_usec - tv1->tv_usec) / 1000;
|
|
||||||
return (unsigned long) ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user