3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
8 #ifndef _NGX_CONNECTION_H_INCLUDED_
9 #define _NGX_CONNECTION_H_INCLUDED_
12 #include <ngx_config.h>
16 typedef struct ngx_listening_s ngx_listening_t
;
18 struct ngx_listening_s
{
21 struct sockaddr
*sockaddr
;
22 socklen_t socklen
; /* size of sockaddr */
23 size_t addr_text_max_len
;
31 #if (NGX_HAVE_KEEPALIVE_TUNABLE)
37 /* handler of accepted connection */
38 ngx_connection_handler_pt handler
;
40 void *servers
; /* array of ngx_http_in_addr_t, for example */
46 /* should be here because of the AcceptEx() preread */
47 size_t post_accept_buffer_size
;
48 /* should be here because of the deferred accept */
49 ngx_msec_t post_accept_timeout
;
51 ngx_listening_t
*previous
;
52 ngx_connection_t
*connection
;
58 unsigned bound
:1; /* already bound */
59 unsigned inherited
:1; /* inherited from previous process */
60 unsigned nonblocking_accept
:1;
62 unsigned nonblocking
:1;
63 unsigned shared
:1; /* shared between threads or processes */
66 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
71 #if (NGX_HAVE_DEFERRED_ACCEPT)
72 unsigned deferred_accept
:1;
73 unsigned delete_deferred
:1;
74 unsigned add_deferred
:1;
75 #ifdef SO_ACCEPTFILTER
90 NGX_ERROR_IGNORE_ECONNRESET
,
91 NGX_ERROR_IGNORE_EINVAL
92 } ngx_connection_log_error_e
;
96 NGX_TCP_NODELAY_UNSET
= 0,
98 NGX_TCP_NODELAY_DISABLED
99 } ngx_connection_tcp_nodelay_e
;
103 NGX_TCP_NOPUSH_UNSET
= 0,
105 NGX_TCP_NOPUSH_DISABLED
106 } ngx_connection_tcp_nopush_e
;
109 #define NGX_LOWLEVEL_BUFFERED 0x0f
110 #define NGX_SSL_BUFFERED 0x01
113 struct ngx_connection_s
{
122 ngx_recv_chain_pt recv_chain
;
123 ngx_send_chain_pt send_chain
;
125 ngx_listening_t
*listening
;
133 struct sockaddr
*sockaddr
;
138 ngx_ssl_connection_t
*ssl
;
141 struct sockaddr
*local_sockaddr
;
147 ngx_atomic_uint_t number
;
153 unsigned log_error
:3; /* ngx_connection_log_error_e */
155 unsigned unexpected_eof
:1;
158 unsigned destroyed
:1;
166 unsigned tcp_nodelay
:2; /* ngx_connection_tcp_nodelay_e */
167 unsigned tcp_nopush
:2; /* ngx_connection_tcp_nopush_e */
170 unsigned accept_context_updated
:1;
173 #if (NGX_HAVE_AIO_SENDFILE)
174 unsigned aio_sendfile
:1;
175 ngx_buf_t
*busy_sendfile
;
184 ngx_listening_t
*ngx_create_listening(ngx_conf_t
*cf
, void *sockaddr
,
186 ngx_int_t
ngx_set_inherited_sockets(ngx_cycle_t
*cycle
);
187 ngx_int_t
ngx_open_listening_sockets(ngx_cycle_t
*cycle
);
188 void ngx_configure_listening_sockets(ngx_cycle_t
*cycle
);
189 void ngx_close_listening_sockets(ngx_cycle_t
*cycle
);
190 void ngx_close_connection(ngx_connection_t
*c
);
191 ngx_int_t
ngx_connection_local_sockaddr(ngx_connection_t
*c
, ngx_str_t
*s
,
193 ngx_int_t
ngx_connection_error(ngx_connection_t
*c
, ngx_err_t err
, char *text
);
195 ngx_connection_t
*ngx_get_connection(ngx_socket_t s
, ngx_log_t
*log
);
196 void ngx_free_connection(ngx_connection_t
*c
);
198 void ngx_reusable_connection(ngx_connection_t
*c
, ngx_uint_t reusable
);
200 #endif /* _NGX_CONNECTION_H_INCLUDED_ */