nginx-quic/src/event/ngx_event_recv.c

148 lines
2.9 KiB
C
Raw Normal View History

#include <ngx_config.h>
2002-08-22 11:24:03 -04:00
#include <ngx_core.h>
#include <ngx_errno.h>
#include <ngx_log.h>
2002-08-15 13:20:26 -04:00
#include <ngx_recv.h>
#include <ngx_connection.h>
2003-02-06 14:21:13 -03:00
ssize_t ngx_event_recv_core(ngx_connection_t *c, char *buf, size_t size)
{
2003-03-20 12:09:44 -04:00
ssize_t n;
ngx_err_t err;
ngx_event_t *ev;
2002-08-15 13:20:26 -04:00
2003-03-11 16:38:13 -04:00
ev = c->read;
2003-03-20 12:09:44 -04:00
/* DEBUG */
#if (HAVE_KQUEUE)
2003-03-11 16:38:13 -04:00
if (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) {
ngx_log_debug(c->log, "ngx_event_recv: eof:%d, avail:%d, err:%d" _
ev->eof _ ev->available _ ev->error);
}
#endif
2003-02-06 14:21:13 -03:00
#if (USE_KQUEUE)
2003-03-11 16:38:13 -04:00
if (ev->eof && ev->available == 0) {
2003-03-20 12:09:44 -04:00
if (ev->error == 0) {
return 0;
}
ngx_set_socket_errno(ev->error);
err = ev->error;
n = -1;
} else {
n = ngx_recv(c->fd, buf, size, 0);
if (n == -1) {
err = ngx_socket_errno;
}
}
if (n == -1) {
ev->ready = 0;
2003-03-11 16:38:13 -04:00
2003-03-20 12:09:44 -04:00
if (err == NGX_ECONNRESET && ev->ignore_econnreset) {
return 0;
2003-02-06 14:21:13 -03:00
}
2003-03-20 12:09:44 -04:00
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;
2003-02-06 14:21:13 -03:00
}
2003-03-20 12:09:44 -04:00
ev->available -= n;
if (ev->available == 0) {
ev->ready = 0;
}
2003-02-06 14:21:13 -03:00
2003-03-20 12:09:44 -04:00
return n;
2003-03-11 16:38:13 -04:00
2003-03-20 12:09:44 -04:00
#elif (HAVE_KQUEUE)
2003-03-11 16:38:13 -04:00
2003-03-20 12:09:44 -04:00
if ((ngx_event_flags & NGX_HAVE_KQUEUE_EVENT)
&& ev->eof && ev->available == 0) {
2003-03-20 12:09:44 -04:00
if (ev->error == 0) {
return 0;
}
2003-02-06 14:21:13 -03:00
2003-03-20 12:09:44 -04:00
ngx_set_socket_errno(ev->error);
err = ev->error;
n = -1;
2003-03-20 12:09:44 -04:00
} else {
n = ngx_recv(c->fd, buf, size, 0);
ngx_log_debug(c->log, "ngx_event_recv: read:%d:%d" _ n _ size);
if (n == -1) {
err = ngx_socket_errno;
}
}
if (n == -1) {
2003-03-20 12:09:44 -04:00
ev->ready = 0;
2003-03-20 12:09:44 -04:00
if (err == NGX_ECONNRESET && ev->ignore_econnreset) {
2003-03-11 16:38:13 -04:00
return 0;
}
if (err == NGX_EAGAIN) {
2003-03-20 12:09:44 -04:00
ngx_log_error(NGX_LOG_INFO, c->log, err, "recv() returned EAGAIN");
2002-08-22 11:24:03 -04:00
return NGX_AGAIN;
}
2002-08-29 12:59:54 -04:00
ngx_log_error(NGX_LOG_ERR, c->log, err, "recv() failed");
2002-08-22 11:24:03 -04:00
return NGX_ERROR;
}
2003-03-20 12:09:44 -04:00
if (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) {
ev->available -= n;
if (ev->available == 0) {
ev->ready = 0;
}
2003-02-06 14:21:13 -03:00
2003-03-20 12:09:44 -04:00
} else if ((size_t) n < size) {
ev->ready = 0;
}
2003-02-06 14:21:13 -03:00
2003-03-20 12:09:44 -04:00
return n;
2003-02-06 14:21:13 -03:00
2003-03-20 12:09:44 -04:00
#else /* not kqueue */
n = ngx_recv(c->fd, buf, size, 0);
if (n == -1) {
err = ngx_socket_errno;
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;
2003-02-06 14:21:13 -03:00
}
2003-03-20 12:09:44 -04:00
if ((size_t) n < size) {
ev->ready = 0;
}
return n;
2003-03-20 12:09:44 -04:00
#endif
}