Mercurial > hg > nginx
annotate src/stream/ngx_stream_upstream_round_robin.h @ 6435:d1c791479bbb
Stream: post first read events from client and upstream.
The main proxy function ngx_stream_proxy_process() can terminate the stream
session. The code, following it, should check its return code to make sure the
session still exists. This happens in client and upstream initialization
functions. Swapping ngx_stream_proxy_process() call with the code, that
follows it, leaves the same problem vice versa.
In future ngx_stream_proxy_process() will call ngx_stream_proxy_next_upstream()
making it too complicated to know if stream session still exists after this
call.
Now ngx_stream_proxy_process() is called from posted event handlers in both
places with no code following it. The posted event is automatically removed
once session is terminated.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Tue, 15 Mar 2016 15:55:23 +0300 |
parents | 311d232ad803 |
children | 9757cffc1e2f |
rev | line source |
---|---|
6115 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #ifndef _NGX_STREAM_UPSTREAM_ROUND_ROBIN_H_INCLUDED_ | |
9 #define _NGX_STREAM_UPSTREAM_ROUND_ROBIN_H_INCLUDED_ | |
10 | |
11 | |
12 #include <ngx_config.h> | |
13 #include <ngx_core.h> | |
14 #include <ngx_stream.h> | |
15 | |
16 | |
17 typedef struct ngx_stream_upstream_rr_peer_s ngx_stream_upstream_rr_peer_t; | |
18 | |
19 struct ngx_stream_upstream_rr_peer_s { | |
20 struct sockaddr *sockaddr; | |
21 socklen_t socklen; | |
22 ngx_str_t name; | |
23 ngx_str_t server; | |
24 | |
25 ngx_int_t current_weight; | |
26 ngx_int_t effective_weight; | |
27 ngx_int_t weight; | |
28 | |
29 ngx_uint_t conns; | |
30 | |
31 ngx_uint_t fails; | |
32 time_t accessed; | |
33 time_t checked; | |
34 | |
35 ngx_uint_t max_fails; | |
36 time_t fail_timeout; | |
37 | |
38 ngx_uint_t down; /* unsigned down:1; */ | |
39 | |
40 #if (NGX_STREAM_SSL) | |
41 void *ssl_session; | |
42 int ssl_session_len; | |
43 #endif | |
44 | |
45 ngx_stream_upstream_rr_peer_t *next; | |
46 | |
47 #if (NGX_STREAM_UPSTREAM_ZONE) | |
48 ngx_atomic_t lock; | |
49 #endif | |
50 }; | |
51 | |
52 | |
53 typedef struct ngx_stream_upstream_rr_peers_s ngx_stream_upstream_rr_peers_t; | |
54 | |
55 struct ngx_stream_upstream_rr_peers_s { | |
56 ngx_uint_t number; | |
57 | |
58 #if (NGX_STREAM_UPSTREAM_ZONE) | |
59 ngx_slab_pool_t *shpool; | |
60 ngx_atomic_t rwlock; | |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
61 ngx_stream_upstream_rr_peers_t *zone_next; |
6115 | 62 #endif |
63 | |
64 ngx_uint_t total_weight; | |
65 | |
66 unsigned single:1; | |
67 unsigned weighted:1; | |
68 | |
69 ngx_str_t *name; | |
70 | |
71 ngx_stream_upstream_rr_peers_t *next; | |
72 | |
73 ngx_stream_upstream_rr_peer_t *peer; | |
74 }; | |
75 | |
76 | |
77 #if (NGX_STREAM_UPSTREAM_ZONE) | |
78 | |
79 #define ngx_stream_upstream_rr_peers_rlock(peers) \ | |
80 \ | |
81 if (peers->shpool) { \ | |
82 ngx_rwlock_rlock(&peers->rwlock); \ | |
83 } | |
84 | |
85 #define ngx_stream_upstream_rr_peers_wlock(peers) \ | |
86 \ | |
87 if (peers->shpool) { \ | |
88 ngx_rwlock_wlock(&peers->rwlock); \ | |
89 } | |
90 | |
91 #define ngx_stream_upstream_rr_peers_unlock(peers) \ | |
92 \ | |
93 if (peers->shpool) { \ | |
94 ngx_rwlock_unlock(&peers->rwlock); \ | |
95 } | |
96 | |
97 | |
98 #define ngx_stream_upstream_rr_peer_lock(peers, peer) \ | |
99 \ | |
100 if (peers->shpool) { \ | |
101 ngx_rwlock_wlock(&peer->lock); \ | |
102 } | |
103 | |
104 #define ngx_stream_upstream_rr_peer_unlock(peers, peer) \ | |
105 \ | |
106 if (peers->shpool) { \ | |
107 ngx_rwlock_unlock(&peer->lock); \ | |
108 } | |
109 | |
110 #else | |
111 | |
112 #define ngx_stream_upstream_rr_peers_rlock(peers) | |
113 #define ngx_stream_upstream_rr_peers_wlock(peers) | |
114 #define ngx_stream_upstream_rr_peers_unlock(peers) | |
115 #define ngx_stream_upstream_rr_peer_lock(peers, peer) | |
116 #define ngx_stream_upstream_rr_peer_unlock(peers, peer) | |
117 | |
118 #endif | |
119 | |
120 | |
121 typedef struct { | |
122 ngx_stream_upstream_rr_peers_t *peers; | |
123 ngx_stream_upstream_rr_peer_t *current; | |
124 uintptr_t *tried; | |
125 uintptr_t data; | |
126 } ngx_stream_upstream_rr_peer_data_t; | |
127 | |
128 | |
129 ngx_int_t ngx_stream_upstream_init_round_robin(ngx_conf_t *cf, | |
130 ngx_stream_upstream_srv_conf_t *us); | |
131 ngx_int_t ngx_stream_upstream_init_round_robin_peer(ngx_stream_session_t *s, | |
132 ngx_stream_upstream_srv_conf_t *us); | |
133 ngx_int_t ngx_stream_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, | |
134 void *data); | |
135 void ngx_stream_upstream_free_round_robin_peer(ngx_peer_connection_t *pc, | |
136 void *data, ngx_uint_t state); | |
137 | |
138 | |
139 #endif /* _NGX_STREAM_UPSTREAM_ROUND_ROBIN_H_INCLUDED_ */ |