summaryrefslogtreecommitdiffhomepage
path: root/src/event/ngx_event_close.c
blob: 0e3fe20c750102686d3e912c5b9089725cfc5a10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_types.h>
#include <ngx_connection.h>
#include <ngx_event_close.h>


int ngx_event_close_connection(ngx_event_t *ev)
{
    int rc;
    ngx_connection_t *c = (ngx_connection_t *) ev->data;

    ngx_assert((c->fd != -1), return NGX_ERROR, c->log,
               "ngx_event_close: already closed");

    ngx_destroy_pool(c->pool);

    if ((rc = ngx_close_socket(c->fd)) == -1)
        ngx_log_error(NGX_LOG_ERR, c->log, ngx_socket_errno,
                      "ngx_event_close: close failed");

    if (c->read->next)
        ngx_del_event(c->read, NGX_READ_EVENT);

    if (c->write->next)
        ngx_del_event(c->write, NGX_WRITE_EVENT);

    c->fd = -1;

    return rc;
}