Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.12 ]​[ nginx-1.16.0 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #ifndef _NGX_CONNECTION_H_INCLUDED_
0009 #define _NGX_CONNECTION_H_INCLUDED_
0010 
0011 
0012 #include <ngx_config.h>
0013 #include <ngx_core.h>
0014 
0015 
0016 typedef struct ngx_listening_s  ngx_listening_t;
0017 
0018 struct ngx_listening_s {
0019     ngx_socket_t        fd;
0020 
0021     struct sockaddr    *sockaddr;
0022     socklen_t           socklen;    /* size of sockaddr */
0023     size_t              addr_text_max_len;
0024     ngx_str_t           addr_text;
0025 
0026     int                 type;
0027 
0028     int                 backlog;
0029     int                 rcvbuf;
0030     int                 sndbuf;
0031 #if (NGX_HAVE_KEEPALIVE_TUNABLE)
0032     int                 keepidle;
0033     int                 keepintvl;
0034     int                 keepcnt;
0035 #endif
0036 
0037     /* handler of accepted connection */
0038     ngx_connection_handler_pt   handler;
0039 
0040     void               *servers;  /* array of ngx_http_in_addr_t, for example */
0041 
0042     ngx_log_t           log;
0043     ngx_log_t          *logp;
0044 
0045     size_t              pool_size;
0046     /* should be here because of the AcceptEx() preread */
0047     size_t              post_accept_buffer_size;
0048     /* should be here because of the deferred accept */
0049     ngx_msec_t          post_accept_timeout;
0050 
0051     ngx_listening_t    *previous;
0052     ngx_connection_t   *connection;
0053 
0054     ngx_rbtree_t        rbtree;
0055     ngx_rbtree_node_t   sentinel;
0056 
0057     ngx_uint_t          worker;
0058 
0059     unsigned            open:1;
0060     unsigned            remain:1;
0061     unsigned            ignore:1;
0062 
0063     unsigned            bound:1;       /* already bound */
0064     unsigned            inherited:1;   /* inherited from previous process */
0065     unsigned            nonblocking_accept:1;
0066     unsigned            listen:1;
0067     unsigned            nonblocking:1;
0068     unsigned            shared:1;    /* shared between threads or processes */
0069     unsigned            addr_ntop:1;
0070     unsigned            wildcard:1;
0071 
0072 #if (NGX_HAVE_INET6)
0073     unsigned            ipv6only:1;
0074 #endif
0075     unsigned            reuseport:1;
0076     unsigned            add_reuseport:1;
0077     unsigned            keepalive:2;
0078 
0079     unsigned            deferred_accept:1;
0080     unsigned            delete_deferred:1;
0081     unsigned            add_deferred:1;
0082 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
0083     char               *accept_filter;
0084 #endif
0085 #if (NGX_HAVE_SETFIB)
0086     int                 setfib;
0087 #endif
0088 
0089 #if (NGX_HAVE_TCP_FASTOPEN)
0090     int                 fastopen;
0091 #endif
0092 
0093 };
0094 
0095 
0096 typedef enum {
0097     NGX_ERROR_ALERT = 0,
0098     NGX_ERROR_ERR,
0099     NGX_ERROR_INFO,
0100     NGX_ERROR_IGNORE_ECONNRESET,
0101     NGX_ERROR_IGNORE_EINVAL
0102 } ngx_connection_log_error_e;
0103 
0104 
0105 typedef enum {
0106     NGX_TCP_NODELAY_UNSET = 0,
0107     NGX_TCP_NODELAY_SET,
0108     NGX_TCP_NODELAY_DISABLED
0109 } ngx_connection_tcp_nodelay_e;
0110 
0111 
0112 typedef enum {
0113     NGX_TCP_NOPUSH_UNSET = 0,
0114     NGX_TCP_NOPUSH_SET,
0115     NGX_TCP_NOPUSH_DISABLED
0116 } ngx_connection_tcp_nopush_e;
0117 
0118 
0119 #define NGX_LOWLEVEL_BUFFERED  0x0f
0120 #define NGX_SSL_BUFFERED       0x01
0121 #define NGX_HTTP_V2_BUFFERED   0x02
0122 
0123 
0124 struct ngx_connection_s {
0125     void               *data;
0126     ngx_event_t        *read;
0127     ngx_event_t        *write;
0128 
0129     ngx_socket_t        fd;
0130 
0131     ngx_recv_pt         recv;
0132     ngx_send_pt         send;
0133     ngx_recv_chain_pt   recv_chain;
0134     ngx_send_chain_pt   send_chain;
0135 
0136     ngx_listening_t    *listening;
0137 
0138     off_t               sent;
0139 
0140     ngx_log_t          *log;
0141 
0142     ngx_pool_t         *pool;
0143 
0144     int                 type;
0145 
0146     struct sockaddr    *sockaddr;
0147     socklen_t           socklen;
0148     ngx_str_t           addr_text;
0149 
0150     ngx_str_t           proxy_protocol_addr;
0151     in_port_t           proxy_protocol_port;
0152 
0153 #if (NGX_SSL || NGX_COMPAT)
0154     ngx_ssl_connection_t  *ssl;
0155 #endif
0156 
0157     ngx_udp_connection_t  *udp;
0158 
0159     struct sockaddr    *local_sockaddr;
0160     socklen_t           local_socklen;
0161 
0162     ngx_buf_t          *buffer;
0163 
0164     ngx_queue_t         queue;
0165 
0166     ngx_atomic_uint_t   number;
0167 
0168     ngx_uint_t          requests;
0169 
0170     unsigned            buffered:8;
0171 
0172     unsigned            log_error:3;     /* ngx_connection_log_error_e */
0173 
0174     unsigned            timedout:1;
0175     unsigned            error:1;
0176     unsigned            destroyed:1;
0177 
0178     unsigned            idle:1;
0179     unsigned            reusable:1;
0180     unsigned            close:1;
0181     unsigned            shared:1;
0182 
0183     unsigned            sendfile:1;
0184     unsigned            sndlowat:1;
0185     unsigned            tcp_nodelay:2;   /* ngx_connection_tcp_nodelay_e */
0186     unsigned            tcp_nopush:2;    /* ngx_connection_tcp_nopush_e */
0187 
0188     unsigned            need_last_buf:1;
0189 
0190 #if (NGX_HAVE_AIO_SENDFILE || NGX_COMPAT)
0191     unsigned            busy_count:2;
0192 #endif
0193 
0194 #if (NGX_THREADS || NGX_COMPAT)
0195     ngx_thread_task_t  *sendfile_task;
0196 #endif
0197 };
0198 
0199 
0200 #define ngx_set_connection_log(c, l)                                         \
0201                                                                              \
0202     c->log->file = l->file;                                                  \
0203     c->log->next = l->next;                                                  \
0204     c->log->writer = l->writer;                                              \
0205     c->log->wdata = l->wdata;                                                \
0206     if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {                   \
0207         c->log->log_level = l->log_level;                                    \
0208     }
0209 
0210 
0211 ngx_listening_t *ngx_create_listening(ngx_conf_t *cf, struct sockaddr *sockaddr,
0212     socklen_t socklen);
0213 ngx_int_t ngx_clone_listening(ngx_cycle_t *cycle, ngx_listening_t *ls);
0214 ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle);
0215 ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle);
0216 void ngx_configure_listening_sockets(ngx_cycle_t *cycle);
0217 void ngx_close_listening_sockets(ngx_cycle_t *cycle);
0218 void ngx_close_connection(ngx_connection_t *c);
0219 void ngx_close_idle_connections(ngx_cycle_t *cycle);
0220 ngx_int_t ngx_connection_local_sockaddr(ngx_connection_t *c, ngx_str_t *s,
0221     ngx_uint_t port);
0222 ngx_int_t ngx_tcp_nodelay(ngx_connection_t *c);
0223 ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text);
0224 
0225 ngx_connection_t *ngx_get_connection(ngx_socket_t s, ngx_log_t *log);
0226 void ngx_free_connection(ngx_connection_t *c);
0227 
0228 void ngx_reusable_connection(ngx_connection_t *c, ngx_uint_t reusable);
0229 
0230 #endif /* _NGX_CONNECTION_H_INCLUDED_ */