Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.13.12 ]​[ nginx-1.12.2 ]​

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_uint_t          worker;
0055 
0056     unsigned            open:1;
0057     unsigned            remain:1;
0058     unsigned            ignore:1;
0059 
0060     unsigned            bound:1;       /* already bound */
0061     unsigned            inherited:1;   /* inherited from previous process */
0062     unsigned            nonblocking_accept:1;
0063     unsigned            listen:1;
0064     unsigned            nonblocking:1;
0065     unsigned            shared:1;    /* shared between threads or processes */
0066     unsigned            addr_ntop:1;
0067     unsigned            wildcard:1;
0068 
0069 #if (NGX_HAVE_INET6)
0070     unsigned            ipv6only:1;
0071 #endif
0072     unsigned            reuseport:1;
0073     unsigned            add_reuseport:1;
0074     unsigned            keepalive:2;
0075 
0076     unsigned            deferred_accept:1;
0077     unsigned            delete_deferred:1;
0078     unsigned            add_deferred:1;
0079 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
0080     char               *accept_filter;
0081 #endif
0082 #if (NGX_HAVE_SETFIB)
0083     int                 setfib;
0084 #endif
0085 
0086 #if (NGX_HAVE_TCP_FASTOPEN)
0087     int                 fastopen;
0088 #endif
0089 
0090 };
0091 
0092 
0093 typedef enum {
0094     NGX_ERROR_ALERT = 0,
0095     NGX_ERROR_ERR,
0096     NGX_ERROR_INFO,
0097     NGX_ERROR_IGNORE_ECONNRESET,
0098     NGX_ERROR_IGNORE_EINVAL
0099 } ngx_connection_log_error_e;
0100 
0101 
0102 typedef enum {
0103     NGX_TCP_NODELAY_UNSET = 0,
0104     NGX_TCP_NODELAY_SET,
0105     NGX_TCP_NODELAY_DISABLED
0106 } ngx_connection_tcp_nodelay_e;
0107 
0108 
0109 typedef enum {
0110     NGX_TCP_NOPUSH_UNSET = 0,
0111     NGX_TCP_NOPUSH_SET,
0112     NGX_TCP_NOPUSH_DISABLED
0113 } ngx_connection_tcp_nopush_e;
0114 
0115 
0116 #define NGX_LOWLEVEL_BUFFERED  0x0f
0117 #define NGX_SSL_BUFFERED       0x01
0118 #define NGX_HTTP_V2_BUFFERED   0x02
0119 
0120 
0121 struct ngx_connection_s {
0122     void               *data;
0123     ngx_event_t        *read;
0124     ngx_event_t        *write;
0125 
0126     ngx_socket_t        fd;
0127 
0128     ngx_recv_pt         recv;
0129     ngx_send_pt         send;
0130     ngx_recv_chain_pt   recv_chain;
0131     ngx_send_chain_pt   send_chain;
0132 
0133     ngx_listening_t    *listening;
0134 
0135     off_t               sent;
0136 
0137     ngx_log_t          *log;
0138 
0139     ngx_pool_t         *pool;
0140 
0141     int                 type;
0142 
0143     struct sockaddr    *sockaddr;
0144     socklen_t           socklen;
0145     ngx_str_t           addr_text;
0146 
0147     ngx_str_t           proxy_protocol_addr;
0148     in_port_t           proxy_protocol_port;
0149 
0150 #if (NGX_SSL || NGX_COMPAT)
0151     ngx_ssl_connection_t  *ssl;
0152 #endif
0153 
0154     struct sockaddr    *local_sockaddr;
0155     socklen_t           local_socklen;
0156 
0157     ngx_buf_t          *buffer;
0158 
0159     ngx_queue_t         queue;
0160 
0161     ngx_atomic_uint_t   number;
0162 
0163     ngx_uint_t          requests;
0164 
0165     unsigned            buffered:8;
0166 
0167     unsigned            log_error:3;     /* ngx_connection_log_error_e */
0168 
0169     unsigned            timedout:1;
0170     unsigned            error:1;
0171     unsigned            destroyed:1;
0172 
0173     unsigned            idle:1;
0174     unsigned            reusable:1;
0175     unsigned            close:1;
0176     unsigned            shared:1;
0177 
0178     unsigned            sendfile:1;
0179     unsigned            sndlowat:1;
0180     unsigned            tcp_nodelay:2;   /* ngx_connection_tcp_nodelay_e */
0181     unsigned            tcp_nopush:2;    /* ngx_connection_tcp_nopush_e */
0182 
0183     unsigned            need_last_buf:1;
0184 
0185 #if (NGX_HAVE_AIO_SENDFILE || NGX_COMPAT)
0186     unsigned            busy_count:2;
0187 #endif
0188 
0189 #if (NGX_THREADS || NGX_COMPAT)
0190     ngx_thread_task_t  *sendfile_task;
0191 #endif
0192 };
0193 
0194 
0195 #define ngx_set_connection_log(c, l)                                         \
0196                                                                              \
0197     c->log->file = l->file;                                                  \
0198     c->log->next = l->next;                                                  \
0199     c->log->writer = l->writer;                                              \
0200     c->log->wdata = l->wdata;                                                \
0201     if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {                   \
0202         c->log->log_level = l->log_level;                                    \
0203     }
0204 
0205 
0206 ngx_listening_t *ngx_create_listening(ngx_conf_t *cf, struct sockaddr *sockaddr,
0207     socklen_t socklen);
0208 ngx_int_t ngx_clone_listening(ngx_conf_t *cf, ngx_listening_t *ls);
0209 ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle);
0210 ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle);
0211 void ngx_configure_listening_sockets(ngx_cycle_t *cycle);
0212 void ngx_close_listening_sockets(ngx_cycle_t *cycle);
0213 void ngx_close_connection(ngx_connection_t *c);
0214 void ngx_close_idle_connections(ngx_cycle_t *cycle);
0215 ngx_int_t ngx_connection_local_sockaddr(ngx_connection_t *c, ngx_str_t *s,
0216     ngx_uint_t port);
0217 ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text);
0218 
0219 ngx_connection_t *ngx_get_connection(ngx_socket_t s, ngx_log_t *log);
0220 void ngx_free_connection(ngx_connection_t *c);
0221 
0222 void ngx_reusable_connection(ngx_connection_t *c, ngx_uint_t reusable);
0223 
0224 #endif /* _NGX_CONNECTION_H_INCLUDED_ */