mirror of
https://github.com/nginx/nginx.git
synced 2026-08-27 04:07:18 +00:00
nginx-0.0.2-2004-02-09-10:46:43 import
This commit is contained in:
parent
9260294400
commit
7af6b16936
32 changed files with 304 additions and 248 deletions
|
|
@ -377,8 +377,11 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
|||
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
|
||||
"can not respawn %s",
|
||||
ngx_processes[i].name);
|
||||
continue;
|
||||
}
|
||||
|
||||
live = 1;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -443,7 +446,7 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
|||
|
||||
if (ngx_reopen) {
|
||||
if (ngx_process == NGX_PROCESS_MASTER) {
|
||||
if (ccf->worker_reopen > 0) {
|
||||
if (ccf->worker_reopen != 0) {
|
||||
signo = ngx_signal_value(NGX_REOPEN_SIGNAL);
|
||||
ngx_reopen = 0;
|
||||
|
||||
|
|
@ -461,7 +464,7 @@ static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
|
|||
ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
|
||||
"reopening logs");
|
||||
ngx_reopen_files(cycle,
|
||||
ccf->worker_reopen > 0 ? ccf->user : -1);
|
||||
ccf->worker_reopen != 0 ? ccf->user : (uid_t) -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -574,6 +577,17 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
|
|||
}
|
||||
}
|
||||
|
||||
#if (HAVE_PR_SET_DUMPABLE)
|
||||
|
||||
/* allow coredump after setuid() in Linux 2.4.x */
|
||||
|
||||
if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
||||
"prctl(PR_SET_DUMPABLE) failed");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
sigemptyset(&set);
|
||||
|
||||
if (sigprocmask(SIG_SETMASK, &set, NULL) == -1) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define _NGX_CONFIG_H_INCLUDED_
|
||||
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
/* STUB to allocate a big ngx_connections */
|
||||
#undef FD_SETSIZE
|
||||
#define FD_SETSIZE 5000
|
||||
|
|
|
|||
|
|
@ -48,11 +48,6 @@ ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle)
|
|||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
/* STUB: autoconf & set sin_len in ls[i].sockaddr in ngx_http.c */
|
||||
#if __FreeBSD__
|
||||
addr_in->sin_len = 0;
|
||||
#endif
|
||||
|
||||
ls[i].family = addr_in->sin_family;
|
||||
ls[i].addr_text.len = ngx_sock_ntop(ls[i].family, ls[i].sockaddr,
|
||||
ls[i].addr_text.data,
|
||||
|
|
@ -68,11 +63,11 @@ ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle)
|
|||
|
||||
ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
|
||||
{
|
||||
int tries, failed, reuseaddr, i;
|
||||
ngx_err_t err;
|
||||
ngx_log_t *log;
|
||||
ngx_socket_t s;
|
||||
ngx_listening_t *ls;
|
||||
ngx_int_t tries, failed, reuseaddr, i;
|
||||
ngx_err_t err;
|
||||
ngx_log_t *log;
|
||||
ngx_socket_t s;
|
||||
ngx_listening_t *ls;
|
||||
|
||||
reuseaddr = 1;
|
||||
#if (NGX_SUPPRESS_WARN)
|
||||
|
|
@ -241,3 +236,39 @@ void ngx_close_listening_sockets(ngx_cycle_t *cycle)
|
|||
cycle->connections[fd].fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
|
||||
{
|
||||
ngx_int_t level;
|
||||
|
||||
if (err == NGX_ECONNRESET
|
||||
&& c->read->log_error == NGX_ERROR_IGNORE_ECONNRESET)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (err == NGX_ECONNRESET || err == NGX_EPIPE || err == NGX_ENOTCONN) {
|
||||
|
||||
switch (c->read->log_error) {
|
||||
|
||||
case NGX_ERROR_INFO:
|
||||
level = NGX_LOG_INFO;
|
||||
break;
|
||||
|
||||
case NGX_ERROR_ERR:
|
||||
level = NGX_LOG_ERR;
|
||||
break;
|
||||
|
||||
default:
|
||||
level = NGX_LOG_CRIT;
|
||||
}
|
||||
|
||||
} else {
|
||||
level = NGX_LOG_CRIT;
|
||||
}
|
||||
|
||||
ngx_log_error(level, c->log, err, text);
|
||||
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ struct ngx_connection_s {
|
|||
ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle);
|
||||
ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle);
|
||||
void ngx_close_listening_sockets(ngx_cycle_t *cycle);
|
||||
ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text);
|
||||
|
||||
|
||||
extern ngx_os_io_t ngx_io;
|
||||
|
|
|
|||
|
|
@ -202,11 +202,11 @@ static int ngx_epoll_add_event(ngx_event_t *ev, int event, u_int flags)
|
|||
}
|
||||
#endif
|
||||
|
||||
ee.events = event;
|
||||
ee.events = event|EPOLLET;
|
||||
ee.data.ptr = (void *) ((uintptr_t) c | c->read->instance);
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||
"epoll add event: fd:%d ev:%04X", c->fd, ee.events);
|
||||
"epoll add event: fd:%d ev:%08X", c->fd, ee.events);
|
||||
|
||||
if (epoll_ctl(ep, EPOLL_CTL_ADD, c->fd, &ee) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
|
||||
|
|
@ -230,8 +230,8 @@ static int ngx_epoll_del_event(ngx_event_t *ev, int event, u_int flags)
|
|||
ee.events = 0;
|
||||
ee.data.ptr = NULL;
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||
"epoll del event: fd:%d ev:%04X", c->fd, ee.events);
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||
"epoll del event: fd:%d", c->fd);
|
||||
|
||||
if (epoll_ctl(ep, EPOLL_CTL_DEL, c->fd, &ee) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
|
||||
|
|
@ -249,11 +249,11 @@ static int ngx_epoll_add_connection(ngx_connection_t *c)
|
|||
{
|
||||
struct epoll_event ee;
|
||||
|
||||
ee.events = EPOLLIN|EPOLLOUT;
|
||||
ee.events = EPOLLIN|EPOLLOUT|EPOLLET;
|
||||
ee.data.ptr = (void *) ((uintptr_t) c | c->read->instance);
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||
"epoll add connection: fd:%d ev:%04X", c->fd, ee.events);
|
||||
"epoll add connection: fd:%d ev:%08X", c->fd, ee.events);
|
||||
|
||||
if (epoll_ctl(ep, EPOLL_CTL_ADD, c->fd, &ee) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
|
||||
|
|
@ -355,9 +355,9 @@ int ngx_epoll_process_events(ngx_log_t *log)
|
|||
}
|
||||
|
||||
if (event_list[i].events & (EPOLLERR|EPOLLHUP)) {
|
||||
ngx_log_error(NGX_LOG_ALERT, log, 0,
|
||||
"epoll_wait() error on fd:%d ev:%d",
|
||||
c->fd, event_list[i].events);
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0,
|
||||
"epoll_wait() error on fd:%d ev:%04X",
|
||||
c->fd, event_list[i].events);
|
||||
}
|
||||
|
||||
if (event_list[i].events & ~(EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP)) {
|
||||
|
|
|
|||
|
|
@ -286,7 +286,8 @@ static int ngx_poll_process_events(ngx_log_t *log)
|
|||
delta = ngx_elapsed_msec;
|
||||
ngx_elapsed_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000 - ngx_start_msec;
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "poll ready %d", ready);
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0,
|
||||
"poll ready %d of %d", ready, nevents);
|
||||
|
||||
if (err) {
|
||||
ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT,
|
||||
|
|
|
|||
|
|
@ -459,6 +459,12 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
|
|||
ngx_conf_init_value(ecf->use, ngx_devpoll_module.ctx_index);
|
||||
ngx_conf_init_ptr_value(ecf->name, ngx_devpoll_module_ctx.name->data);
|
||||
|
||||
#elif (HAVE_EPOLL)
|
||||
|
||||
ngx_conf_init_value(ecf->connections, DEFAULT_CONNECTIONS);
|
||||
ngx_conf_init_value(ecf->use, ngx_epoll_module.ctx_index);
|
||||
ngx_conf_init_ptr_value(ecf->name, ngx_epoll_module_ctx.name->data);
|
||||
|
||||
#else /* HAVE_SELECT */
|
||||
|
||||
ngx_conf_init_value(ecf->connections,
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ void ngx_event_accept(ngx_event_t *ev)
|
|||
}
|
||||
|
||||
} else {
|
||||
if ((ngx_event_flags & NGX_USE_AIO_EVENT) == 0) {
|
||||
if (!(ngx_event_flags & NGX_USE_AIO_EVENT)) {
|
||||
if (ngx_nonblocking(s) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno,
|
||||
ngx_nonblocking_n " failed");
|
||||
|
|
|
|||
|
|
@ -87,8 +87,8 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
|
|||
}
|
||||
|
||||
/*
|
||||
* there is a valid cached open file, i.e by index handler,
|
||||
* and it must be already registered in r->cleanup
|
||||
* there is a valid cached open file, i.e by the index handler,
|
||||
* and it should be already registered in r->cleanup
|
||||
*/
|
||||
|
||||
if (r->cache && !r->cache->expired) {
|
||||
|
|
@ -100,13 +100,14 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
|
|||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||
|
||||
/*
|
||||
* make a file name
|
||||
* 2 bytes is for a trailing '/' in a possible redirect and for '\0'
|
||||
* make a file name, reserve 2 bytes for a trailing '/'
|
||||
* in a possible redirect and for the last '\0'
|
||||
*/
|
||||
|
||||
ngx_test_null(name.data,
|
||||
ngx_palloc(r->pool, clcf->doc_root.len + r->uri.len + 2),
|
||||
NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||
name.data = ngx_palloc(r->pool, clcf->doc_root.len + r->uri.len + 2);
|
||||
if (name.data == NULL) {
|
||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
|
||||
location.data = ngx_cpymem(name.data, clcf->doc_root.data,
|
||||
clcf->doc_root.len);
|
||||
|
|
|
|||
|
|
@ -483,6 +483,9 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||
ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)),
|
||||
NGX_CONF_ERROR);
|
||||
|
||||
#if (HAVE_SIN_LEN)
|
||||
addr_in->sin_len = sizeof(struct sockaddr_in);
|
||||
#endif
|
||||
addr_in->sin_family = AF_INET;
|
||||
addr_in->sin_addr.s_addr = in_addr[a].addr;
|
||||
addr_in->sin_port = htons((u_short) in_port[p].port);
|
||||
|
|
|
|||
|
|
@ -1217,10 +1217,10 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
|
|||
prev->default_type, "text/plain");
|
||||
|
||||
ngx_conf_merge_msec_value(conf->client_body_timeout,
|
||||
prev->client_body_timeout, 10000);
|
||||
prev->client_body_timeout, 60000);
|
||||
ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
|
||||
ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
|
||||
ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 10000);
|
||||
ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
|
||||
ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
|
||||
ngx_conf_merge_size_value(conf->discarded_buffer_size,
|
||||
prev->discarded_buffer_size, 1500);
|
||||
|
|
|
|||
|
|
@ -84,6 +84,8 @@ void ngx_http_init_connection(ngx_connection_t *c)
|
|||
rev->event_handler = ngx_http_init_request;
|
||||
rev->log_error = NGX_ERROR_INFO;
|
||||
|
||||
/* STUB: epoll */ c->write->event_handler = ngx_http_empty_handler;
|
||||
|
||||
if (rev->ready) {
|
||||
/* deferred accept, aio, iocp, epoll */
|
||||
ngx_http_init_request(rev);
|
||||
|
|
@ -160,7 +162,7 @@ static void ngx_http_init_request(ngx_event_t *rev)
|
|||
if (in_port->addrs.nelts > 1) {
|
||||
|
||||
/*
|
||||
* There're the several addresses on this port and one of them
|
||||
* There are the several addresses on this port and one of them
|
||||
* is "*:port" so getsockname() is needed to determine
|
||||
* the server address.
|
||||
* AcceptEx() already gave this address.
|
||||
|
|
@ -215,8 +217,8 @@ static void ngx_http_init_request(ngx_event_t *rev)
|
|||
c->log->log_level = clcf->err_log->log_level;
|
||||
|
||||
if (c->buffer == NULL) {
|
||||
c->buffer =
|
||||
ngx_create_temp_hunk(c->pool, cscf->client_header_buffer_size);
|
||||
c->buffer = ngx_create_temp_hunk(c->pool,
|
||||
cscf->client_header_buffer_size);
|
||||
if (c->buffer == NULL) {
|
||||
ngx_http_close_connection(c);
|
||||
return;
|
||||
|
|
@ -918,7 +920,7 @@ void ngx_http_finalize_request(ngx_http_request_t *r, int rc)
|
|||
#if (NGX_KQUEUE)
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log,
|
||||
r->connection->read->kq_errno,
|
||||
"kevent reported about closed connection by client");
|
||||
"kevent() reported about an closed connection");
|
||||
#endif
|
||||
ngx_http_close_request(r, 0);
|
||||
ngx_http_close_connection(r->connection);
|
||||
|
|
|
|||
|
|
@ -115,8 +115,8 @@ int ngx_os_init(ngx_log_t *log)
|
|||
|
||||
/*
|
||||
* The determination of the sendfile() nbytes bug is complex enough.
|
||||
* There are two sendfile() syscalls: a new 393 has no bug while
|
||||
* an old 336 has the bug in some versions and has not in others.
|
||||
* There are two sendfile() syscalls: a new #393 has no bug while
|
||||
* an old #336 has the bug in some versions and has not in others.
|
||||
* Besides libc_r wrapper also emulates the bug in some versions.
|
||||
* There's no way to say exactly if a given FreeBSD version has the bug.
|
||||
* Here is the algorithm that works at least for RELEASEs
|
||||
|
|
|
|||
|
|
@ -5,17 +5,20 @@
|
|||
|
||||
|
||||
/*
|
||||
* FreeBSD's sendfile() often sends 4K pages over ethernet in 3 packets: 2x1460
|
||||
* and 1176 or in 6 packets: 5x1460 and 892. Besides although sendfile()
|
||||
* allows to pass the header and the trailer it never sends the header or
|
||||
* the trailer with the part of the file in one packet. So we use TCP_NOPUSH
|
||||
* (similar to Linux's TCP_CORK) to postpone the sending - it not only sends
|
||||
* the header and the first part of the file in one packet but also sends
|
||||
* 4K pages in the full packets.
|
||||
* Although FreeBSD sendfile() allows to pass a header and a trailer
|
||||
* it never sends a header with a part of the file in one packet until
|
||||
* FreeBSD 5.2-STABLE. Besides over the fast ethernet connection sendfile()
|
||||
* can send the partially filled packets, i.e. the 8 file pages can be sent
|
||||
* as 11 full 1460-bytes packets, then one incomplete 324-bytes packet, and
|
||||
* then again 11 full 1460-bytes packets.
|
||||
*
|
||||
* Until FreeBSD 4.5 the turning TCP_NOPUSH off does not flush a pending
|
||||
* So we use the TCP_NOPUSH option (similar to Linux's TCP_CORK)
|
||||
* to postpone the sending - it not only sends a header and the first part
|
||||
* of the file in one packet but also sends 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 can be sent with 5 second delay.
|
||||
* We do not use TCP_NOPUSH on FreeBSD prior to 4.5 although it can be used
|
||||
* So we do not use TCP_NOPUSH on FreeBSD prior to 4.5 although it can be used
|
||||
* for non-keepalive HTTP connections.
|
||||
*/
|
||||
|
||||
|
|
@ -26,7 +29,7 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
|
|||
char *prev;
|
||||
off_t sent, fprev;
|
||||
size_t hsize, fsize, size;
|
||||
ngx_int_t eintr, eagain, level;
|
||||
ngx_int_t eintr, eagain;
|
||||
struct iovec *iov;
|
||||
struct sf_hdtr hdtr;
|
||||
ngx_err_t err;
|
||||
|
|
@ -45,7 +48,7 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
|
|||
|
||||
if ((ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) && wev->kq_eof) {
|
||||
ngx_log_error(NGX_LOG_INFO, c->log, wev->kq_errno,
|
||||
"kevent() reported about closed connection");
|
||||
"kevent() reported about an closed connection");
|
||||
|
||||
wev->error = 1;
|
||||
return NGX_CHAIN_ERROR;
|
||||
|
|
@ -59,7 +62,6 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
|
|||
hsize = 0;
|
||||
eintr = 0;
|
||||
eagain = 0;
|
||||
level = NGX_LOG_CRIT;
|
||||
|
||||
ngx_init_array(header, c->pool, 10, sizeof(struct iovec),
|
||||
NGX_CHAIN_ERROR);
|
||||
|
|
@ -152,14 +154,26 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
|
|||
if (file) {
|
||||
|
||||
if (ngx_freebsd_use_tcp_nopush && c->tcp_nopush == 0) {
|
||||
c->tcp_nopush = 1;
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "tcp_nopush");
|
||||
|
||||
if (ngx_tcp_nopush(c->fd) == NGX_ERROR) {
|
||||
ngx_log_error(NGX_LOG_CRIT, c->log, ngx_errno,
|
||||
ngx_tcp_nopush_n " failed");
|
||||
return NGX_CHAIN_ERROR;
|
||||
err = ngx_errno;
|
||||
|
||||
/*
|
||||
* there is a tiny chance to be interrupted, however
|
||||
* we continue a processing without the TCP_NOPUSH
|
||||
*/
|
||||
|
||||
if (err != NGX_EINTR) {
|
||||
wev->error = 1;
|
||||
ngx_connection_error(c, err,
|
||||
ngx_tcp_nopush_n " failed");
|
||||
return NGX_CHAIN_ERROR;
|
||||
}
|
||||
|
||||
} else {
|
||||
c->tcp_nopush = 1;
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||
"tcp_nopush");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -185,30 +199,21 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
|
|||
if (rc == -1) {
|
||||
err = ngx_errno;
|
||||
|
||||
if (err == NGX_EINTR) {
|
||||
eintr = 1;
|
||||
|
||||
} else if (err == NGX_EAGAIN) {
|
||||
eagain = 1;
|
||||
|
||||
} else if (err == NGX_EPIPE || err == NGX_ENOTCONN) {
|
||||
level = NGX_LOG_INFO;
|
||||
}
|
||||
|
||||
if (err == NGX_EAGAIN || err == NGX_EINTR) {
|
||||
if (err == NGX_EINTR) {
|
||||
eintr = 1;
|
||||
|
||||
} else {
|
||||
eagain = 1;
|
||||
}
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, err,
|
||||
"sendfile() sent only " OFF_T_FMT " bytes",
|
||||
sent);
|
||||
|
||||
} else {
|
||||
wev->error = 1;
|
||||
#if 0
|
||||
ngx_log_error(level, c->log, err,
|
||||
"sendfile() failed");
|
||||
#else
|
||||
ngx_log_error(level, c->log, err,
|
||||
"sendfile(#%d) failed", c->fd);
|
||||
#endif
|
||||
ngx_connection_error(c, err, "sendfile() failed");
|
||||
return NGX_CHAIN_ERROR;
|
||||
}
|
||||
}
|
||||
|
|
@ -223,20 +228,17 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
|
|||
if (rc == -1) {
|
||||
err = ngx_errno;
|
||||
|
||||
if (err == NGX_EINTR) {
|
||||
eintr = 1;
|
||||
|
||||
} else if (err == NGX_EPIPE) {
|
||||
level = NGX_LOG_INFO;
|
||||
}
|
||||
|
||||
if (err == NGX_EAGAIN || err == NGX_EINTR) {
|
||||
if (err == NGX_EINTR) {
|
||||
eintr = 1;
|
||||
}
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
|
||||
"writev() not ready");
|
||||
|
||||
} else {
|
||||
wev->error = 1;
|
||||
ngx_log_error(level, c->log, err, "writev() failed");
|
||||
ngx_connection_error(c, err, "writev() failed");
|
||||
return NGX_CHAIN_ERROR;
|
||||
}
|
||||
}
|
||||
|
|
@ -292,8 +294,9 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
|
|||
|
||||
/*
|
||||
* sendfile() can return EAGAIN even if it has sent
|
||||
* a whole file part and successive sendfile() would
|
||||
* return EAGAIN right away and would not send anything
|
||||
* a whole file part but the successive sendfile() call would
|
||||
* return EAGAIN right away and would not send anything.
|
||||
* We use it as a hint.
|
||||
*/
|
||||
|
||||
wev->ready = 0;
|
||||
|
|
|
|||
|
|
@ -34,8 +34,17 @@
|
|||
#include <netdb.h>
|
||||
#include <dirent.h>
|
||||
|
||||
|
||||
/* Linux has a broken strerror_r() */
|
||||
#define HAVE_STRERROR_R 0
|
||||
|
||||
#include <ngx_auto_config.h>
|
||||
|
||||
|
||||
#if (HAVE_PRCTL)
|
||||
#include <sys/prctl.h>
|
||||
#endif
|
||||
|
||||
#if (HAVE_SENDFILE64)
|
||||
#include <sys/sendfile.h>
|
||||
#else
|
||||
|
|
@ -67,7 +76,7 @@ extern ssize_t sendfile(int s, int fd, int32_t *offset, size_t size);
|
|||
|
||||
|
||||
#ifndef HAVE_INHERITED_NONBLOCK
|
||||
#define HAVE_INHERITED_NONBLOCK 1
|
||||
#define HAVE_INHERITED_NONBLOCK 0
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
/*
|
||||
* On Linux up to 2.4.21 sendfile() (syscall #187) works with 32-bit
|
||||
* offsets only and the including <sys/sendfile.h> breaks the compiling if
|
||||
* off_t is 64 bit wide. So we use own sendfile() definition where offset
|
||||
* offsets only and the including <sys/sendfile.h> breaks the compiling
|
||||
* if off_t is 64 bit wide. So we use own sendfile() definition where offset
|
||||
* parameter is int32_t and use sendfile() with the file parts below 2G.
|
||||
*
|
||||
* Linux 2.4.21 has a new sendfile64() syscall #239.
|
||||
|
|
@ -80,14 +80,24 @@ ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
|
|||
&& cl
|
||||
&& cl->hunk->type & NGX_HUNK_FILE)
|
||||
{
|
||||
c->tcp_nopush = 1;
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "tcp_nopush");
|
||||
|
||||
if (ngx_tcp_nopush(c->fd) == NGX_ERROR) {
|
||||
ngx_log_error(NGX_LOG_CRIT, c->log, ngx_errno,
|
||||
ngx_tcp_nopush_n " failed");
|
||||
return NGX_CHAIN_ERROR;
|
||||
err = ngx_errno;
|
||||
|
||||
/*
|
||||
* there is a tiny chance to be interrupted, however
|
||||
* we continue a processing without the TCP_CORK
|
||||
*/
|
||||
|
||||
if (err != NGX_EINTR) {
|
||||
wev->error = 1;
|
||||
ngx_connection_error(c, err, ngx_tcp_nopush_n " failed");
|
||||
return NGX_CHAIN_ERROR;
|
||||
}
|
||||
|
||||
} else {
|
||||
c->tcp_nopush = 1;
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||
"tcp_nopush");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -132,51 +142,52 @@ ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
|
|||
|
||||
if (rc == -1) {
|
||||
err = ngx_errno;
|
||||
if (err == NGX_EAGAIN) {
|
||||
ngx_log_error(NGX_LOG_INFO, c->log, err,
|
||||
"sendfile() EAGAIN");
|
||||
|
||||
} else if (err == NGX_EINTR) {
|
||||
eintr = 1;
|
||||
ngx_log_error(NGX_LOG_INFO, c->log, err,
|
||||
"sendfile() EINTR");
|
||||
if (err == NGX_EAGAIN || err == NGX_EINTR) {
|
||||
if (err == NGX_EINTR) {
|
||||
eintr = 1;
|
||||
}
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
|
||||
"sendfile() is not ready");
|
||||
|
||||
} else {
|
||||
ngx_log_error(NGX_LOG_CRIT, c->log, err,
|
||||
"sendfile() failed");
|
||||
wev->error = 1;
|
||||
ngx_connection_error(c, err, "sendfile() failed");
|
||||
return NGX_CHAIN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
sent = rc > 0 ? rc : 0;
|
||||
|
||||
#if (NGX_DEBUG_WRITE_CHAIN)
|
||||
ngx_log_debug(c->log, "sendfile: %d, @" OFF_T_FMT " %d:%d" _
|
||||
rc _ file->file_pos _ sent _ fsize);
|
||||
#endif
|
||||
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||
"sendfile: %d, @" OFF_T_FMT " %d:%d",
|
||||
rc, file->file_pos, sent, fsize);
|
||||
|
||||
} else {
|
||||
rc = writev(c->fd, header.elts, header.nelts);
|
||||
|
||||
if (rc == -1) {
|
||||
err = ngx_errno;
|
||||
if (err == NGX_EAGAIN) {
|
||||
ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EAGAIN");
|
||||
|
||||
} else if (err == NGX_EINTR) {
|
||||
eintr = 1;
|
||||
ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EINTR");
|
||||
if (err == NGX_EAGAIN || err == NGX_EINTR) {
|
||||
if (err == NGX_EINTR) {
|
||||
eintr = 1;
|
||||
}
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
|
||||
"writev() not ready");
|
||||
|
||||
} else {
|
||||
ngx_log_error(NGX_LOG_CRIT, c->log, err, "writev() failed");
|
||||
return NGX_CHAIN_ERROR;
|
||||
wev->error = 1;
|
||||
ngx_connection_error(c, err, "writev() failed");
|
||||
return NGX_CHAIN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
sent = rc > 0 ? rc : 0;
|
||||
|
||||
#if (NGX_DEBUG_WRITE_CHAIN)
|
||||
ngx_log_debug(c->log, "writev: %d" _ sent);
|
||||
#endif
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "writev: %d", sent);
|
||||
}
|
||||
|
||||
c->sent += sent;
|
||||
|
|
|
|||
|
|
@ -4,14 +4,12 @@
|
|||
#include <ngx_event.h>
|
||||
|
||||
|
||||
static int ngx_unix_recv_error(ngx_event_t *rev, ngx_err_t err);
|
||||
|
||||
|
||||
#if (HAVE_KQUEUE)
|
||||
|
||||
ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size)
|
||||
{
|
||||
ssize_t n;
|
||||
ngx_err_t err;
|
||||
ngx_event_t *rev;
|
||||
|
||||
rev = c->read;
|
||||
|
|
@ -26,11 +24,12 @@ ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size)
|
|||
rev->ready = 0;
|
||||
rev->eof = 1;
|
||||
|
||||
ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno,
|
||||
"kevent() reported about an closed connection");
|
||||
|
||||
if (rev->kq_errno) {
|
||||
rev->error = 1;
|
||||
ngx_set_socket_errno(rev->kq_errno);
|
||||
ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno,
|
||||
"kevent() reported about closed connection");
|
||||
|
||||
if (rev->kq_errno == NGX_ECONNRESET
|
||||
&& rev->log_error == NGX_ERROR_IGNORE_ECONNRESET)
|
||||
|
|
@ -52,7 +51,8 @@ ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size)
|
|||
do {
|
||||
n = recv(c->fd, buf, size, 0);
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,"recv: %d:%d", n, size);
|
||||
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||
"recv: fd:%d %d of %d", c->fd, n, size);
|
||||
|
||||
if (n >= 0) {
|
||||
if (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) {
|
||||
|
|
@ -87,11 +87,19 @@ ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size)
|
|||
return n;
|
||||
}
|
||||
|
||||
n = ngx_unix_recv_error(rev, ngx_socket_errno);
|
||||
err = ngx_socket_errno;
|
||||
|
||||
} while (n == NGX_EINTR);
|
||||
if (err == NGX_EAGAIN || err == NGX_EINTR) {
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, rev->log, err,
|
||||
"recv() not ready");
|
||||
n = NGX_AGAIN;
|
||||
|
||||
/* NGX_ERROR || NGX_AGAIN */
|
||||
} else {
|
||||
n = ngx_connection_error(c, err, "recv() failed");
|
||||
break;
|
||||
}
|
||||
|
||||
} while (err == NGX_EINTR);
|
||||
|
||||
rev->ready = 0;
|
||||
|
||||
|
|
@ -107,6 +115,7 @@ ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size)
|
|||
ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size)
|
||||
{
|
||||
ssize_t n;
|
||||
ngx_err_t err;
|
||||
ngx_event_t *rev;
|
||||
|
||||
rev = c->read;
|
||||
|
|
@ -114,7 +123,8 @@ ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size)
|
|||
do {
|
||||
n = recv(c->fd, buf, size, 0);
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,"recv: %d:%d", n, size);
|
||||
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||
"recv: fd:%d %d of %d", c->fd, n, size);
|
||||
|
||||
if (n >= 0) {
|
||||
if ((size_t) n < size) {
|
||||
|
|
@ -128,11 +138,19 @@ ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size)
|
|||
return n;
|
||||
}
|
||||
|
||||
n = ngx_unix_recv_error(rev, ngx_socket_errno);
|
||||
err = ngx_socket_errno;
|
||||
|
||||
} while (n == NGX_EINTR);
|
||||
if (err == NGX_EAGAIN || err == NGX_EINTR) {
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, rev->log, err,
|
||||
"recv() not ready");
|
||||
n = NGX_AGAIN;
|
||||
|
||||
/* NGX_ERROR || NGX_AGAIN */
|
||||
} else {
|
||||
n = ngx_connection_error(c, err, "recv() failed");
|
||||
break;
|
||||
}
|
||||
|
||||
} while (err == NGX_EINTR);
|
||||
|
||||
rev->ready = 0;
|
||||
|
||||
|
|
@ -144,37 +162,3 @@ ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size)
|
|||
}
|
||||
|
||||
#endif /* NAVE_KQUEUE */
|
||||
|
||||
|
||||
static int ngx_unix_recv_error(ngx_event_t *rev, ngx_err_t err)
|
||||
{
|
||||
ngx_int_t level;
|
||||
|
||||
if (err == NGX_EAGAIN || err == NGX_EINTR) {
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, rev->log, err, "recv() not ready");
|
||||
return NGX_AGAIN;
|
||||
}
|
||||
|
||||
if (err == NGX_ECONNRESET) {
|
||||
|
||||
switch (rev->log_error) {
|
||||
case NGX_ERROR_IGNORE_ECONNRESET:
|
||||
return 0;
|
||||
case NGX_ERROR_INFO:
|
||||
level = NGX_LOG_INFO;
|
||||
break;
|
||||
case NGX_ERROR_ERR:
|
||||
level = NGX_LOG_ERR;
|
||||
break;
|
||||
default:
|
||||
level = NGX_LOG_CRIT;
|
||||
}
|
||||
|
||||
} else {
|
||||
level = NGX_LOG_CRIT;
|
||||
}
|
||||
|
||||
ngx_log_error(level, rev->log, err, "recv() failed");
|
||||
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
#ifndef _NGX_RECV_H_INCLUDED_
|
||||
#define _NGX_RECV_H_INCLUDED_
|
||||
|
||||
|
||||
#if 0
|
||||
#include <errno.h>
|
||||
|
||||
#define ngx_recv(fd, buf, size, flags) recv(fd, buf, size, flags)
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _NGX_RECV_H_INCLUDED_ */
|
||||
|
|
@ -4,12 +4,13 @@
|
|||
|
||||
|
||||
/*
|
||||
ioctl(FIONBIO) set blocking mode with one syscall only while
|
||||
fcntl(F_SETFL, ~O_NONBLOCK) need to know previous state
|
||||
using fcntl(F_GETFL).
|
||||
|
||||
ioctl() and fcntl() are syscalls on FreeBSD, Solaris 7/8 and Linux
|
||||
*/
|
||||
* ioctl(FIONBIO) sets a blocking mode with the single syscall
|
||||
* while fcntl(F_SETFL, ~O_NONBLOCK) needs to learn before
|
||||
* a previous state using fcntl(F_GETFL).
|
||||
*
|
||||
* ioctl() and fcntl() are syscalls on at least FreeBSD 2.x, Linux 2.2
|
||||
* and Solaris 7
|
||||
*/
|
||||
|
||||
|
||||
#if (HAVE_FIONBIO)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue