src/stream/ngx_stream_upstream.h - nginx

Data types defined

Macros defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #ifndef _NGX_STREAM_UPSTREAM_H_INCLUDED_
  6. #define _NGX_STREAM_UPSTREAM_H_INCLUDED_


  7. #include <ngx_config.h>
  8. #include <ngx_core.h>
  9. #include <ngx_stream.h>
  10. #include <ngx_event_connect.h>


  11. #define NGX_STREAM_UPSTREAM_CREATE        0x0001
  12. #define NGX_STREAM_UPSTREAM_WEIGHT        0x0002
  13. #define NGX_STREAM_UPSTREAM_MAX_FAILS     0x0004
  14. #define NGX_STREAM_UPSTREAM_FAIL_TIMEOUT  0x0008
  15. #define NGX_STREAM_UPSTREAM_DOWN          0x0010
  16. #define NGX_STREAM_UPSTREAM_BACKUP        0x0020
  17. #define NGX_STREAM_UPSTREAM_MODIFY        0x0040
  18. #define NGX_STREAM_UPSTREAM_MAX_CONNS     0x0100


  19. #define NGX_STREAM_UPSTREAM_NOTIFY_CONNECT     0x1
  20. #define NGX_STREAM_UPSTREAM_NOTIFY_FIRST_BYTE  0x2


  21. typedef struct {
  22.     ngx_array_t                        upstreams;
  23.                                            /* ngx_stream_upstream_srv_conf_t */
  24. } ngx_stream_upstream_main_conf_t;


  25. typedef struct ngx_stream_upstream_srv_conf_s  ngx_stream_upstream_srv_conf_t;


  26. typedef ngx_int_t (*ngx_stream_upstream_init_pt)(ngx_conf_t *cf,
  27.     ngx_stream_upstream_srv_conf_t *us);
  28. typedef ngx_int_t (*ngx_stream_upstream_init_peer_pt)(ngx_stream_session_t *s,
  29.     ngx_stream_upstream_srv_conf_t *us);


  30. typedef struct {
  31.     ngx_stream_upstream_init_pt        init_upstream;
  32.     ngx_stream_upstream_init_peer_pt   init;
  33.     void                              *data;
  34. } ngx_stream_upstream_peer_t;


  35. typedef struct {
  36.     ngx_str_t                          name;
  37.     ngx_addr_t                        *addrs;
  38.     ngx_uint_t                         naddrs;
  39.     ngx_uint_t                         weight;
  40.     ngx_uint_t                         max_conns;
  41.     ngx_uint_t                         max_fails;
  42.     time_t                             fail_timeout;
  43.     ngx_msec_t                         slow_start;
  44.     ngx_uint_t                         down;

  45.     unsigned                           backup:1;

  46. #if (NGX_STREAM_UPSTREAM_ZONE)
  47.     ngx_str_t                          host;
  48.     ngx_str_t                          service;
  49. #endif
  50. } ngx_stream_upstream_server_t;


  51. struct ngx_stream_upstream_srv_conf_s {
  52.     ngx_stream_upstream_peer_t         peer;
  53.     void                             **srv_conf;

  54.     ngx_array_t                       *servers;
  55.                                               /* ngx_stream_upstream_server_t */

  56.     ngx_uint_t                         flags;
  57.     ngx_str_t                          host;
  58.     u_char                            *file_name;
  59.     ngx_uint_t                         line;
  60.     in_port_t                          port;
  61.     ngx_uint_t                         no_port;  /* unsigned no_port:1 */

  62. #if (NGX_STREAM_UPSTREAM_ZONE)
  63.     ngx_shm_zone_t                    *shm_zone;
  64.     ngx_resolver_t                    *resolver;
  65.     ngx_msec_t                         resolver_timeout;
  66. #endif
  67. };


  68. typedef struct {
  69.     ngx_msec_t                         response_time;
  70.     ngx_msec_t                         connect_time;
  71.     ngx_msec_t                         first_byte_time;
  72.     off_t                              bytes_sent;
  73.     off_t                              bytes_received;

  74.     ngx_str_t                         *peer;
  75. } ngx_stream_upstream_state_t;


  76. typedef struct {
  77.     ngx_str_t                          host;
  78.     in_port_t                          port;
  79.     ngx_uint_t                         no_port; /* unsigned no_port:1 */

  80.     ngx_uint_t                         naddrs;
  81.     ngx_resolver_addr_t               *addrs;

  82.     struct sockaddr                   *sockaddr;
  83.     socklen_t                          socklen;
  84.     ngx_str_t                          name;

  85.     ngx_resolver_ctx_t                *ctx;
  86. } ngx_stream_upstream_resolved_t;


  87. typedef struct {
  88.     ngx_peer_connection_t              peer;

  89.     ngx_buf_t                          downstream_buf;
  90.     ngx_buf_t                          upstream_buf;

  91.     ngx_chain_t                       *free;
  92.     ngx_chain_t                       *upstream_out;
  93.     ngx_chain_t                       *upstream_busy;
  94.     ngx_chain_t                       *downstream_out;
  95.     ngx_chain_t                       *downstream_busy;

  96.     off_t                              received;
  97.     time_t                             start_sec;
  98.     ngx_uint_t                         requests;
  99.     ngx_uint_t                         responses;
  100.     ngx_msec_t                         start_time;

  101.     size_t                             upload_rate;
  102.     size_t                             download_rate;

  103.     ngx_str_t                          ssl_name;

  104.     ngx_stream_upstream_srv_conf_t    *upstream;
  105.     ngx_stream_upstream_resolved_t    *resolved;
  106.     ngx_stream_upstream_state_t       *state;
  107.     unsigned                           connected:1;
  108.     unsigned                           proxy_protocol:1;
  109.     unsigned                           half_closed:1;
  110. } ngx_stream_upstream_t;


  111. ngx_stream_upstream_srv_conf_t *ngx_stream_upstream_add(ngx_conf_t *cf,
  112.     ngx_url_t *u, ngx_uint_t flags);


  113. #define ngx_stream_conf_upstream_srv_conf(uscf, module)                       \
  114.     uscf->srv_conf[module.ctx_index]


  115. extern ngx_module_t  ngx_stream_upstream_module;


  116. #endif /* _NGX_STREAM_UPSTREAM_H_INCLUDED_ */