aboutsummaryrefslogtreecommitdiff
path: root/src/os/unix
diff options
context:
space:
mode:
Diffstat (limited to 'src/os/unix')
-rw-r--r--src/os/unix/ngx_aio_read_chain.c1
-rw-r--r--src/os/unix/ngx_aio_write_chain.c1
-rw-r--r--src/os/unix/ngx_alloc.c18
-rw-r--r--src/os/unix/ngx_errno.c3
-rw-r--r--src/os/unix/ngx_errno.h6
-rw-r--r--src/os/unix/ngx_files.c4
-rw-r--r--src/os/unix/ngx_freebsd_init.c19
-rw-r--r--src/os/unix/ngx_freebsd_rfork_thread.c19
-rw-r--r--src/os/unix/ngx_freebsd_rfork_thread.h2
-rw-r--r--src/os/unix/ngx_freebsd_sendfile_chain.c18
-rw-r--r--src/os/unix/ngx_linux_sendfile_chain.c3
-rw-r--r--src/os/unix/ngx_posix_init.c2
-rw-r--r--src/os/unix/ngx_process.c1
-rw-r--r--src/os/unix/ngx_process_cycle.c66
-rw-r--r--src/os/unix/ngx_pthread_thread.c6
-rw-r--r--src/os/unix/ngx_readv_chain.c49
-rw-r--r--src/os/unix/ngx_setproctitle.c3
-rw-r--r--src/os/unix/ngx_socket.c28
-rw-r--r--src/os/unix/ngx_solaris_sendfilev_chain.c8
-rw-r--r--src/os/unix/ngx_writev_chain.c6
20 files changed, 173 insertions, 90 deletions
diff --git a/src/os/unix/ngx_aio_read_chain.c b/src/os/unix/ngx_aio_read_chain.c
index 31793d5a4..c6f9aea84 100644
--- a/src/os/unix/ngx_aio_read_chain.c
+++ b/src/os/unix/ngx_aio_read_chain.c
@@ -16,7 +16,6 @@ ssize_t ngx_aio_read_chain(ngx_connection_t *c, ngx_chain_t *cl)
u_char *buf, *prev;
size_t size;
ssize_t total;
- ngx_err_t err;
if (c->read->pending_eof) {
c->read->ready = 0;
diff --git a/src/os/unix/ngx_aio_write_chain.c b/src/os/unix/ngx_aio_write_chain.c
index 88b2474c9..b90f8bba1 100644
--- a/src/os/unix/ngx_aio_write_chain.c
+++ b/src/os/unix/ngx_aio_write_chain.c
@@ -17,7 +17,6 @@ ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in,
off_t send, sent;
size_t len;
ssize_t n, size;
- ngx_err_t err;
ngx_chain_t *cl;
/* the maximum limit size is the maximum size_t value - the page size */
diff --git a/src/os/unix/ngx_alloc.c b/src/os/unix/ngx_alloc.c
index 258a10fa9..72cf4e42e 100644
--- a/src/os/unix/ngx_alloc.c
+++ b/src/os/unix/ngx_alloc.c
@@ -11,11 +11,13 @@
int ngx_pagesize;
-void *ngx_alloc(size_t size, ngx_log_t *log)
+void *
+ngx_alloc(size_t size, ngx_log_t *log)
{
void *p;
- if (!(p = malloc(size))) {
+ p = malloc(size);
+ if (p == NULL) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
"malloc() %uz bytes failed", size);
}
@@ -26,7 +28,8 @@ void *ngx_alloc(size_t size, ngx_log_t *log)
}
-void *ngx_calloc(size_t size, ngx_log_t *log)
+void *
+ngx_calloc(size_t size, ngx_log_t *log)
{
void *p;
@@ -42,7 +45,8 @@ void *ngx_calloc(size_t size, ngx_log_t *log)
#if (NGX_HAVE_POSIX_MEMALIGN)
-void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
+void *
+ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
{
void *p;
@@ -60,11 +64,13 @@ void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
#elif (NGX_HAVE_MEMALIGN)
-void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
+void *
+ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
{
void *p;
- if (!(p = memalign(alignment, size))) {
+ p = memalign(alignment, size);
+ if (p == NULL) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
"memalign() %uz bytes aligned to %uz failed",
size, alignment);
diff --git a/src/os/unix/ngx_errno.c b/src/os/unix/ngx_errno.c
index 607b361d9..a3addf00c 100644
--- a/src/os/unix/ngx_errno.c
+++ b/src/os/unix/ngx_errno.c
@@ -34,8 +34,7 @@ u_char *ngx_strerror_r(int err, u_char *errstr, size_t size)
u_char *ngx_strerror_r(int err, u_char *errstr, size_t size)
{
- char *str;
- size_t len;
+ char *str;
if (size == 0) {
return 0;
diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h
index c1c5801d3..51d608bf4 100644
--- a/src/os/unix/ngx_errno.h
+++ b/src/os/unix/ngx_errno.h
@@ -25,7 +25,7 @@ typedef int ngx_err_t;
#define NGX_ENOTDIR ENOTDIR
#define NGX_EINVAL EINVAL
#define NGX_EPIPE EPIPE
-#define NGX_EAGAIN EWOULDBLOCK
+#define NGX_EAGAIN EAGAIN
#define NGX_EINPROGRESS EINPROGRESS
#define NGX_EADDRINUSE EADDRINUSE
#define NGX_ECONNABORTED ECONNABORTED
@@ -52,10 +52,10 @@ u_char *ngx_strerror_r(int err, u_char *errstr, size_t size);
#else
-/* Solaris has threads-safe strerror() */
+/* Solaris has thread-safe strerror() */
#define ngx_strerror_r(err, errstr, size) \
- ngx_cpystrn(errstr, (u_char *) strerror(err), size)
+ ngx_cpystrn(errstr, (u_char *) strerror(err), size)
#endif
diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c
index e67b2cac7..f8f98c7fe 100644
--- a/src/os/unix/ngx_files.c
+++ b/src/os/unix/ngx_files.c
@@ -131,7 +131,6 @@ ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl,
u_char *prev;
size_t size;
ssize_t n;
- ngx_err_t err;
ngx_array_t vec;
struct iovec *iov, iovs[NGX_IOVS];
@@ -162,7 +161,8 @@ ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl,
iov->iov_len += cl->buf->last - cl->buf->pos;
} else {
- if (!(iov = ngx_array_push(&vec))) {
+ iov = ngx_array_push(&vec);
+ if (iov == NULL) {
return NGX_ERROR;
}
diff --git a/src/os/unix/ngx_freebsd_init.c b/src/os/unix/ngx_freebsd_init.c
index 044d9d5c9..7defb4676 100644
--- a/src/os/unix/ngx_freebsd_init.c
+++ b/src/os/unix/ngx_freebsd_init.c
@@ -14,6 +14,7 @@ char ngx_freebsd_kern_osrelease[128];
int ngx_freebsd_kern_osreldate;
int ngx_freebsd_hw_ncpu;
int ngx_freebsd_net_inet_tcp_sendspace;
+int ngx_freebsd_kern_ipc_somaxconn;
/* FreeBSD 4.9 */
int ngx_freebsd_machdep_hlt_logical_cpus;
@@ -61,6 +62,10 @@ sysctl_t sysctls[] = {
&ngx_freebsd_net_inet_tcp_sendspace,
sizeof(int), 0 },
+ { "kern.ipc.somaxconn",
+ &ngx_freebsd_kern_ipc_somaxconn,
+ sizeof(int), 0 },
+
{ "kern.ipc.zero_copy.send",
&ngx_freebsd_kern_ipc_zero_copy_send,
sizeof(int), 0 },
@@ -85,7 +90,7 @@ void ngx_debug_init()
ngx_int_t ngx_os_init(ngx_log_t *log)
{
- int version;
+ int version, somaxconn;
size_t size;
ngx_err_t err;
ngx_uint_t i;
@@ -203,6 +208,18 @@ ngx_int_t ngx_os_init(ngx_log_t *log)
ngx_ncpu = ngx_freebsd_hw_ncpu;
}
+ if (version < 600008) {
+ somaxconn = 32767;
+ } else {
+ somaxconn = 65535;
+ }
+
+ if (ngx_freebsd_kern_ipc_somaxconn > somaxconn) {
+ ngx_log_error(NGX_LOG_ALERT, log, 0,
+ "sysctl kern.ipc.somaxconn must be no more than %d",
+ somaxconn);
+ return NGX_ERROR;
+ }
ngx_tcp_nodelay_and_tcp_nopush = 1;
diff --git a/src/os/unix/ngx_freebsd_rfork_thread.c b/src/os/unix/ngx_freebsd_rfork_thread.c
index 5dfd46807..b7e803b3c 100644
--- a/src/os/unix/ngx_freebsd_rfork_thread.c
+++ b/src/os/unix/ngx_freebsd_rfork_thread.c
@@ -227,13 +227,15 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle)
/* create the thread errno' array */
- if (!(errnos = ngx_calloc(n * sizeof(int), cycle->log))) {
+ errnos = ngx_calloc(n * sizeof(int), cycle->log);
+ if (errnos == NULL) {
return NGX_ERROR;
}
/* create the thread tids array */
- if (!(tids = ngx_calloc((n + 1) * sizeof(ngx_tid_t), cycle->log))) {
+ tids = ngx_calloc((n + 1) * sizeof(ngx_tid_t), cycle->log);
+ if (tids == NULL) {
return NGX_ERROR;
}
@@ -264,8 +266,7 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle)
ngx_tid_t ngx_thread_self()
{
- int tid;
- ngx_tid_t pid;
+ ngx_int_t tid;
tid = ngx_gettid();
@@ -305,7 +306,8 @@ ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags)
ngx_mutex_t *m;
union semun op;
- if (!(m = ngx_alloc(sizeof(ngx_mutex_t), log))) {
+ m = ngx_alloc(sizeof(ngx_mutex_t), log);
+ if (m == NULL) {
return NULL;
}
@@ -353,7 +355,7 @@ void ngx_mutex_destroy(ngx_mutex_t *m)
ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
{
- uint32_t lock, new, old;
+ uint32_t lock, old;
ngx_uint_t tries;
struct sembuf op;
@@ -483,7 +485,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
{
- uint32_t lock, new, old;
+ uint32_t lock, old;
struct sembuf op;
if (!ngx_threaded) {
@@ -576,7 +578,8 @@ ngx_cond_t *ngx_cond_init(ngx_log_t *log)
{
ngx_cond_t *cv;
- if (!(cv = ngx_alloc(sizeof(ngx_cond_t), log))) {
+ cv = ngx_alloc(sizeof(ngx_cond_t), log);
+ if (cv == NULL) {
return NULL;
}
diff --git a/src/os/unix/ngx_freebsd_rfork_thread.h b/src/os/unix/ngx_freebsd_rfork_thread.h
index 2af0adb80..215d2dc86 100644
--- a/src/os/unix/ngx_freebsd_rfork_thread.h
+++ b/src/os/unix/ngx_freebsd_rfork_thread.h
@@ -56,7 +56,7 @@ extern char *ngx_freebsd_kern_usrstack;
extern size_t ngx_thread_stack_size;
-static inline int ngx_gettid()
+static ngx_inline ngx_int_t ngx_gettid()
{
char *sp;
diff --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c
index 50cad3090..a29aaf3c9 100644
--- a/src/os/unix/ngx_freebsd_sendfile_chain.c
+++ b/src/os/unix/ngx_freebsd_sendfile_chain.c
@@ -21,19 +21,19 @@
* to postpone the sending - it not only sends a header and the first part of
* the file in one packet, but also sends the file pages in the full packets.
*
- * But until FreeBSD 4.5 the turning TCP_NOPUSH off does not flush a pending
- * data that less than MSS so that data may be sent with 5 second delay.
- * So we do not use TCP_NOPUSH on FreeBSD prior to 4.5 although it can be used
+ * But until FreeBSD 4.5 turning TCP_NOPUSH off does not flush a pending
+ * data that less than MSS, so that data may be sent with 5 second delay.
+ * So we do not use TCP_NOPUSH on FreeBSD prior to 4.5, although it can be used
* for non-keepalive HTTP connections.
*/
#define NGX_HEADERS 8
-#define NGX_TRAILERS 4
+#define NGX_TRAILERS 8
-ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
- off_t limit)
+ngx_chain_t *
+ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
{
int rc;
u_char *prev;
@@ -123,7 +123,8 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
iov->iov_len += (size_t) size;
} else {
- if (!(iov = ngx_array_push(&header))) {
+ iov = ngx_array_push(&header);
+ if (iov == NULL) {
return NGX_CHAIN_ERROR;
}
@@ -197,7 +198,8 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
iov->iov_len += (size_t) size;
} else {
- if (!(iov = ngx_array_push(&trailer))) {
+ iov = ngx_array_push(&trailer);
+ if (iov == NULL) {
return NGX_CHAIN_ERROR;
}
diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c
index ac8c303eb..9ddac673a 100644
--- a/src/os/unix/ngx_linux_sendfile_chain.c
+++ b/src/os/unix/ngx_linux_sendfile_chain.c
@@ -121,7 +121,8 @@ ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
iov->iov_len += (size_t) size;
} else {
- if (!(iov = ngx_array_push(&header))) {
+ iov = ngx_array_push(&header);
+ if (iov == NULL) {
return NGX_CHAIN_ERROR;
}
diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c
index 4fb512665..d48343b30 100644
--- a/src/os/unix/ngx_posix_init.c
+++ b/src/os/unix/ngx_posix_init.c
@@ -182,7 +182,7 @@ void ngx_signal_handler(int signo)
case ngx_signal_value(NGX_NOACCEPT_SIGNAL):
ngx_noaccept = 1;
- action = ", stop the accepting connections";
+ action = ", stop accepting connections";
break;
case ngx_signal_value(NGX_RECONFIGURE_SIGNAL):
diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c
index 0825c5f3a..0562a4644 100644
--- a/src/os/unix/ngx_process.c
+++ b/src/os/unix/ngx_process.c
@@ -214,7 +214,6 @@ void ngx_process_get_status()
ngx_err_t err;
ngx_int_t i;
ngx_uint_t one;
- struct timeval tv;
one = 0;
diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
index a48880914..9c5a7ee15 100644
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -11,7 +11,7 @@
static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n,
- ngx_int_t type);
+ ngx_int_t type);
static void ngx_start_garbage_collector(ngx_cycle_t *cycle, ngx_int_t type);
static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo);
static ngx_uint_t ngx_reap_childs(ngx_cycle_t *cycle);
@@ -23,7 +23,9 @@ static void ngx_channel_handler(ngx_event_t *ev);
static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle);
static void *ngx_worker_thread_cycle(void *data);
#endif
+#if 0
static void ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data);
+#endif
ngx_uint_t ngx_process;
@@ -59,7 +61,8 @@ ngx_int_t ngx_threads_n;
u_char master_process[] = "master process";
-void ngx_master_process_cycle(ngx_cycle_t *cycle)
+void
+ngx_master_process_cycle(ngx_cycle_t *cycle)
{
char *title;
u_char *p;
@@ -254,7 +257,8 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle)
}
-void ngx_single_process_cycle(ngx_cycle_t *cycle)
+void
+ngx_single_process_cycle(ngx_cycle_t *cycle)
{
ngx_uint_t i;
@@ -300,8 +304,8 @@ void ngx_single_process_cycle(ngx_cycle_t *cycle)
}
-static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n,
- ngx_int_t type)
+static void
+ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, ngx_int_t type)
{
ngx_int_t i;
ngx_channel_t ch;
@@ -359,12 +363,12 @@ static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n,
}
-static void ngx_start_garbage_collector(ngx_cycle_t *cycle, ngx_int_t type)
+static void
+ngx_start_garbage_collector(ngx_cycle_t *cycle, ngx_int_t type)
{
- ngx_int_t i;
- ngx_channel_t ch;
-
- return;
+#if 0
+ ngx_int_t i;
+ ngx_channel_t ch;
ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "start garbage collector");
@@ -397,16 +401,17 @@ static void ngx_start_garbage_collector(ngx_cycle_t *cycle, ngx_int_t type)
ngx_write_channel(ngx_processes[i].channel[0],
&ch, sizeof(ngx_channel_t), cycle->log);
}
+#endif
}
-static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo)
+static void
+ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo)
{
ngx_int_t i;
ngx_err_t err;
ngx_channel_t ch;
-
switch (signo) {
case ngx_signal_value(NGX_SHUTDOWN_SIGNAL):
@@ -492,7 +497,8 @@ static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo)
}
-static ngx_uint_t ngx_reap_childs(ngx_cycle_t *cycle)
+static ngx_uint_t
+ngx_reap_childs(ngx_cycle_t *cycle)
{
ngx_int_t i, n;
ngx_uint_t live;
@@ -619,7 +625,8 @@ static ngx_uint_t ngx_reap_childs(ngx_cycle_t *cycle)
}
-static void ngx_master_exit(ngx_cycle_t *cycle)
+static void
+ngx_master_exit(ngx_cycle_t *cycle)
{
ngx_delete_pidfile(cycle);
@@ -631,11 +638,14 @@ static void ngx_master_exit(ngx_cycle_t *cycle)
}
-static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
+static void
+ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
{
+#if (NGX_THREADS)
ngx_int_t n;
ngx_err_t err;
ngx_core_conf_t *ccf;
+#endif
ngx_worker_process_init(cycle, 1);
@@ -668,7 +678,9 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
for (n = 0; n < ngx_threads_n; n++) {
- if (!(ngx_threads[n].cv = ngx_cond_init(cycle->log))) {
+ ngx_threads[n].cv = ngx_cond_init(cycle->log);
+
+ if (ngx_threads[n].cv == NULL) {
/* fatal */
exit(2);
}
@@ -748,7 +760,8 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
}
-static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
+static void
+ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
{
sigset_t set;
ngx_int_t n;
@@ -873,7 +886,8 @@ static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
}
-static void ngx_channel_handler(ngx_event_t *ev)
+static void
+ngx_channel_handler(ngx_event_t *ev)
{
ngx_int_t n;
ngx_channel_t ch;
@@ -952,7 +966,8 @@ static void ngx_channel_handler(ngx_event_t *ev)
#if (NGX_THREADS)
-static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle)
+static void
+ngx_wakeup_worker_threads(ngx_cycle_t *cycle)
{
ngx_int_t i;
ngx_uint_t live;
@@ -994,7 +1009,8 @@ static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle)
}
-static void *ngx_worker_thread_cycle(void *data)
+static void *
+ngx_worker_thread_cycle(void *data)
{
ngx_thread_t *thr = data;
@@ -1022,7 +1038,8 @@ static void *ngx_worker_thread_cycle(void *data)
ngx_setthrtitle("worker thread");
- if (!(tls = ngx_calloc(sizeof(ngx_core_tls_t), cycle->log))) {
+ tls = ngx_calloc(sizeof(ngx_core_tls_t), cycle->log);
+ if (tls == NULL) {
return (void *) 1;
}
@@ -1077,7 +1094,10 @@ static void *ngx_worker_thread_cycle(void *data)
#endif
-static void ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data)
+#if 0
+
+static void
+ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data)
{
ngx_uint_t i;
ngx_gc_t ctx;
@@ -1123,3 +1143,5 @@ static void ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data)
ngx_process_events(cycle);
}
}
+
+#endif
diff --git a/src/os/unix/ngx_pthread_thread.c b/src/os/unix/ngx_pthread_thread.c
index 4903d5e50..0b55c7192 100644
--- a/src/os/unix/ngx_pthread_thread.c
+++ b/src/os/unix/ngx_pthread_thread.c
@@ -75,7 +75,8 @@ ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags)
int err;
ngx_mutex_t *m;
- if (!(m = ngx_alloc(sizeof(ngx_mutex_t), log))) {
+ m = ngx_alloc(sizeof(ngx_mutex_t), log);
+ if (m == NULL) {
return NULL;
}
@@ -189,7 +190,8 @@ ngx_cond_t *ngx_cond_init(ngx_log_t *log)
int err;
ngx_cond_t *cv;
- if (!(cv = ngx_alloc(sizeof(ngx_cond_t), log))) {
+ cv = ngx_alloc(sizeof(ngx_cond_t), log);
+ if (cv == NULL) {
return NULL;
}
diff --git a/src/os/unix/ngx_readv_chain.c b/src/os/unix/ngx_readv_chain.c
index 7c57b7abe..47d8f3b7c 100644
--- a/src/os/unix/ngx_readv_chain.c
+++ b/src/os/unix/ngx_readv_chain.c
@@ -9,16 +9,20 @@
#include <ngx_event.h>
+#define NGX_IOVS 16
+
+
#if (NGX_HAVE_KQUEUE)
-ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
+ssize_t
+ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
{
u_char *prev;
ssize_t n, size;
ngx_err_t err;
- ngx_array_t io;
+ ngx_array_t vec;
ngx_event_t *rev;
- struct iovec *iov;
+ struct iovec *iov, iovs[NGX_IOVS];
rev = c->read;
@@ -53,7 +57,11 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
iov = NULL;
size = 0;
- ngx_init_array(io, c->pool, 10, sizeof(struct iovec), NGX_ERROR);
+ vec.elts = iovs;
+ vec.nelts = 0;
+ vec.size = sizeof(struct iovec);
+ vec.nalloc = NGX_IOVS;
+ vec.pool = c->pool;
/* coalesce the neighbouring bufs */
@@ -62,7 +70,11 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
iov->iov_len += chain->buf->end - chain->buf->last;
} else {
- ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR);
+ iov = ngx_array_push(&vec);
+ if (iov == NULL) {
+ return NGX_ERROR;
+ }
+
iov->iov_base = (void *) chain->buf->last;
iov->iov_len = chain->buf->end - chain->buf->last;
}
@@ -73,12 +85,12 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
}
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "readv: %d, last:%d", io.nelts, iov->iov_len);
+ "readv: %d, last:%d", vec.nelts, iov->iov_len);
rev = c->read;
do {
- n = readv(c->fd, (struct iovec *) io.elts, io.nelts);
+ n = readv(c->fd, (struct iovec *) vec.elts, vec.nelts);
if (n >= 0) {
if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
@@ -138,20 +150,25 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
#else /* ! NGX_HAVE_KQUEUE */
-ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
+ssize_t
+ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
{
u_char *prev;
ssize_t n, size;
ngx_err_t err;
- ngx_array_t io;
+ ngx_array_t vec;
ngx_event_t *rev;
- struct iovec *iov;
+ struct iovec *iov, iovs[NGX_IOVS];
prev = NULL;
iov = NULL;
size = 0;
- ngx_init_array(io, c->pool, 10, sizeof(struct iovec), NGX_ERROR);
+ vec.elts = iovs;
+ vec.nelts = 0;
+ vec.size = sizeof(struct iovec);
+ vec.nalloc = NGX_IOVS;
+ vec.pool = c->pool;
/* coalesce the neighbouring bufs */
@@ -160,7 +177,11 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
iov->iov_len += chain->buf->end - chain->buf->last;
} else {
- ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR);
+ iov = ngx_array_push(&vec);
+ if (iov == NULL) {
+ return NGX_ERROR;
+ }
+
iov->iov_base = chain->buf->last;
iov->iov_len = chain->buf->end - chain->buf->last;
}
@@ -171,12 +192,12 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
}
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "readv: %d:%d", io.nelts, iov->iov_len);
+ "readv: %d:%d", vec.nelts, iov->iov_len);
rev = c->read;
do {
- n = readv(c->fd, (struct iovec *) io.elts, io.nelts);
+ n = readv(c->fd, (struct iovec *) vec.elts, vec.nelts);
if (n == 0) {
rev->ready = 0;
diff --git a/src/os/unix/ngx_setproctitle.c b/src/os/unix/ngx_setproctitle.c
index 6c95cdf4e..25bbc9b1e 100644
--- a/src/os/unix/ngx_setproctitle.c
+++ b/src/os/unix/ngx_setproctitle.c
@@ -43,7 +43,8 @@ ngx_init_setproctitle(ngx_log_t *log)
size += ngx_strlen(environ[i]) + 1;
}
- if (!(p = ngx_alloc(size, log))) {
+ p = ngx_alloc(size, log);
+ if (p == NULL) {
return NGX_ERROR;
}
diff --git a/src/os/unix/ngx_socket.c b/src/os/unix/ngx_socket.c
index 523f1f4ce..121958977 100644
--- a/src/os/unix/ngx_socket.c
+++ b/src/os/unix/ngx_socket.c
@@ -22,7 +22,8 @@
#if (NGX_HAVE_FIONBIO)
-int ngx_nonblocking(ngx_socket_t s)
+int
+ngx_nonblocking(ngx_socket_t s)
{
u_long nb;
@@ -32,7 +33,8 @@ int ngx_nonblocking(ngx_socket_t s)
}
-int ngx_blocking(ngx_socket_t s)
+int
+ngx_blocking(ngx_socket_t s)
{
u_long nb;
@@ -46,7 +48,8 @@ int ngx_blocking(ngx_socket_t s)
#if (NGX_FREEBSD)
-int ngx_tcp_nopush(ngx_socket_t s)
+int
+ngx_tcp_nopush(ngx_socket_t s)
{
int tcp_nopush;
@@ -57,7 +60,8 @@ int ngx_tcp_nopush(ngx_socket_t s)
}
-int ngx_tcp_push(ngx_socket_t s)
+int
+ngx_tcp_push(ngx_socket_t s)
{
int tcp_nopush;
@@ -69,7 +73,8 @@ int ngx_tcp_push(ngx_socket_t s)
#elif (NGX_LINUX)
-int ngx_tcp_nopush(ngx_socket_t s)
+int
+ngx_tcp_nopush(ngx_socket_t s)
{
int cork;
@@ -79,7 +84,8 @@ int ngx_tcp_nopush(ngx_socket_t s)
(const void *) &cork, sizeof(int));
}
-int ngx_tcp_push(ngx_socket_t s)
+int
+ngx_tcp_push(ngx_socket_t s)
{
int cork;
@@ -91,14 +97,16 @@ int ngx_tcp_push(ngx_socket_t s)
#else
-int ngx_tcp_nopush(ngx_socket_t s)
+int
+ngx_tcp_nopush(ngx_socket_t s)
{
- return NGX_OK;
+ return 0;
}
-int ngx_tcp_push(ngx_socket_t s)
+int
+ngx_tcp_push(ngx_socket_t s)
{
- return NGX_OK;
+ return 0;
}
#endif
diff --git a/src/os/unix/ngx_solaris_sendfilev_chain.c b/src/os/unix/ngx_solaris_sendfilev_chain.c
index c5b812091..4345385e3 100644
--- a/src/os/unix/ngx_solaris_sendfilev_chain.c
+++ b/src/os/unix/ngx_solaris_sendfilev_chain.c
@@ -47,7 +47,7 @@ ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in,
sendfilevec_t *sfv, sfvs[NGX_SENDFILEVECS];
ngx_array_t vec;
ngx_event_t *wev;
- ngx_chain_t *cl, *tail;
+ ngx_chain_t *cl;
wev = c->write;
@@ -107,7 +107,8 @@ ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in,
sfv->sfv_len += (size_t) size;
} else {
- if (!(sfv = ngx_array_push(&vec))) {
+ sfv = ngx_array_push(&vec);
+ if (sfv == NULL) {
return NGX_CHAIN_ERROR;
}
@@ -140,7 +141,8 @@ ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in,
sfv->sfv_len += (size_t) size;
} else {
- if (!(sfv = ngx_array_push(&vec))) {
+ sfv = ngx_array_push(&vec);
+ if (sfv == NULL) {
return NGX_CHAIN_ERROR;
}
diff --git a/src/os/unix/ngx_writev_chain.c b/src/os/unix/ngx_writev_chain.c
index 9cbcd864d..ed3ad7158 100644
--- a/src/os/unix/ngx_writev_chain.c
+++ b/src/os/unix/ngx_writev_chain.c
@@ -12,7 +12,8 @@
#define NGX_IOVS 16
-ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
+ngx_chain_t *
+ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
{
u_char *prev;
ssize_t n, size, sent;
@@ -88,7 +89,8 @@ ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
iov->iov_len += size;
} else {
- if (!(iov = ngx_array_push(&vec))) {
+ iov = ngx_array_push(&vec);
+ if (iov == NULL) {
return NGX_CHAIN_ERROR;
}