nginx/src/event/ngx_event_close.c

44 lines
1.0 KiB
C
Raw Normal View History

#include <ngx_config.h>
2002-08-30 00:59:54 +08:00
#include <ngx_core.h>
#include <ngx_types.h>
#include <ngx_connection.h>
2003-01-24 02:47:54 +08:00
#include <ngx_event.h>
#include <ngx_event_timer.h>
#include <ngx_event_close.h>
2002-08-26 23:18:19 +08:00
int ngx_event_close_connection(ngx_event_t *ev)
{
int rc;
2002-08-30 00:59:54 +08:00
ngx_connection_t *c = (ngx_connection_t *) ev->data;
2003-03-12 04:38:13 +08:00
ngx_log_debug(c->log, "close connection: %d" _ c->fd);
2002-12-15 14:25:09 +08:00
2002-08-30 00:59:54 +08:00
ngx_assert((c->fd != -1), return NGX_ERROR, c->log,
"ngx_event_close: already closed");
2003-03-12 04:38:13 +08:00
if (c->read->timer_set) {
ngx_del_timer(c->read);
c->read->timer_set = 0;
}
2002-08-30 00:59:54 +08:00
2003-03-12 04:38:13 +08:00
if (c->write->timer_set) {
ngx_del_timer(c->write);
c->write->timer_set = 0;
}
2002-12-24 15:09:57 +08:00
2002-12-15 14:25:09 +08:00
ngx_del_event(c->read, NGX_READ_EVENT, NGX_CLOSE_EVENT);
ngx_del_event(c->write, NGX_WRITE_EVENT, NGX_CLOSE_EVENT);
2002-08-30 00:59:54 +08:00
if ((rc = ngx_close_socket(c->fd)) == -1)
2003-02-07 01:21:13 +08:00
ngx_log_error(NGX_LOG_ALERT, c->log, ngx_socket_errno,
"ngx_event_close: close failed");
2002-08-30 00:59:54 +08:00
c->fd = -1;
2003-03-12 04:38:13 +08:00
ngx_destroy_pool(c->pool);
return rc;
}