2002-08-06 12:39:45 -04:00
|
|
|
|
|
|
|
#include <ngx_config.h>
|
|
|
|
#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
|
|
|
|
|
|
|
#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) {
|
|
|
|
ngx_log_error(NGX_LOG_ERR, ev->log, ev->error,
|
2002-08-15 13:20:26 -04:00
|
|
|
"ngx_event_recv: recv failed while %s",
|
|
|
|
ev->log->action);
|
2002-08-06 12:39:45 -04:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
ngx_log_error(NGX_LOG_INFO, ev->log, err,
|
|
|
|
"ngx_event_recv: EAGAIN while %s", ev->log->action);
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_log_error(NGX_LOG_INFO, ev->log, err,
|
|
|
|
"ngx_event_recv: recv failed while %s", ev->log->action);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if (HAVE_KQUEUE)
|
|
|
|
#if !(USE_KQUEUE)
|
|
|
|
if (ngx_event_type == NGX_KQUEUE_EVENT)
|
|
|
|
#endif
|
|
|
|
ev->available -= n;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|