代码拉取完成,页面将自动刷新
multi_c
to the end of ngx_connection_s
(#11)
diff --git src/core/ngx_connection.h src/core/ngx_connection.h
--- src/core/ngx_connection.h
+++ src/core/ngx_connection.h
@@ -193,6 +193,9 @@ struct ngx_connection_s {
#if (NGX_THREADS || NGX_COMPAT)
ngx_thread_task_t *sendfile_task;
#endif
+#if (T_NGX_MULTI_UPSTREAM)
+ void *multi_c;
+#endif
};
diff --git src/http/ngx_http_request.h src/http/ngx_http_request.h
--- src/http/ngx_http_request.h
+++ src/http/ngx_http_request.h
@@ -593,6 +593,13 @@ struct ngx_http_request_s {
unsigned http_minor:16;
unsigned http_major:16;
+
+#if (T_NGX_MULTI_UPSTREAM)
+ ngx_queue_t *multi_item;
+ ngx_queue_t *backend_r;
+ ngx_queue_t waiting_queue;
+ ngx_flag_t waiting;
+#endif
};
diff --git src/http/ngx_http_upstream.c src/http/ngx_http_upstream.c
--- src/http/ngx_http_upstream.c
+++ src/http/ngx_http_upstream.c
@@ -9,6 +9,10 @@
#include <ngx_core.h>
#include <ngx_http.h>
+#if (T_NGX_MULTI_UPSTREAM)
+#include <ngx_http_multi_upstream_module.h>
+#endif
+
#if (NGX_HTTP_CACHE)
static ngx_int_t ngx_http_upstream_cache(ngx_http_request_t *r,
@@ -1502,6 +1506,12 @@ ngx_http_upstream_check_broken_connection(ngx_http_request_t *r,
}
+#if (T_NGX_MULTI_UPSTREAM)
+
+#include "ngx_http_multi_upstream.c"
+
+#endif /* T_NGX_MULTI_UPSTREAM */
+
static void
ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
@@ -1562,6 +1572,47 @@ ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
c = u->peer.connection;
+#if (T_NGX_MULTI_UPSTREAM)
+ if (u->multi) {
+ if (!(u->multi_mode & NGX_MULTI_UPS_SUPPORT_MULTI)) {
+ ngx_http_multi_upstream_finalize_request(c,
+ NGX_HTTP_INTERNAL_SERVER_ERROR);
+ ngx_log_error(NGX_LOG_ERR, c->log, 0,
+ "multi: upstream configured multi, but handler no support");
+ return;
+ }
+
+ if (rc == NGX_AGAIN) { //first real connect
+ c->read->handler = ngx_http_multi_upstream_connect_handler;
+ c->write->handler = ngx_http_multi_upstream_connect_handler;
+ ngx_add_timer(c->write, u->conf->connect_timeout);
+ ngx_log_error(NGX_LOG_INFO, c->log, 0,
+ "multi: connect new to backend %p", c);
+ } else if (rc == NGX_DONE) { //use exist connection
+ if (ngx_multi_connected(c)) {
+ ngx_log_error(NGX_LOG_INFO, c->log, 0, "multi: connect reuse %p", c);
+
+ ngx_http_multi_upstream_init_request(c, r);
+ ngx_http_multi_upstream_process(c, 1);
+ } else {
+ ngx_log_error(NGX_LOG_ERR, c->log, 0, "multi: connect reuse unfinished %p", c);
+ }
+ } else {
+ ngx_log_error(NGX_LOG_ERR, c->log, 0,
+ "multi: connect return %i error", rc);
+ }
+
+ return;
+ } else if ((u->multi_mode & NGX_MULTI_UPS_NEED_MULTI) == NGX_MULTI_UPS_NEED_MULTI) {
+ ngx_http_upstream_finalize_request(r, u,
+ NGX_HTTP_INTERNAL_SERVER_ERROR);
+ ngx_log_error(NGX_LOG_ERR, c->log, 0,
+ "multi: need multi, but upstream not support, "
+ "maybee need configuration 'multi' in upstream");
+ return;
+ }
+#endif
+
c->requests++;
c->data = r;
@@ -1780,6 +1831,13 @@ ngx_http_upstream_ssl_handshake(ngx_http_request_t *r, ngx_http_upstream_t *u,
}
}
+#if (T_NGX_MULTI_UPSTREAM)
+ if (u->multi) {
+ ngx_http_multi_upstream_connect_init(c);
+ return;
+ }
+#endif
+
c->write->handler = ngx_http_upstream_handler;
c->read->handler = ngx_http_upstream_handler;
@@ -2063,6 +2121,14 @@ ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u,
c->tcp_nopush = NGX_TCP_NOPUSH_UNSET;
}
+#if (T_NGX_MULTI_UPSTREAM)
+ if (u->multi && r->connection != u->peer.connection && !r->waiting) {
+ ngx_multi_connection_t *multi_c = ngx_get_multi_connection(c);
+ ngx_queue_insert_tail(&multi_c->waiting_list, &r->waiting_queue);
+ r->waiting = 1;
+ }
+#endif
+
return;
}
@@ -2104,6 +2170,12 @@ ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u,
ngx_add_timer(c->read, u->read_timeout);
if (c->read->ready) {
+#if (T_NGX_MULTI_UPSTREAM)
+ if (u->multi) {
+ ngx_http_multi_upstream_read_handler(c);
+ return;
+ }
+#endif
ngx_http_upstream_process_header(r, u);
return;
}
@@ -2141,6 +2213,11 @@ ngx_http_upstream_send_request_body(ngx_http_request_t *r,
u->request_body_blocked = 1;
} else {
+#if T_NGX_MULTI_UPSTREAM
+ if (u->multi && rc == NGX_OK) {
+ ngx_multi_clean_leak(u->peer.connection);
+ }
+#endif
u->request_body_blocked = 0;
}
@@ -3555,6 +3632,13 @@ ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r)
return;
}
+#if (T_NGX_MULTI_UPSTREAM)
+ if (u->multi) {
+ ngx_http_multi_upstream_process_non_buffered_request(r);
+ return;
+ }
+#endif
+
ngx_http_upstream_process_non_buffered_request(r, 1);
}
@@ -4183,6 +4267,16 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http next upstream, %xi", ft_type);
+#if (T_NGX_MULTI_UPSTREAM)
+ if (u->multi && ngx_http_multi_connection_fake(r)) {
+ ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+ "multi: http next upstream fake_r %p", r);
+
+ ngx_http_multi_upstream_next(r->connection, ft_type);
+ return;
+ }
+#endif
+
if (u->peer.sockaddr) {
if (u->peer.connection) {
@@ -4350,6 +4444,16 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r,
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"finalize http upstream request: %i", rc);
+#if (T_NGX_MULTI_UPSTREAM)
+ if (u->multi && ngx_http_multi_connection_fake(r)) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "http finalize upstream fake_r %p", r);
+
+ ngx_http_multi_upstream_finalize_request(r->connection, rc);
+ return;
+ }
+#endif
+
if (u->cleanup == NULL) {
/* the request was already finalized */
ngx_http_finalize_request(r, NGX_DONE);
diff --git src/http/ngx_http_upstream.h src/http/ngx_http_upstream.h
--- src/http/ngx_http_upstream.h
+++ src/http/ngx_http_upstream.h
@@ -402,6 +402,14 @@ struct ngx_http_upstream_s {
unsigned request_body_sent:1;
unsigned request_body_blocked:1;
unsigned header_sent:1;
+
+#if (T_NGX_MULTI_UPSTREAM)
+ unsigned multi:1;
+ void *multi_init;
+ ngx_pool_t *send_pool;
+ ngx_flag_t multi_mode;
+#endif
+
};
diff --git src/stream/ngx_stream.h src/stream/ngx_stream.h
--- src/stream/ngx_stream.h
+++ src/stream/ngx_stream.h
@@ -229,6 +229,13 @@ struct ngx_stream_session_s {
unsigned health_check:1;
unsigned limit_conn_status:2;
+
+#if (T_NGX_MULTI_UPSTREAM)
+ ngx_queue_t *multi_item;
+ ngx_queue_t *backend_r;
+ ngx_queue_t waiting_queue;
+ ngx_flag_t waiting;
+#endif
};
diff --git src/stream/ngx_stream_upstream.h src/stream/ngx_stream_upstream.h
--- src/stream/ngx_stream_upstream.h
+++ src/stream/ngx_stream_upstream.h
@@ -142,6 +142,10 @@ typedef struct {
unsigned connected:1;
unsigned proxy_protocol:1;
unsigned half_closed:1;
+
+#if (T_NGX_MULTI_UPSTREAM)
+ unsigned multi:1;
+#endif
} ngx_stream_upstream_t;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。