upstream nginx-0.7.36
[nginx.git] / nginx / src / core / ngx_connection.h
1
2 /*
3  * Copyright (C) Igor Sysoev
4  */
5
6
7 #ifndef _NGX_CONNECTION_H_INCLUDED_
8 #define _NGX_CONNECTION_H_INCLUDED_
9
10
11 #include <ngx_config.h>
12 #include <ngx_core.h>
13
14
15 typedef struct ngx_listening_s  ngx_listening_t;
16
17 struct ngx_listening_s {
18     ngx_socket_t        fd;
19
20     struct sockaddr    *sockaddr;
21     socklen_t           socklen;    /* size of sockaddr */
22     size_t              addr_text_max_len;
23     ngx_str_t           addr_text;
24
25     int                 type;
26
27     int                 backlog;
28     int                 rcvbuf;
29     int                 sndbuf;
30
31     /* handler of accepted connection */
32     ngx_connection_handler_pt   handler;
33
34     void               *servers;  /* array of ngx_http_in_addr_t, for example */
35
36     ngx_log_t           log;
37
38     size_t              pool_size;
39     /* should be here because of the AcceptEx() preread */
40     size_t              post_accept_buffer_size;
41     /* should be here because of the deferred accept */
42     ngx_msec_t          post_accept_timeout;
43
44     ngx_listening_t    *previous;
45     ngx_connection_t   *connection;
46
47     unsigned            open:1;
48     unsigned            remain:1;
49     unsigned            ignore:1;
50
51     unsigned            bound:1;       /* already bound */
52     unsigned            inherited:1;   /* inherited from previous process */
53     unsigned            nonblocking_accept:1;
54     unsigned            listen:1;
55     unsigned            nonblocking:1;
56     unsigned            shared:1;    /* shared between threads or processes */
57     unsigned            addr_ntop:1;
58
59 #if (NGX_HAVE_DEFERRED_ACCEPT)
60     unsigned            deferred_accept:1;
61     unsigned            delete_deferred:1;
62     unsigned            add_deferred:1;
63 #ifdef SO_ACCEPTFILTER
64     char               *accept_filter;
65 #endif
66 #endif
67
68 };
69
70
71 typedef enum {
72      NGX_ERROR_CRIT = 0,
73      NGX_ERROR_ERR,
74      NGX_ERROR_INFO,
75      NGX_ERROR_IGNORE_ECONNRESET
76 } ngx_connection_log_error_e;
77
78
79 typedef enum {
80      NGX_TCP_NODELAY_UNSET = 0,
81      NGX_TCP_NODELAY_SET,
82      NGX_TCP_NODELAY_DISABLED
83 } ngx_connection_tcp_nodelay_e;
84
85
86 typedef enum {
87      NGX_TCP_NOPUSH_UNSET = 0,
88      NGX_TCP_NOPUSH_SET,
89      NGX_TCP_NOPUSH_DISABLED
90 } ngx_connection_tcp_nopush_e;
91
92
93 #define NGX_LOWLEVEL_BUFFERED  0x0f
94 #define NGX_SSL_BUFFERED       0x01
95
96
97 struct ngx_connection_s {
98     void               *data;
99     ngx_event_t        *read;
100     ngx_event_t        *write;
101
102     ngx_socket_t        fd;
103
104     ngx_recv_pt         recv;
105     ngx_send_pt         send;
106     ngx_recv_chain_pt   recv_chain;
107     ngx_send_chain_pt   send_chain;
108
109     ngx_listening_t    *listening;
110
111     off_t               sent;
112
113     ngx_log_t          *log;
114
115     ngx_pool_t         *pool;
116
117     struct sockaddr    *sockaddr;
118     socklen_t           socklen;
119     ngx_str_t           addr_text;
120
121 #if (NGX_SSL)
122     ngx_ssl_connection_t  *ssl;
123 #endif
124
125     struct sockaddr    *local_sockaddr;
126     socklen_t           local_socklen;
127
128     ngx_buf_t          *buffer;
129
130     ngx_atomic_uint_t   number;
131
132     unsigned            buffered:8;
133
134     unsigned            log_error:2;     /* ngx_connection_log_error_e */
135
136     unsigned            single_connection:1;
137     unsigned            unexpected_eof:1;
138     unsigned            timedout:1;
139     unsigned            error:1;
140     unsigned            destroyed:1;
141
142     unsigned            idle:1;
143     unsigned            close:1;
144
145     unsigned            sendfile:1;
146     unsigned            sndlowat:1;
147     unsigned            tcp_nodelay:2;   /* ngx_connection_tcp_nodelay_e */
148     unsigned            tcp_nopush:2;    /* ngx_connection_tcp_nopush_e */
149
150 #if (NGX_HAVE_IOCP)
151     unsigned            accept_context_updated:1;
152 #endif
153
154 #if (NGX_THREADS)
155     ngx_atomic_t        lock;
156 #endif
157 };
158
159
160 #ifndef ngx_ssl_set_nosendshut
161 #define ngx_ssl_set_nosendshut(ssl)
162 #endif
163
164
165 ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf,
166     in_addr_t addr, in_port_t port);
167 ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle);
168 ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle);
169 void ngx_configure_listening_socket(ngx_cycle_t *cycle);
170 void ngx_close_listening_sockets(ngx_cycle_t *cycle);
171 void ngx_close_connection(ngx_connection_t *c);
172 ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text);
173
174 ngx_connection_t *ngx_get_connection(ngx_socket_t s, ngx_log_t *log);
175 void ngx_free_connection(ngx_connection_t *c);
176
177
178 #endif /* _NGX_CONNECTION_H_INCLUDED_ */