nginx-quic/src/event/ngx_event_recv.c

102 lines
2.2 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)
{
2002-08-15 13:20:26 -04:00
int n;
ngx_err_t err;
2003-03-11 16:38:13 -04:00
ngx_event_t *ev;
2002-08-15 13:20:26 -04:00
2003-03-11 16:38:13 -04:00
ev = c->read;
if (ev->timedout) {
2002-08-26 11:18:19 -04:00
ngx_set_socket_errno(NGX_ETIMEDOUT);
2002-08-29 12:59:54 -04:00
ngx_log_error(NGX_LOG_ERR, c->log, NGX_ETIMEDOUT, "recv() failed");
2002-08-26 11:18:19 -04:00
return NGX_ERROR;
}
#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) {
if (ev->error) {
ngx_set_socket_errno(ev->error);
if (ev->error == NGX_ECONNRESET && ev->ignore_econnreset) {
return 0;
}
ngx_log_error(NGX_LOG_ERR, c->log, ev->error,
2003-02-06 14:21:13 -03:00
"recv() failed");
return NGX_ERROR;
}
return 0;
}
#elif (HAVE_KQUEUE)
2003-03-11 16:38:13 -04:00
if (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) {
if (ev->eof && ev->available == 0) {
if (ev->error) {
ngx_set_socket_errno(ev->error);
if (ev->error == NGX_ECONNRESET && ev->ignore_econnreset) {
return 0;
}
ngx_log_error(NGX_LOG_ERR, c->log, ev->error,
2002-08-29 12:59:54 -04:00
"recv() failed");
2002-08-22 11:24:03 -04:00
return NGX_ERROR;
}
return 0;
}
2003-02-06 14:21:13 -03:00
}
#endif
2002-08-15 13:20:26 -04:00
n = ngx_recv(c->fd, buf, size, 0);
if (n == -1) {
err = ngx_socket_errno;
2003-03-11 16:38:13 -04:00
if (ev->error == NGX_ECONNRESET && ev->ignore_econnreset) {
return 0;
}
if (err == NGX_EAGAIN) {
2002-08-29 12:59:54 -04:00
ngx_log_error(NGX_LOG_INFO, c->log, err, "recv() returns 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-02-06 14:21:13 -03:00
#if (USE_KQUEUE)
2003-03-11 16:38:13 -04:00
ev->available -= n;
2003-02-06 14:21:13 -03:00
#elif (HAVE_KQUEUE)
2003-03-11 16:38:13 -04:00
if (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) {
ev->available -= n;
2003-02-06 14:21:13 -03:00
}
#endif
return n;
}