diff options
Diffstat (limited to 'src/os/unix')
-rw-r--r-- | src/os/unix/ngx_freebsd_init.c | 2 | ||||
-rw-r--r-- | src/os/unix/ngx_linux_init.c | 2 | ||||
-rw-r--r-- | src/os/unix/ngx_os.h | 3 | ||||
-rw-r--r-- | src/os/unix/ngx_send.c | 63 | ||||
-rw-r--r-- | src/os/unix/ngx_solaris_init.c | 2 |
5 files changed, 68 insertions, 4 deletions
diff --git a/src/os/unix/ngx_freebsd_init.c b/src/os/unix/ngx_freebsd_init.c index 6e7db8565..fc51b312a 100644 --- a/src/os/unix/ngx_freebsd_init.c +++ b/src/os/unix/ngx_freebsd_init.c @@ -20,7 +20,7 @@ int ngx_freebsd_kern_ipc_zero_copy_send; ngx_os_io_t ngx_os_io = { ngx_unix_recv, ngx_readv_chain, - NULL, + ngx_unix_send, #if (HAVE_SENDFILE) ngx_freebsd_sendfile_chain, NGX_IO_SENDFILE diff --git a/src/os/unix/ngx_linux_init.c b/src/os/unix/ngx_linux_init.c index 9773e5626..7379c6a18 100644 --- a/src/os/unix/ngx_linux_init.c +++ b/src/os/unix/ngx_linux_init.c @@ -12,7 +12,7 @@ int ngx_linux_rtsig_max; ngx_os_io_t ngx_os_io = { ngx_unix_recv, ngx_readv_chain, - NULL, + ngx_unix_send, #if (HAVE_SENDFILE) ngx_linux_sendfile_chain, NGX_IO_SENDFILE diff --git a/src/os/unix/ngx_os.h b/src/os/unix/ngx_os.h index 385fac0a2..e4e94f2d8 100644 --- a/src/os/unix/ngx_os.h +++ b/src/os/unix/ngx_os.h @@ -33,7 +33,7 @@ typedef struct { ngx_recv_chain_pt recv_chain; ngx_send_pt send; ngx_send_chain_pt send_chain; - int flags; + ngx_uint_t flags; } ngx_os_io_t; @@ -46,6 +46,7 @@ int ngx_posix_post_conf_init(ngx_log_t *log); ssize_t ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size); ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *entry); +ssize_t ngx_unix_send(ngx_connection_t *c, u_char *buf, size_t size); ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit); diff --git a/src/os/unix/ngx_send.c b/src/os/unix/ngx_send.c new file mode 100644 index 000000000..5a1a0ff29 --- /dev/null +++ b/src/os/unix/ngx_send.c @@ -0,0 +1,63 @@ + +#include <ngx_config.h> +#include <ngx_core.h> +#include <ngx_event.h> + + +ssize_t ngx_unix_send(ngx_connection_t *c, u_char *buf, size_t size) +{ + ssize_t n; + ngx_err_t err; + ngx_event_t *wev; + + wev = c->write; + +#if (HAVE_KQUEUE) + + if ((ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) && wev->pending_eof) { + ngx_log_error(NGX_LOG_INFO, c->log, wev->kq_errno, + "kevent() reported about an closed connection"); + + wev->error = 1; + return NGX_ERROR; + } + +#endif + + for ( ;; ) { + n = send(c->fd, buf, size, 0); + + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, + "send: fd:%d %d of %d", c->fd, n, size); + + if (n > 0) { + if (n < (ssize_t) size) { + wev->ready = 0; + } + + return n; + } + + err = ngx_socket_errno; + + if (n == 0) { + ngx_log_error(NGX_LOG_ALERT, c->log, err, "send() returned zero"); + } + + if (err == NGX_EAGAIN || err == NGX_EINTR) { + wev->ready = 0; + + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, + "send() not ready"); + + if (err == NGX_EAGAIN) { + return NGX_AGAIN; + } + + } else { + wev->error = 1; + ngx_connection_error(c, err, "recv() failed"); + return NGX_ERROR; + } + } +} diff --git a/src/os/unix/ngx_solaris_init.c b/src/os/unix/ngx_solaris_init.c index 59db3d870..25fa14dcc 100644 --- a/src/os/unix/ngx_solaris_init.c +++ b/src/os/unix/ngx_solaris_init.c @@ -11,7 +11,7 @@ char ngx_solaris_version[50]; ngx_os_io_t ngx_os_io = { ngx_unix_recv, ngx_readv_chain, - NULL, + ngx_unix_send, #if (HAVE_SENDFILE) ngx_solaris_sendfilev_chain, NGX_IO_SENDFILE |