upstream nginx-0.7.42
[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_INET6 && defined IPV6_V6ONLY)
60     unsigned            ipv6only:2;
61 #endif
62
63 #if (NGX_HAVE_DEFERRED_ACCEPT)
64     unsigned            deferred_accept:1;
65     unsigned            delete_deferred:1;
66     unsigned            add_deferred:1;
67 #ifdef SO_ACCEPTFILTER
68     char               *accept_filter;
69 #endif
70 #endif
71
72 };
73
74
75 typedef enum {
76      NGX_ERROR_ALERT = 0,
77      NGX_ERROR_ERR,
78      NGX_ERROR_INFO,
79      NGX_ERROR_IGNORE_ECONNRESET,
80      NGX_ERROR_IGNORE_EINVAL
81 } ngx_connection_log_error_e;
82
83
84 typedef enum {
85      NGX_TCP_NODELAY_UNSET = 0,
86      NGX_TCP_NODELAY_SET,
87      NGX_TCP_NODELAY_DISABLED
88 } ngx_connection_tcp_nodelay_e;
89
90
91 typedef enum {
92      NGX_TCP_NOPUSH_UNSET = 0,
93      NGX_TCP_NOPUSH_SET,
94      NGX_TCP_NOPUSH_DISABLED
95 } ngx_connection_tcp_nopush_e;
96
97
98 #define NGX_LOWLEVEL_BUFFERED  0x0f
99 #define NGX_SSL_BUFFERED       0x01
100
101
102 struct ngx_connection_s {
103     void               *data;
104     ngx_event_t        *read;
105     ngx_event_t        *write;
106
107     ngx_socket_t        fd;
108
109     ngx_recv_pt         recv;
110     ngx_send_pt         send;
111     ngx_recv_chain_pt   recv_chain;
112     ngx_send_chain_pt   send_chain;
113
114     ngx_listening_t    *listening;
115
116     off_t               sent;
117
118     ngx_log_t          *log;
119
120     ngx_pool_t         *pool;
121
122     struct sockaddr    *sockaddr;
123     socklen_t           socklen;
124     ngx_str_t           addr_text;
125
126 #if (NGX_SSL)
127     ngx_ssl_connection_t  *ssl;
128 #endif
129
130     struct sockaddr    *local_sockaddr;
131     socklen_t           local_socklen;
132
133     ngx_buf_t          *buffer;
134
135     ngx_atomic_uint_t   number;
136
137     unsigned            buffered:8;
138
139     unsigned            log_error:3;     /* ngx_connection_log_error_e */
140
141     unsigned            single_connection:1;
142     unsigned            unexpected_eof:1;
143     unsigned            timedout:1;
144     unsigned            error:1;
145     unsigned            destroyed:1;
146
147     unsigned            idle:1;
148     unsigned            close:1;
149
150     unsigned            sendfile:1;
151     unsigned            sndlowat:1;
152     unsigned            tcp_nodelay:2;   /* ngx_connection_tcp_nodelay_e */
153     unsigned            tcp_nopush:2;    /* ngx_connection_tcp_nopush_e */
154
155 #if (NGX_HAVE_IOCP)
156     unsigned            accept_context_updated:1;
157 #endif
158
159 #if (NGX_THREADS)
160     ngx_atomic_t        lock;
161 #endif
162 };
163
164
165 #ifndef ngx_ssl_set_nosendshut
166 #define ngx_ssl_set_nosendshut(ssl)
167 #endif
168
169
170 ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf,
171     in_addr_t addr, in_port_t port);
172 ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle);
173 ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle);
174 void ngx_configure_listening_socket(ngx_cycle_t *cycle);
175 void ngx_close_listening_sockets(ngx_cycle_t *cycle);
176 void ngx_close_connection(ngx_connection_t *c);
177 ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text);
178
179 ngx_connection_t *ngx_get_connection(ngx_socket_t s, ngx_log_t *log);
180 void ngx_free_connection(ngx_connection_t *c);
181
182
183 #endif /* _NGX_CONNECTION_H_INCLUDED_ */