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