Permalink
Browse files

tidy the source

  • Loading branch information...
1 parent 77a7461 commit c07017130caa6e50686dcc71d1ecb4658fc23952 @yaoweibin committed Oct 20, 2011
@@ -28,8 +28,8 @@ typedef struct ngx_tcp_proxy_conf_s {
static void ngx_tcp_proxy_init_session(ngx_tcp_session_t *s);
-static void ngx_tcp_proxy_init(ngx_connection_t *c, ngx_tcp_session_t *s);
-static void ngx_tcp_upstream_proxy_generic_handler(ngx_tcp_session_t *s,
+static void ngx_tcp_proxy_init_upstream(ngx_connection_t *c, ngx_tcp_session_t *s);
+static void ngx_tcp_upstream_init_proxy_handler(ngx_tcp_session_t *s,
ngx_tcp_upstream_t *u);
static char *ngx_tcp_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static void ngx_tcp_proxy_dummy_read_handler(ngx_event_t *ev);
@@ -125,9 +125,14 @@ ngx_tcp_proxy_init_session(ngx_tcp_session_t *s)
{
ngx_connection_t *c;
ngx_tcp_proxy_conf_t *pcf;
+ ngx_tcp_core_srv_conf_t *cscf;
c = s->connection;
+ ngx_log_debug0(NGX_LOG_DEBUG_TCP, c->log, 0, "tcp proxy init session");
+
+ cscf = ngx_tcp_get_module_srv_conf(s, ngx_tcp_core_module);
+
pcf = ngx_tcp_get_module_srv_conf(s, ngx_tcp_proxy_module);
s->buffer = ngx_create_temp_buf(s->connection->pool, pcf->buffer_size);
@@ -136,17 +141,14 @@ ngx_tcp_proxy_init_session(ngx_tcp_session_t *s)
return;
}
+ s->out.len = 0;
+
c->write->handler = ngx_tcp_proxy_dummy_write_handler;
c->read->handler = ngx_tcp_proxy_dummy_read_handler;
- if (ngx_tcp_upstream_create(s) != NGX_OK) {
- ngx_tcp_finalize_session(s);
- return;
- }
+ ngx_add_timer(c->read, cscf->timeout);
- /*do something about the proxy related part in the session struct*/
-
- ngx_tcp_proxy_init(c, s);
+ ngx_tcp_proxy_init_upstream(c, s);
return;
}
@@ -187,13 +189,13 @@ ngx_tcp_proxy_dummy_read_handler(ngx_event_t *rev)
static void
-ngx_tcp_proxy_init(ngx_connection_t *c, ngx_tcp_session_t *s)
+ngx_tcp_proxy_init_upstream(ngx_connection_t *c, ngx_tcp_session_t *s)
{
ngx_tcp_upstream_t *u;
ngx_tcp_proxy_ctx_t *p;
ngx_tcp_proxy_conf_t *pcf;
- s->connection->log->action = "ngx_tcp_proxy_init";
+ s->connection->log->action = "ngx_tcp_proxy_init_upstream";
pcf = ngx_tcp_get_module_srv_conf(s, ngx_tcp_proxy_module);
@@ -205,12 +207,17 @@ ngx_tcp_proxy_init(ngx_connection_t *c, ngx_tcp_session_t *s)
ngx_tcp_set_ctx(s, p, ngx_tcp_proxy_module);
+ if (ngx_tcp_upstream_create(s) != NGX_OK) {
+ ngx_tcp_finalize_session(s);
+ return;
+ }
+
u = s->upstream;
u->conf = &pcf->upstream;
- u->write_event_handler = ngx_tcp_upstream_proxy_generic_handler;
- u->read_event_handler = ngx_tcp_upstream_proxy_generic_handler;
+ u->write_event_handler = ngx_tcp_upstream_init_proxy_handler;
+ u->read_event_handler = ngx_tcp_upstream_init_proxy_handler;
p->upstream = &u->peer;
@@ -220,16 +227,14 @@ ngx_tcp_proxy_init(ngx_connection_t *c, ngx_tcp_session_t *s)
return;
}
- s->out.len = 0;
-
ngx_tcp_upstream_init(s);
return;
}
static void
-ngx_tcp_upstream_proxy_generic_handler(ngx_tcp_session_t *s, ngx_tcp_upstream_t *u)
+ngx_tcp_upstream_init_proxy_handler(ngx_tcp_session_t *s, ngx_tcp_upstream_t *u)
{
ngx_connection_t *c;
ngx_tcp_proxy_ctx_t *pctx;
@@ -239,7 +244,7 @@ ngx_tcp_upstream_proxy_generic_handler(ngx_tcp_session_t *s, ngx_tcp_upstream_t
cscf = ngx_tcp_get_module_srv_conf(s, ngx_tcp_core_module);
c = s->connection;
- c->log->action = "ngx_tcp_proxy_handler";
+ c->log->action = "ngx_tcp_upstream_init_proxy_handler";
ngx_log_debug0(NGX_LOG_DEBUG_TCP, s->connection->log, 0, "tcp proxy upstream init proxy");
@@ -271,8 +276,6 @@ ngx_tcp_upstream_proxy_generic_handler(ngx_tcp_session_t *s, ngx_tcp_upstream_t
c->read->handler = ngx_tcp_proxy_handler;
c->write->handler = ngx_tcp_proxy_handler;
- ngx_add_timer(s->connection->read, cscf->timeout);
-
ngx_add_timer(c->read, pcf->upstream.read_timeout);
ngx_add_timer(c->write, pcf->upstream.send_timeout);
@@ -454,7 +457,7 @@ ngx_tcp_proxy_handler(ngx_event_t *ev)
{
action = c->log->action;
c->log->action = NULL;
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "proxied session done");
+ ngx_log_error(NGX_LOG_DEBUG, c->log, 0, "proxied session done");
c->log->action = action;
ngx_tcp_finalize_session(s);
@@ -152,6 +152,8 @@ ngx_tcp_websocket_init_session(ngx_tcp_session_t *s)
c = s->connection;
+ ngx_log_debug0(NGX_LOG_DEBUG_TCP, c->log, 0, "tcp websocket init session");
+
cscf = ngx_tcp_get_module_srv_conf(s, ngx_tcp_core_module);
wcf = ngx_tcp_get_module_srv_conf(s, ngx_tcp_websocket_module);
@@ -866,7 +868,7 @@ ngx_tcp_websocket_proxy_handler(ngx_event_t *ev)
{
action = c->log->action;
c->log->action = NULL;
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "proxied session done");
+ ngx_log_error(NGX_LOG_DEBUG, c->log, 0, "proxied session done");
c->log->action = action;
ngx_tcp_finalize_session(s);
View
@@ -66,6 +66,13 @@ typedef struct {
} ngx_tcp_server_name_t;
+typedef struct {
+ ngx_uint_t hash;
+ ngx_str_t name;
+ ngx_tcp_conf_ctx_t *ctx;
+} ngx_tcp_virtual_server_t;
+
+
typedef struct {
ngx_str_t name;
} ngx_tcp_core_loc_t;
View
@@ -14,6 +14,7 @@ static void ngx_tcp_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c);
static void ngx_tcp_ssl_handshake_handler(ngx_connection_t *c);
#endif
+
void
ngx_tcp_init_connection(ngx_connection_t *c)
{
View
@@ -41,6 +41,7 @@ typedef struct ngx_tcp_session_s {
} ngx_tcp_session_t;
+
typedef void (*ngx_tcp_cleanup_pt)(void *data);
View
@@ -41,60 +41,60 @@ static ngx_conf_bitmask_t ngx_check_smtp_expect_alive_masks[] = {
static ngx_command_t ngx_tcp_upstream_commands[] = {
{ ngx_string("upstream"),
- NGX_TCP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1,
- ngx_tcp_upstream,
- 0,
- 0,
- NULL },
+ NGX_TCP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1,
+ ngx_tcp_upstream,
+ 0,
+ 0,
+ NULL },
{ ngx_string("server"),
- NGX_TCP_UPS_CONF|NGX_CONF_1MORE,
- ngx_tcp_upstream_server,
- NGX_TCP_SRV_CONF_OFFSET,
- 0,
- NULL },
+ NGX_TCP_UPS_CONF|NGX_CONF_1MORE,
+ ngx_tcp_upstream_server,
+ NGX_TCP_SRV_CONF_OFFSET,
+ 0,
+ NULL },
{ ngx_string("check"),
- NGX_TCP_UPS_CONF|NGX_CONF_1MORE,
- ngx_tcp_upstream_check,
- NGX_TCP_SRV_CONF_OFFSET,
- 0,
- NULL },
+ NGX_TCP_UPS_CONF|NGX_CONF_1MORE,
+ ngx_tcp_upstream_check,
+ NGX_TCP_SRV_CONF_OFFSET,
+ 0,
+ NULL },
{ ngx_string("check_http_send"),
- NGX_TCP_UPS_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_str_slot,
- NGX_TCP_SRV_CONF_OFFSET,
- offsetof(ngx_tcp_upstream_srv_conf_t, send),
- NULL },
+ NGX_TCP_UPS_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_str_slot,
+ NGX_TCP_SRV_CONF_OFFSET,
+ offsetof(ngx_tcp_upstream_srv_conf_t, send),
+ NULL },
{ ngx_string("check_smtp_send"),
- NGX_TCP_UPS_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_str_slot,
- NGX_TCP_SRV_CONF_OFFSET,
- offsetof(ngx_tcp_upstream_srv_conf_t, send),
- NULL },
+ NGX_TCP_UPS_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_str_slot,
+ NGX_TCP_SRV_CONF_OFFSET,
+ offsetof(ngx_tcp_upstream_srv_conf_t, send),
+ NULL },
{ ngx_string("check_http_expect_alive"),
- NGX_TCP_UPS_CONF|NGX_CONF_1MORE,
- ngx_conf_set_bitmask_slot,
- NGX_TCP_SRV_CONF_OFFSET,
- offsetof(ngx_tcp_upstream_srv_conf_t, status_alive),
- &ngx_check_http_expect_alive_masks },
+ NGX_TCP_UPS_CONF|NGX_CONF_1MORE,
+ ngx_conf_set_bitmask_slot,
+ NGX_TCP_SRV_CONF_OFFSET,
+ offsetof(ngx_tcp_upstream_srv_conf_t, status_alive),
+ &ngx_check_http_expect_alive_masks },
{ ngx_string("check_smtp_expect_alive"),
- NGX_TCP_UPS_CONF|NGX_CONF_1MORE,
- ngx_conf_set_bitmask_slot,
- NGX_TCP_SRV_CONF_OFFSET,
- offsetof(ngx_tcp_upstream_srv_conf_t, status_alive),
- &ngx_check_smtp_expect_alive_masks },
+ NGX_TCP_UPS_CONF|NGX_CONF_1MORE,
+ ngx_conf_set_bitmask_slot,
+ NGX_TCP_SRV_CONF_OFFSET,
+ offsetof(ngx_tcp_upstream_srv_conf_t, status_alive),
+ &ngx_check_smtp_expect_alive_masks },
{ ngx_string("check_shm_size"),
- NGX_TCP_MAIN_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_size_slot,
- NGX_TCP_MAIN_CONF_OFFSET,
- offsetof(ngx_tcp_upstream_main_conf_t, check_shm_size),
- NULL },
+ NGX_TCP_MAIN_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_size_slot,
+ NGX_TCP_MAIN_CONF_OFFSET,
+ offsetof(ngx_tcp_upstream_main_conf_t, check_shm_size),
+ NULL },
ngx_null_command
};
@@ -35,9 +35,8 @@ our $WorkerConnections = 1024;
our $LogLevel = 'debug';
our $MasterProcessEnabled = 'off';
our $DaemonEnabled = 'on';
-our $ServerPort = 1982;
-our $ServerPortForClient = 1982;
-#our $ServerPortForClient = 1984;
+our $ServerPort = 1984;
+our $ServerPortForClient = 1984;
sub repeat_each (@) {
View
@@ -38,7 +38,7 @@ __DATA__
server {
deny 127.0.0.1;
- listen 1982;
+ listen 1984;
proxy_pass test;
}
View
@@ -40,7 +40,7 @@ __DATA__
}
server {
- listen 1982;
+ listen 1984;
proxy_pass test;
}
@@ -55,7 +55,7 @@ GET /
}
server {
- listen 1982;
+ listen 1984;
proxy_pass test;
}
@@ -74,7 +74,7 @@ GET /
}
server {
- listen 1982;
+ listen 1984;
proxy_pass blog.163.com;
}
View
@@ -38,7 +38,7 @@ __DATA__
}
server {
- listen 1982;
+ listen 1984;
proxy_pass test;
}
View
@@ -39,7 +39,7 @@ __DATA__
}
server {
- listen 1982;
+ listen 1984;
proxy_pass test;
}
View
@@ -39,7 +39,7 @@ __DATA__
}
server {
- listen 1982;
+ listen 1984;
proxy_pass test;
}
View
@@ -41,7 +41,7 @@ __DATA__
}
server {
- listen 1982;
+ listen 1984;
proxy_pass test;
}
View
@@ -45,7 +45,7 @@ __DATA__
}
server {
- listen 1982 ssl;
+ listen 1984 ssl;
proxy_pass test;
}
View
@@ -39,7 +39,7 @@ __DATA__
}
server {
- listen 1982;
+ listen 1984;
proxy_pass test;
}
Oops, something went wrong.

0 comments on commit c070171

Please sign in to comment.