diff options
author | Igor Sysoev <igor@sysoev.ru> | 2007-12-03 19:46:46 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2007-12-03 19:46:46 +0300 |
commit | e67d46189c911ca7dbeef8c7b7c99c4751683948 (patch) | |
tree | a3084634a8316873f2cb05a2cd1b0b69aca73a1b /src/os/unix/ngx_udp_recv.c | |
parent | 7b35de92a94683ee20ee5bd7ecd7a0e3a9c91521 (diff) |
ngx_udp_recv()
Diffstat (limited to 'src/os/unix/ngx_udp_recv.c')
-rw-r--r-- | src/os/unix/ngx_udp_recv.c | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/os/unix/ngx_udp_recv.c b/src/os/unix/ngx_udp_recv.c new file mode 100644 index 000000000..25f0738ac --- /dev/null +++ b/src/os/unix/ngx_udp_recv.c @@ -0,0 +1,114 @@ + +/* + * Copyright (C) Igor Sysoev + */ + + +#include <ngx_config.h> +#include <ngx_core.h> +#include <ngx_event.h> + + +#if (NGX_HAVE_KQUEUE) + +ssize_t +ngx_udp_unix_recv(ngx_connection_t *c, u_char *buf, size_t size) +{ + ssize_t n; + ngx_err_t err; + ngx_event_t *rev; + + rev = c->read; + + do { + n = recv(c->fd, buf, size, 0); + + 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_USE_KQUEUE_EVENT) { + rev->available -= n; + + /* + * rev->available may be negative here because some additional + * bytes may be received between kevent() and recv() + */ + + if (rev->available <= 0) { + rev->ready = 0; + rev->available = 0; + } + } + + return n; + } + + err = ngx_socket_errno; + + if (err == NGX_EAGAIN || err == NGX_EINTR) { + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, + "recv() not ready"); + n = NGX_AGAIN; + + } else { + n = ngx_connection_error(c, err, "recv() failed"); + break; + } + + } while (err == NGX_EINTR); + + rev->ready = 0; + + if (n == NGX_ERROR){ + rev->error = 1; + } + + return n; +} + +#else /* ! NGX_HAVE_KQUEUE */ + +ssize_t +ngx_udp_unix_recv(ngx_connection_t *c, u_char *buf, size_t size) +{ + ssize_t n; + ngx_err_t err; + ngx_event_t *rev; + + rev = c->read; + + do { + n = recv(c->fd, buf, size, 0); + + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, + "recv: fd:%d %d of %d", c->fd, n, size); + + if (n >= 0) { + return n; + } + + err = ngx_socket_errno; + + if (err == NGX_EAGAIN || err == NGX_EINTR) { + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, + "recv() not ready"); + n = NGX_AGAIN; + + } else { + n = ngx_connection_error(c, err, "recv() failed"); + break; + } + + } while (err == NGX_EINTR); + + rev->ready = 0; + + if (n == NGX_ERROR){ + rev->error = 1; + } + + return n; +} + +#endif /* NGX_HAVE_KQUEUE */ |