blob: 8c8fd1bef68ce4e2105b2e5a0941e8aafd8edaa6 [file] [log] [blame]
Igor Sysoev6de5c2c2002-08-06 16:39:45 +00001
2#include <ngx_config.h>
Igor Sysoev016b8522002-08-29 16:59:54 +00003#include <ngx_core.h>
Igor Sysoev6de5c2c2002-08-06 16:39:45 +00004#include <ngx_types.h>
5#include <ngx_connection.h>
Igor Sysoevfcce8d52003-01-23 18:47:54 +00006#include <ngx_event.h>
7#include <ngx_event_timer.h>
Igor Sysoev6de5c2c2002-08-06 16:39:45 +00008#include <ngx_event_close.h>
9
10
Igor Sysoev0ad17c02002-08-26 15:18:19 +000011int ngx_event_close_connection(ngx_event_t *ev)
Igor Sysoev6de5c2c2002-08-06 16:39:45 +000012{
13 int rc;
Igor Sysoev016b8522002-08-29 16:59:54 +000014 ngx_connection_t *c = (ngx_connection_t *) ev->data;
Igor Sysoev6de5c2c2002-08-06 16:39:45 +000015
Igor Sysoev42feecb2002-12-15 06:25:09 +000016 ngx_log_debug(c->log, "CLOSE: %d" _ c->fd);
17
Igor Sysoev016b8522002-08-29 16:59:54 +000018 ngx_assert((c->fd != -1), return NGX_ERROR, c->log,
Igor Sysoev6de5c2c2002-08-06 16:39:45 +000019 "ngx_event_close: already closed");
20
Igor Sysoev016b8522002-08-29 16:59:54 +000021 ngx_destroy_pool(c->pool);
22
Igor Sysoev0d2bda52002-12-24 07:09:57 +000023 ngx_del_timer(c->read);
24 ngx_del_timer(c->write);
25
Igor Sysoev42feecb2002-12-15 06:25:09 +000026 ngx_del_event(c->read, NGX_READ_EVENT, NGX_CLOSE_EVENT);
27 ngx_del_event(c->write, NGX_WRITE_EVENT, NGX_CLOSE_EVENT);
28
Igor Sysoev016b8522002-08-29 16:59:54 +000029 if ((rc = ngx_close_socket(c->fd)) == -1)
Igor Sysoev73009772003-02-06 17:21:13 +000030 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_socket_errno,
Igor Sysoev6de5c2c2002-08-06 16:39:45 +000031 "ngx_event_close: close failed");
32
Igor Sysoev016b8522002-08-29 16:59:54 +000033 c->fd = -1;
Igor Sysoev6de5c2c2002-08-06 16:39:45 +000034
35 return rc;
36}