3 * Copyright (C) Igor Sysoev
7 #ifndef _NGX_CONNECTION_H_INCLUDED_
8 #define _NGX_CONNECTION_H_INCLUDED_
11 #include <ngx_config.h>
15 typedef struct ngx_listening_s ngx_listening_t;
17 struct ngx_listening_s {
20 struct sockaddr *sockaddr;
21 socklen_t socklen; /* size of sockaddr */
22 size_t addr_text_max_len;
31 /* handler of accepted connection */
32 ngx_connection_handler_pt handler;
34 void *servers; /* array of ngx_http_in_addr_t, for example */
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;
44 ngx_listening_t *previous;
45 ngx_connection_t *connection;
51 unsigned bound:1; /* already bound */
52 unsigned inherited:1; /* inherited from previous process */
53 unsigned nonblocking_accept:1;
55 unsigned nonblocking:1;
56 unsigned shared:1; /* shared between threads or processes */
59 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
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
79 NGX_ERROR_IGNORE_ECONNRESET,
80 NGX_ERROR_IGNORE_EINVAL
81 } ngx_connection_log_error_e;
85 NGX_TCP_NODELAY_UNSET = 0,
87 NGX_TCP_NODELAY_DISABLED
88 } ngx_connection_tcp_nodelay_e;
92 NGX_TCP_NOPUSH_UNSET = 0,
94 NGX_TCP_NOPUSH_DISABLED
95 } ngx_connection_tcp_nopush_e;
98 #define NGX_LOWLEVEL_BUFFERED 0x0f
99 #define NGX_SSL_BUFFERED 0x01
102 struct ngx_connection_s {
111 ngx_recv_chain_pt recv_chain;
112 ngx_send_chain_pt send_chain;
114 ngx_listening_t *listening;
122 struct sockaddr *sockaddr;
127 ngx_ssl_connection_t *ssl;
130 struct sockaddr *local_sockaddr;
131 socklen_t local_socklen;
135 ngx_atomic_uint_t number;
139 unsigned log_error:3; /* ngx_connection_log_error_e */
141 unsigned single_connection:1;
142 unsigned unexpected_eof:1;
145 unsigned destroyed:1;
152 unsigned tcp_nodelay:2; /* ngx_connection_tcp_nodelay_e */
153 unsigned tcp_nopush:2; /* ngx_connection_tcp_nopush_e */
156 unsigned accept_context_updated:1;
165 #ifndef ngx_ssl_set_nosendshut
166 #define ngx_ssl_set_nosendshut(ssl)
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);
179 ngx_connection_t *ngx_get_connection(ngx_socket_t s, ngx_log_t *log);
180 void ngx_free_connection(ngx_connection_t *c);
183 #endif /* _NGX_CONNECTION_H_INCLUDED_ */