diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-04-21 22:54:33 +0400 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-04-21 22:54:33 +0400 |
commit | 732a27196381164c799d345ec0d010b416408555 (patch) | |
tree | 043848398927223e1b08d1b15c071b3a23717d76 /src/core | |
parent | bb570859043557c5c1b20d933ff2e4c18d13c980 (diff) |
nginx-0.0.3-2004-04-21-22:54:33 import
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/nginx.c | 2 | ||||
-rw-r--r-- | src/core/ngx_config.h | 17 | ||||
-rw-r--r-- | src/core/ngx_times.c | 157 | ||||
-rw-r--r-- | src/core/ngx_times.h | 10 |
4 files changed, 126 insertions, 60 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index 3c5f789fe..f63eeccaa 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -86,7 +86,7 @@ int main(int argc, char *const *argv) ngx_core_conf_t *ccf; ngx_master_ctx_t ctx; -#if __FreeBSD__ +#if defined __FreeBSD__ ngx_debug_init(); #endif diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h index dea3e5cf9..3d44f1ea4 100644 --- a/src/core/ngx_config.h +++ b/src/core/ngx_config.h @@ -2,29 +2,22 @@ #define _NGX_CONFIG_H_INCLUDED_ -#if 0 -/* STUB to allocate a big ngx_connections */ -#undef FD_SETSIZE -#define FD_SETSIZE 5000 -#endif - - -#if defined __DragonFly__ && !defined(__FreeBSD__) +#if defined __DragonFly__ && !defined __FreeBSD__ #define __FreeBSD__ 4 #define __FreeBSD_version 480101 #endif -#if defined (__FreeBSD__) +#if defined __FreeBSD__ #include <ngx_freebsd_config.h> -#elif defined (__linux__) +#elif defined __linux__ #include <ngx_linux_config.h> /* Solaris */ -#elif defined (sun) && (defined (__svr4__) || defined (__SVR4)) +#elif defined sun && (defined __svr4__ || defined __SVR4) #include <ngx_solaris_config.h> @@ -101,6 +94,8 @@ typedef int ngx_flag_t; #define ngx_inline inline #endif +#define NGX_ACCEPT_THRESHOLD 50 + #ifndef INADDR_NONE /* Solaris */ #define INADDR_NONE ((unsigned int) -1) #endif diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c index 4a6ad2ef3..bb1c49cb3 100644 --- a/src/core/ngx_times.c +++ b/src/core/ngx_times.c @@ -8,21 +8,27 @@ static ngx_mutex_t *ngx_time_mutex; #endif -time_t ngx_cached_time; -ngx_epoch_msec_t ngx_elapsed_msec; -ngx_epoch_msec_t ngx_old_elapsed_msec; -ngx_epoch_msec_t ngx_start_msec; +ngx_epoch_msec_t ngx_elapsed_msec; +ngx_epoch_msec_t ngx_old_elapsed_msec; +ngx_epoch_msec_t ngx_start_msec; -ngx_tm_t ngx_cached_gmtime; +volatile time_t ngx_cached_time; -static u_char cached_err_log_time[] = "1970/09/28 12:00:00"; -ngx_str_t ngx_cached_err_log_time; +volatile ngx_str_t ngx_cached_err_log_time; +volatile ngx_str_t ngx_cached_http_time; +volatile ngx_str_t ngx_cached_http_log_time; -static u_char cached_http_time[] = "Mon, 28 Sep 1970 06:00:00 GMT"; -ngx_str_t ngx_cached_http_time; +static ngx_tm_t ngx_cached_gmtime; +static ngx_int_t ngx_gmtoff; -static u_char cached_http_log_time[] = "28/Sep/1970:12:00:00"; -ngx_str_t ngx_cached_http_log_time; +static u_char cached_err_log_time0[] = "1970/09/28 12:00:00"; +static u_char cached_err_log_time1[] = "1970/09/28 12:00:00"; + +static u_char cached_http_time0[] = "Mon, 28 Sep 1970 06:00:00 GMT"; +static u_char cached_http_time1[] = "Mon, 28 Sep 1970 06:00:00 GMT"; + +static u_char cached_http_log_time0[] = "28/Sep/1970:12:00:00 +0600"; +static u_char cached_http_log_time1[] = "28/Sep/1970:12:00:00 +0600"; static char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fir", "Sat" }; @@ -39,9 +45,15 @@ void ngx_time_init() ngx_cached_gmtime.ngx_tm_zone = "GMT"; #endif - ngx_cached_err_log_time.data = cached_err_log_time; - ngx_cached_http_time.data = cached_http_time; - ngx_cached_http_log_time.data = cached_http_log_time; + ngx_cached_err_log_time.len = sizeof(cached_err_log_time0) - 1; + ngx_cached_err_log_time.data = cached_err_log_time0; + + ngx_cached_http_time.len = sizeof(cached_http_time0) - 1; + ngx_cached_http_time.data = cached_http_time0; + + ngx_cached_http_log_time.len = sizeof(cached_http_log_time0) - 1; + ngx_cached_http_log_time.data = cached_http_log_time0; + ngx_cached_time = 0; ngx_gettimeofday(&tv); @@ -50,6 +62,10 @@ void ngx_time_init() ngx_old_elapsed_msec = 0; ngx_elapsed_msec = 0; +#if !(WIN32) + tzset(); +#endif + ngx_time_update(tv.tv_sec); } @@ -70,7 +86,11 @@ ngx_int_t ngx_time_mutex_init(ngx_log_t *log) void ngx_time_update(time_t s) { - ngx_tm_t tm; + char *p; + ngx_tm_t tm; +#if (WIN32) + TIME_ZONE_INFORMATION tz; +#endif if (ngx_cached_time == s) { return; @@ -86,37 +106,88 @@ void ngx_time_update(time_t s) ngx_gmtime(ngx_cached_time, &ngx_cached_gmtime); - ngx_cached_http_time.len = ngx_snprintf((char *) ngx_cached_http_time.data, - sizeof("Mon, 28 Sep 1970 06:00:00 GMT"), - "%s, %02d %s %4d %02d:%02d:%02d GMT", - week[ngx_cached_gmtime.ngx_tm_wday], - ngx_cached_gmtime.ngx_tm_mday, - months[ngx_cached_gmtime.ngx_tm_mon - 1], - ngx_cached_gmtime.ngx_tm_year, - ngx_cached_gmtime.ngx_tm_hour, - ngx_cached_gmtime.ngx_tm_min, - ngx_cached_gmtime.ngx_tm_sec); + + if (ngx_cached_http_time.data == cached_http_time0) { + p = cached_http_time1; + } else { + p = cached_http_time0; + } + + ngx_snprintf(p, sizeof("Mon, 28 Sep 1970 06:00:00 GMT"), + "%s, %02d %s %4d %02d:%02d:%02d GMT", + week[ngx_cached_gmtime.ngx_tm_wday], + ngx_cached_gmtime.ngx_tm_mday, + months[ngx_cached_gmtime.ngx_tm_mon - 1], + ngx_cached_gmtime.ngx_tm_year, + ngx_cached_gmtime.ngx_tm_hour, + ngx_cached_gmtime.ngx_tm_min, + ngx_cached_gmtime.ngx_tm_sec); + + ngx_cached_http_time.data = p; + + +#if (WIN32) + + /* + * we do not use GetLocalTime() because it does not return GMT offset, + * and our ngx_gmtime() is fast enough + */ + + if (GetTimeZoneInformation(&tz) != TIME_ZONE_ID_INVALID) { + ngx_gmtoff = - tz.Bias; + } + + ngx_gmtime(ngx_cached_time + ngx_gmtoff * 60, &tm); + +#elif (SOLARIS) + + ngx_gmtoff = (daylight) ? - altzone / 60: - timezone / 60; + ngx_gmtime(ngx_cached_time + ngx_gmtoff * 60, &tm); + +#elif defined __linux__ + + ngx_gmtoff = - timezone / 60 + daylight * 60; + ngx_gmtime(ngx_cached_time + ngx_gmtoff * 60, &tm); + +#else ngx_localtime(&tm); + ngx_gmtoff = tm.ngx_tm_gmtoff / 60; + +#endif + + + if (ngx_cached_err_log_time.data == cached_err_log_time0) { + p = cached_err_log_time1; + } else { + p = cached_err_log_time0; + } + + ngx_snprintf(p, sizeof("1970/09/28 12:00:00"), + "%4d/%02d/%02d %02d:%02d:%02d", + tm.ngx_tm_year, tm.ngx_tm_mon, + tm.ngx_tm_mday, tm.ngx_tm_hour, + tm.ngx_tm_min, tm.ngx_tm_sec); + + ngx_cached_err_log_time.data = p; + + + if (ngx_cached_http_log_time.data == cached_http_log_time0) { + p = cached_http_log_time1; + } else { + p = cached_http_log_time0; + } + + ngx_snprintf(p, sizeof("28/Sep/1970:12:00:00 +0600"), + "%02d/%s/%d:%02d:%02d:%02d %c%02d%02d", + tm.ngx_tm_mday, months[tm.ngx_tm_mon - 1], + tm.ngx_tm_year, tm.ngx_tm_hour, + tm.ngx_tm_min, tm.ngx_tm_sec, + ngx_gmtoff < 0 ? '-' : '+', + abs(ngx_gmtoff / 60), abs(ngx_gmtoff % 60)); + + ngx_cached_http_log_time.data = p; - ngx_cached_err_log_time.len = ngx_snprintf((char *) - ngx_cached_err_log_time.data, - sizeof("1970/09/28 12:00:00"), - "%4d/%02d/%02d %02d:%02d:%02d", - tm.ngx_tm_year, tm.ngx_tm_mon, - tm.ngx_tm_mday, tm.ngx_tm_hour, - tm.ngx_tm_min, tm.ngx_tm_sec); - - ngx_cached_http_log_time.len = ngx_snprintf((char *) - ngx_cached_http_log_time.data, - sizeof("28/Sep/1970:12:00:00"), - "%02d/%s/%d:%02d:%02d:%02d", - tm.ngx_tm_mday, - months[tm.ngx_tm_mon - 1], - tm.ngx_tm_year, - tm.ngx_tm_hour, - tm.ngx_tm_min, - tm.ngx_tm_sec); #if (NGX_THREADS) ngx_mutex_unlock(ngx_time_mutex); diff --git a/src/core/ngx_times.h b/src/core/ngx_times.h index eccbcde14..8fdf685df 100644 --- a/src/core/ngx_times.h +++ b/src/core/ngx_times.h @@ -17,12 +17,12 @@ void ngx_gmtime(time_t t, ngx_tm_t *tp); #define ngx_time() ngx_cached_time -extern time_t ngx_cached_time; -extern ngx_str_t ngx_cached_err_log_time; -extern ngx_str_t ngx_cached_http_time; -extern ngx_str_t ngx_cached_http_log_time; +extern volatile time_t ngx_cached_time; +extern volatile ngx_str_t ngx_cached_err_log_time; +extern volatile ngx_str_t ngx_cached_http_time; +extern volatile ngx_str_t ngx_cached_http_log_time; -extern ngx_epoch_msec_t ngx_start_msec; +extern ngx_epoch_msec_t ngx_start_msec; /* * msecs elapsed since ngx_start_msec in the current event cycle, |