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_DEFERRED_ACCEPT)
60 unsigned deferred_accept:1;
61 unsigned delete_deferred:1;
62 unsigned add_deferred:1;
63 #ifdef SO_ACCEPTFILTER
75 NGX_ERROR_IGNORE_ECONNRESET
76 } ngx_connection_log_error_e;
80 NGX_TCP_NODELAY_UNSET = 0,
82 NGX_TCP_NODELAY_DISABLED
83 } ngx_connection_tcp_nodelay_e;
87 NGX_TCP_NOPUSH_UNSET = 0,
89 NGX_TCP_NOPUSH_DISABLED
90 } ngx_connection_tcp_nopush_e;
93 #define NGX_LOWLEVEL_BUFFERED 0x0f
94 #define NGX_SSL_BUFFERED 0x01
97 struct ngx_connection_s {
106 ngx_recv_chain_pt recv_chain;
107 ngx_send_chain_pt send_chain;
109 ngx_listening_t *listening;
117 struct sockaddr *sockaddr;
122 ngx_ssl_connection_t *ssl;
125 struct sockaddr *local_sockaddr;
126 socklen_t local_socklen;
130 ngx_atomic_uint_t number;
134 unsigned log_error:2; /* ngx_connection_log_error_e */
136 unsigned single_connection:1;
137 unsigned unexpected_eof:1;
140 unsigned destroyed:1;
147 unsigned tcp_nodelay:2; /* ngx_connection_tcp_nodelay_e */
148 unsigned tcp_nopush:2; /* ngx_connection_tcp_nopush_e */
151 unsigned accept_context_updated:1;
160 #ifndef ngx_ssl_set_nosendshut
161 #define ngx_ssl_set_nosendshut(ssl)
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);
174 ngx_connection_t *ngx_get_connection(ngx_socket_t s, ngx_log_t *log);
175 void ngx_free_connection(ngx_connection_t *c);
178 #endif /* _NGX_CONNECTION_H_INCLUDED_ */