aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2004-06-17 17:18:53 +0000
committerIgor Sysoev <igor@sysoev.ru>2004-06-17 17:18:53 +0000
commit415b1ce1b93a3b74efe8a3ee5a35ee55e0a11caa (patch)
tree077bf24b4f310a87ab8bff140c730cb679069988 /src
parentf924e6b694db7fd1d99473b3d7db7eb2b49c9e62 (diff)
downloadnginx-415b1ce1b93a3b74efe8a3ee5a35ee55e0a11caa.tar.gz
nginx-415b1ce1b93a3b74efe8a3ee5a35ee55e0a11caa.zip
nginx-0.0.7-2004-06-17-21:18:53 import
Diffstat (limited to 'src')
-rw-r--r--src/core/ngx_core.h1
-rw-r--r--src/core/ngx_times.c11
-rw-r--r--src/event/ngx_event.c12
-rw-r--r--src/http/ngx_http_request.c3
-rw-r--r--src/os/unix/ngx_linux_config.h5
-rw-r--r--src/os/unix/ngx_shared.c91
-rw-r--r--src/os/unix/ngx_shared.h12
-rw-r--r--src/os/unix/ngx_time.h21
-rw-r--r--src/os/win32/ngx_shared.h12
-rw-r--r--src/os/win32/ngx_time.c2
-rw-r--r--src/os/win32/ngx_time.h7
11 files changed, 146 insertions, 31 deletions
diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h
index 55c4147f7..2a112dded 100644
--- a/src/core/ngx_core.h
+++ b/src/core/ngx_core.h
@@ -19,6 +19,7 @@ typedef struct ngx_connection_s ngx_connection_t;
#include <ngx_time.h>
#include <ngx_socket.h>
#include <ngx_errno.h>
+#include <ngx_shared.h>
#include <ngx_process.h>
#include <ngx_thread.h>
#include <ngx_user.h>
diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c
index ac2a3a9db..aa461c56f 100644
--- a/src/core/ngx_times.c
+++ b/src/core/ngx_times.c
@@ -123,16 +123,21 @@ void ngx_time_update(time_t s)
ngx_cached_http_time.data = p;
-#if (HAVE_TIMEZONE)
+#if (HAVE_GETTIMEZONE)
- ngx_gmtoff = ngx_timezone();
+ ngx_gmtoff = ngx_gettimezone();
ngx_gmtime(ngx_cached_time + ngx_gmtoff * 60, &tm);
-#else
+#elif (HAVE_GMTOFF)
ngx_localtime(&tm);
ngx_gmtoff = tm.ngx_tm_gmtoff / 60;
+#else
+
+ ngx_localtime(&tm);
+ ngx_gmtoff = ngx_timezone(tm.ngx_tm_isdst);
+
#endif
diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c
index a74430a50..728dbde70 100644
--- a/src/event/ngx_event.c
+++ b/src/event/ngx_event.c
@@ -187,6 +187,7 @@ static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle)
size = 128 /* ngx_accept_mutex */
+ 128; /* ngx_connection_counter */
+#if 0
shared = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
if (shared == MAP_FAILED) {
@@ -194,6 +195,11 @@ static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle)
"mmap(MAP_ANON|MAP_SHARED) failed");
return NGX_ERROR;
}
+#endif
+
+ if (!(shared = ngx_create_shared_memory(size, cycle->log))) {
+ return NGX_ERROR;
+ }
ngx_accept_mutex_ptr = (ngx_atomic_t *) shared;
ngx_connection_counter = (ngx_atomic_t *) (shared + 128);
@@ -611,7 +617,7 @@ static void *ngx_event_create_conf(ngx_cycle_t *cycle)
NGX_CONF_ERROR);
ecf->connections = NGX_CONF_UNSET_UINT;
- ecf->use = NGX_CONF_UNSET;
+ ecf->use = NGX_CONF_UNSET_UINT;
ecf->multi_accept = NGX_CONF_UNSET;
ecf->accept_mutex = NGX_CONF_UNSET;
ecf->accept_mutex_delay = NGX_CONF_UNSET_MSEC;
@@ -694,9 +700,9 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
return NGX_CONF_ERROR;
}
- ngx_conf_unsigned_init_value(ecf->connections, DEFAULT_CONNECTIONS);
+ ngx_conf_init_unsigned_value(ecf->connections, DEFAULT_CONNECTIONS);
- ngx_conf_unsigned_init_value(ecf->use, m);
+ ngx_conf_init_unsigned_value(ecf->use, m);
ngx_conf_init_ptr_value(ecf->name, module->name->data);
#endif
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index 3f506661f..0f30a3177 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -943,7 +943,8 @@ static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
* in CPU cache
*/
- ua = ngx_strstr(r->headers_in.user_agent->value.data, "MSIE");
+ ua = (u_char *) ngx_strstr(r->headers_in.user_agent->value.data,
+ "MSIE");
if (ua
&& ua + 8 < r->headers_in.user_agent->value.data
+ r->headers_in.user_agent->value.len)
diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h
index 2b6eb9cb3..8a75e229f 100644
--- a/src/os/unix/ngx_linux_config.h
+++ b/src/os/unix/ngx_linux_config.h
@@ -41,11 +41,6 @@
#include <netinet/tcp.h> /* TCP_CORK */
-/* Linux has no <sys/filio.h> so autoconfigure does not find FIONBIO */
-#ifndef HAVE_FIONBIO
-#define HAVE_FIONBIO 1
-#endif
-
#include <ngx_auto_config.h>
diff --git a/src/os/unix/ngx_shared.c b/src/os/unix/ngx_shared.c
new file mode 100644
index 000000000..a19ca5315
--- /dev/null
+++ b/src/os/unix/ngx_shared.c
@@ -0,0 +1,91 @@
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+#if (HAVE_MAP_ANON)
+
+void *ngx_create_shared_memory(size_t size, ngx_log_t *log)
+{
+ void *p;
+
+ p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
+
+ if (p == MAP_FAILED) {
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
+ "mmap(MAP_ANON|MAP_SHARED, " SIZE_T_FMT ") failed",
+ size);
+ return NULL;
+ }
+
+ return p;
+}
+
+#elif (HAVE_MAP_DEVZERO)
+
+void *ngx_create_shared_memory(size_t size, ngx_log_t *log)
+{
+ void *p;
+ ngx_fd_t fd;
+
+ fd = open("/dev/zero", O_RDWR);
+
+ if (fd == -1) {
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
+ "open(/dev/zero) failed");
+ return NULL;
+ }
+
+ p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+
+ if (p == MAP_FAILED) {
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
+ "mmap(/dev/zero, MAP_SHARED, " SIZE_T_FMT ") failed",
+ size);
+ p = NULL;
+ }
+
+ if (close(fd) == -1) {
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "close() failed");
+ }
+
+ return p;
+}
+
+#elif (HAVE_SYSVSHM)
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+
+void *ngx_create_shared_memory(size_t size, ngx_log_t *log)
+{
+ int id;
+ void *p;
+
+ id = shmget(IPC_PRIVATE, size, (SHM_R|SHM_W|IPC_CREAT));
+
+ if (id == -1) {
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
+ "shmget(" SIZE_T_FMT ") failed", size);
+ return NULL;
+ }
+
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "shmget id: %d", id);
+
+ p = shmat(id, NULL, 0);
+
+ if (p == (void *) -1) {
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "shmat() failed");
+ p = NULL;
+ }
+
+ if (shmctl(id, IPC_RMID, NULL) == -1) {
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "shmctl(IPC_RMID) failed");
+ p = NULL;
+ }
+
+ return p;
+}
+
+#endif
diff --git a/src/os/unix/ngx_shared.h b/src/os/unix/ngx_shared.h
new file mode 100644
index 000000000..ca077df42
--- /dev/null
+++ b/src/os/unix/ngx_shared.h
@@ -0,0 +1,12 @@
+#ifndef _NGX_SHARED_H_INCLUDED_
+#define _NGX_SHARED_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+void *ngx_create_shared_memory(size_t size, ngx_log_t *log);
+
+
+#endif /* _NGX_SHARED_H_INCLUDED_ */
diff --git a/src/os/unix/ngx_time.h b/src/os/unix/ngx_time.h
index dbb7a0a54..7cf3d01af 100644
--- a/src/os/unix/ngx_time.h
+++ b/src/os/unix/ngx_time.h
@@ -9,7 +9,6 @@
typedef uint64_t ngx_epoch_msec_t;
typedef ngx_int_t ngx_msec_t;
-#define NGX_MAX_MSEC (ngx_msec_t) -1
typedef struct tm ngx_tm_t;
@@ -20,11 +19,7 @@ typedef struct tm ngx_tm_t;
#define ngx_tm_mon tm_mon
#define ngx_tm_year tm_year
#define ngx_tm_wday tm_wday
-#define ngx_tm_gmtoff tm_gmtoff
-
-#ifndef SOLARIS
-#define ngx_tm_zone tm_zone
-#endif
+#define ngx_tm_isdst tm_isdst
#define ngx_tm_sec_t int
#define ngx_tm_min_t int
@@ -35,16 +30,14 @@ typedef struct tm ngx_tm_t;
#define ngx_tm_wday_t int
-#if (SOLARIS)
-#define HAVE_TIMEZONE 1
-
-#define ngx_timezone() (- (daylight ? altzone : timezone) / 60)
-
-#elif defined __linux__
-#define HAVE_TIMEZONE 1
+#if (HAVE_GMTOFF)
+#define ngx_tm_gmtoff tm_gmtoff
+#define ngx_tm_zone tm_zone
+#endif
-#define ngx_timezone() (- timezone / 60 + daylight * 60)
+#if (SOLARIS)
+#define ngx_timezone(isdst) (- (isdst ? altzone : timezone) / 60)
#endif
diff --git a/src/os/win32/ngx_shared.h b/src/os/win32/ngx_shared.h
new file mode 100644
index 000000000..ca077df42
--- /dev/null
+++ b/src/os/win32/ngx_shared.h
@@ -0,0 +1,12 @@
+#ifndef _NGX_SHARED_H_INCLUDED_
+#define _NGX_SHARED_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+void *ngx_create_shared_memory(size_t size, ngx_log_t *log);
+
+
+#endif /* _NGX_SHARED_H_INCLUDED_ */
diff --git a/src/os/win32/ngx_time.c b/src/os/win32/ngx_time.c
index cef335707..85d1a3b6d 100644
--- a/src/os/win32/ngx_time.c
+++ b/src/os/win32/ngx_time.c
@@ -31,7 +31,7 @@ void ngx_gettimeofday(struct timeval *tp)
}
-ngx_int_t ngx_timezone(void)
+ngx_int_t ngx_gettimezone(void)
{
TIME_ZONE_INFORMATION tz;
diff --git a/src/os/win32/ngx_time.h b/src/os/win32/ngx_time.h
index 9ed94baeb..f86011618 100644
--- a/src/os/win32/ngx_time.h
+++ b/src/os/win32/ngx_time.h
@@ -9,7 +9,6 @@
typedef uint64_t ngx_epoch_msec_t;
typedef ngx_int_t ngx_msec_t;
-#define NGX_MAX_MSEC (ngx_msec_t) -1
typedef SYSTEMTIME ngx_tm_t;
@@ -32,11 +31,11 @@ typedef FILETIME ngx_mtime_t;
#define ngx_tm_wday_t u_short
-#define ngx_msleep Sleep
+#define ngx_msleep Sleep
-#define HAVE_TIMEZONE 1
+#define HAVE_GETIMEZONE 1
-ngx_int_t ngx_timezone(void);
+ngx_int_t ngx_gettimezone(void);
void ngx_gettimeofday(struct timeval *tp);