2002-08-06 12:39:45 -04:00
|
|
|
|
|
|
|
#include <ngx_config.h>
|
2002-08-22 11:24:03 -04:00
|
|
|
#include <ngx_core.h>
|
2002-08-06 12:39:45 -04:00
|
|
|
#include <ngx_errno.h>
|
|
|
|
#include <ngx_log.h>
|
2002-08-15 13:20:26 -04:00
|
|
|
#include <ngx_recv.h>
|
2002-08-06 12:39:45 -04:00
|
|
|
#include <ngx_connection.h>
|
|
|
|
|
2002-08-15 13:20:26 -04:00
|
|
|
int ngx_event_recv_core(ngx_event_t *ev, char *buf, size_t size)
|
2002-08-06 12:39:45 -04:00
|
|
|
{
|
2002-08-15 13:20:26 -04:00
|
|
|
int n;
|
|
|
|
ngx_err_t err;
|
|
|
|
ngx_connection_t *c;
|
|
|
|
|
|
|
|
c = (ngx_connection_t *) ev->data;
|
2002-08-06 12:39:45 -04:00
|
|
|
|
2002-08-26 11:18:19 -04:00
|
|
|
if (ev->timedout) {
|
|
|
|
ngx_set_socket_errno(NGX_ETIMEDOUT);
|
|
|
|
ngx_log_error(NGX_LOG_ERR, ev->log, NGX_ETIMEDOUT, "recv() failed");
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2002-08-06 12:39:45 -04:00
|
|
|
#if (HAVE_KQUEUE)
|
2002-08-15 13:20:26 -04:00
|
|
|
ngx_log_debug(ev->log, "ngx_event_recv: eof:%d, avail:%d, err:%d" _
|
|
|
|
ev->eof _ ev->available _ ev->error);
|
2002-08-06 12:39:45 -04:00
|
|
|
#if !(USE_KQUEUE)
|
|
|
|
if (ngx_event_type == NGX_KQUEUE_EVENT)
|
|
|
|
#endif
|
|
|
|
if (ev->eof && ev->available == 0) {
|
|
|
|
if (ev->error) {
|
2002-08-26 11:18:19 -04:00
|
|
|
ngx_log_error(NGX_LOG_ERR, ev->log, ev->error, "recv() failed");
|
2002-08-22 11:24:03 -04:00
|
|
|
return NGX_ERROR;
|
2002-08-06 12:39:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-08-15 13:20:26 -04:00
|
|
|
n = ngx_recv(c->fd, buf, size, 0);
|
2002-08-06 12:39:45 -04:00
|
|
|
|
|
|
|
if (n == -1) {
|
|
|
|
err = ngx_socket_errno;
|
|
|
|
|
|
|
|
if (err == NGX_EAGAIN) {
|
2002-08-26 11:18:19 -04:00
|
|
|
ngx_log_error(NGX_LOG_INFO, ev->log, err, "recv() returns EAGAIN");
|
2002-08-22 11:24:03 -04:00
|
|
|
return NGX_AGAIN;
|
2002-08-06 12:39:45 -04:00
|
|
|
}
|
|
|
|
|
2002-08-26 11:18:19 -04:00
|
|
|
ngx_log_error(NGX_LOG_ERR, ev->log, err, "recv() failed");
|
2002-08-22 11:24:03 -04:00
|
|
|
return NGX_ERROR;
|
2002-08-06 12:39:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if (HAVE_KQUEUE)
|
|
|
|
#if !(USE_KQUEUE)
|
|
|
|
if (ngx_event_type == NGX_KQUEUE_EVENT)
|
|
|
|
#endif
|
|
|
|
ev->available -= n;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|