diff options
Diffstat (limited to 'src/os/unix')
-rw-r--r-- | src/os/unix/ngx_freebsd_init.c | 10 | ||||
-rw-r--r-- | src/os/unix/ngx_freebsd_init.h | 4 | ||||
-rw-r--r-- | src/os/unix/ngx_init.c | 20 | ||||
-rw-r--r-- | src/os/unix/ngx_os_init.h | 4 | ||||
-rw-r--r-- | src/os/unix/ngx_recv.c | 92 | ||||
-rw-r--r-- | src/os/unix/ngx_recv.h | 2 | ||||
-rw-r--r-- | src/os/unix/ngx_unix_init.c | 39 |
7 files changed, 149 insertions, 22 deletions
diff --git a/src/os/unix/ngx_freebsd_init.c b/src/os/unix/ngx_freebsd_init.c index f8896e871..f9cba480c 100644 --- a/src/os/unix/ngx_freebsd_init.c +++ b/src/os/unix/ngx_freebsd_init.c @@ -10,6 +10,14 @@ int ngx_freebsd_net_inet_tcp_sendspace; int ngx_freebsd_sendfile_nbytes_bug; +ngx_os_io_t ngx_os_io = { + ngx_unix_recv, + NULL, + NULL, + ngx_freebsd_write_chain +}; + + int ngx_os_init(ngx_log_t *log) { size_t size; @@ -99,5 +107,5 @@ int ngx_os_init(ngx_log_t *log) ngx_log_error(NGX_LOG_INFO, log, 0, "net.inet.tcp.sendspace: %d", ngx_freebsd_net_inet_tcp_sendspace); - return NGX_OK; + return ngx_unix_init(log); } diff --git a/src/os/unix/ngx_freebsd_init.h b/src/os/unix/ngx_freebsd_init.h index 400295ae7..d0d2c5b87 100644 --- a/src/os/unix/ngx_freebsd_init.h +++ b/src/os/unix/ngx_freebsd_init.h @@ -5,10 +5,12 @@ #include <ngx_config.h> #include <ngx_core.h> #include <ngx_log.h> +#include <ngx_os_init.h> #include <sys/sysctl.h> -int ngx_os_init(ngx_log_t *log); +int ngx_unix_init(ngx_log_t *log); +ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size); extern int ngx_freebsd_kern_osreldate; diff --git a/src/os/unix/ngx_init.c b/src/os/unix/ngx_init.c deleted file mode 100644 index 28af1288d..000000000 --- a/src/os/unix/ngx_init.c +++ /dev/null @@ -1,20 +0,0 @@ - - -int ngx_unix_init(ngx_log_t *log) -{ - struct rlimit rlmt; - - if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) { - ngx_log_error(NGX_LOG_ALERT, log, errno, - "getrlimit(RLIMIT_NOFILE) failed)"); - return NGX_ERROR; - } - - ngx_log_error(NGX_LOG_INFO, log, 0, - "getrlimit(RLIMIT_NOFILE): %d", rlmt.rlim_cur); - - RLIM_INFINITY - max_connections =< rlmt.rlim_cur; - - return NGX_OK; -} diff --git a/src/os/unix/ngx_os_init.h b/src/os/unix/ngx_os_init.h index 5c445ace6..25e0b6a7a 100644 --- a/src/os/unix/ngx_os_init.h +++ b/src/os/unix/ngx_os_init.h @@ -4,9 +4,13 @@ #include <ngx_config.h> #include <ngx_log.h> +#include <ngx_hunk.h> +#include <ngx_connection.h> int ngx_os_init(ngx_log_t *log); +extern ngx_os_io_t ngx_os_io; + #endif /* _NGX_OS_INIT_H_INCLUDED_ */ diff --git a/src/os/unix/ngx_recv.c b/src/os/unix/ngx_recv.c new file mode 100644 index 000000000..c6e8b0390 --- /dev/null +++ b/src/os/unix/ngx_recv.c @@ -0,0 +1,92 @@ + +#include <ngx_config.h> +#include <ngx_core.h> +#include <ngx_errno.h> +#include <ngx_log.h> +#include <ngx_recv.h> +#include <ngx_connection.h> + + +ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size) +{ + ssize_t n; + ngx_err_t err; + ngx_event_t *ev; + + ev = c->read; + +#if (HAVE_KQUEUE) /* DEBUG */ + if (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) { + ngx_log_debug(c->log, "ngx_recv: eof:%d, avail:%d, err:%d" _ + ev->eof _ ev->available _ ev->error); + } +#endif + +#if (HAVE_KQUEUE) + + if ((ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) + && ev->eof && ev->available == 0) { + + if (ev->error == 0) { + return 0; + } + + ngx_set_socket_errno(ev->error); + err = ev->error; + n = -1; + + } else { + n = recv(c->fd, buf, size, 0); + +ngx_log_debug(c->log, "ngx_recv: read:%d:%d" _ n _ size); + + if (n == -1) { + err = ngx_socket_errno; + } + } + +#else /* not kqueue */ + + n = recv(c->fd, buf, size, 0); + + if (n == -1) { + err = ngx_socket_errno; + } + +#endif + + if (n == -1) { + ev->ready = 0; + + if (err == NGX_ECONNRESET && ev->ignore_econnreset) { + return 0; + } + + if (err == NGX_EAGAIN) { + ngx_log_error(NGX_LOG_INFO, c->log, err, "recv() returned EAGAIN"); + return NGX_AGAIN; + } + + ngx_log_error(NGX_LOG_ERR, c->log, err, "recv() failed"); + return NGX_ERROR; + } + +#if (HAVE_KQUEUE) + + if (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) { + ev->available -= n; + if (ev->available == 0) { + ev->ready = 0; + } + + return n; + } + +#endif + + if ((size_t) n < size) { + ev->ready = 0; + } + + return n; +} diff --git a/src/os/unix/ngx_recv.h b/src/os/unix/ngx_recv.h index e92832cc7..01d662fec 100644 --- a/src/os/unix/ngx_recv.h +++ b/src/os/unix/ngx_recv.h @@ -2,9 +2,11 @@ #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_ */ diff --git a/src/os/unix/ngx_unix_init.c b/src/os/unix/ngx_unix_init.c new file mode 100644 index 000000000..2916c9e44 --- /dev/null +++ b/src/os/unix/ngx_unix_init.c @@ -0,0 +1,39 @@ + +#include <ngx_config.h> +#include <ngx_core.h> + + +int ngx_unix_init(ngx_log_t *log) +{ + struct sigaction sa; + struct rlimit rlmt; + + ngx_memzero(&sa, sizeof(struct sigaction)); + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + + if (sigaction(SIGPIPE, &sa, NULL) == -1) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, + "sigaction(SIGPIPE, SIG_IGN) failed"); + return NGX_ERROR; + } + + + if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) { + ngx_log_error(NGX_LOG_ALERT, log, errno, + "getrlimit(RLIMIT_NOFILE) failed)"); + return NGX_ERROR; + } + + ngx_log_error(NGX_LOG_INFO, log, 0, + "getrlimit(RLIMIT_NOFILE): %qd:%qd", + rlmt.rlim_cur, rlmt.rlim_max); + + +#if 0 + RLIM_INFINITY + max_connections =< rlmt.rlim_cur; +#endif + + return NGX_OK; +} |