comparison src/mail/ngx_mail_handler.c @ 7791:d84f13618277

Mail: postponed session initialization under accept mutex. Similarly to 40e8ce405859 in the stream module, this reduces the time accept mutex is held. This also simplifies following changes to introduce PROXY protocol support.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 05 Mar 2021 17:16:19 +0300
parents da0a85e91587
children adee10c7fac8
comparison
equal deleted inserted replaced
7790:da0a85e91587 7791:d84f13618277
9 #include <ngx_core.h> 9 #include <ngx_core.h>
10 #include <ngx_event.h> 10 #include <ngx_event.h>
11 #include <ngx_mail.h> 11 #include <ngx_mail.h>
12 12
13 13
14 static void ngx_mail_init_session_handler(ngx_event_t *rev);
14 static void ngx_mail_init_session(ngx_connection_t *c); 15 static void ngx_mail_init_session(ngx_connection_t *c);
15 16
16 #if (NGX_MAIL_SSL) 17 #if (NGX_MAIL_SSL)
17 static void ngx_mail_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c); 18 static void ngx_mail_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c);
18 static void ngx_mail_ssl_handshake_handler(ngx_connection_t *c); 19 static void ngx_mail_ssl_handshake_handler(ngx_connection_t *c);
24 void 25 void
25 ngx_mail_init_connection(ngx_connection_t *c) 26 ngx_mail_init_connection(ngx_connection_t *c)
26 { 27 {
27 size_t len; 28 size_t len;
28 ngx_uint_t i; 29 ngx_uint_t i;
30 ngx_event_t *rev;
29 ngx_mail_port_t *port; 31 ngx_mail_port_t *port;
30 struct sockaddr *sa; 32 struct sockaddr *sa;
31 struct sockaddr_in *sin; 33 struct sockaddr_in *sin;
32 ngx_mail_log_ctx_t *ctx; 34 ngx_mail_log_ctx_t *ctx;
33 ngx_mail_in_addr_t *addr; 35 ngx_mail_in_addr_t *addr;
127 s->signature = NGX_MAIL_MODULE; 129 s->signature = NGX_MAIL_MODULE;
128 130
129 s->main_conf = addr_conf->ctx->main_conf; 131 s->main_conf = addr_conf->ctx->main_conf;
130 s->srv_conf = addr_conf->ctx->srv_conf; 132 s->srv_conf = addr_conf->ctx->srv_conf;
131 133
134 #if (NGX_MAIL_SSL)
135 s->ssl = addr_conf->ssl;
136 #endif
137
132 s->addr_text = &addr_conf->addr_text; 138 s->addr_text = &addr_conf->addr_text;
133 139
134 c->data = s; 140 c->data = s;
135 s->connection = c; 141 s->connection = c;
136 142
157 c->log->data = ctx; 163 c->log->data = ctx;
158 c->log->action = "sending client greeting line"; 164 c->log->action = "sending client greeting line";
159 165
160 c->log_error = NGX_ERROR_INFO; 166 c->log_error = NGX_ERROR_INFO;
161 167
168 rev = c->read;
169 rev->handler = ngx_mail_init_session_handler;
170
171 if (ngx_use_accept_mutex) {
172 ngx_post_event(rev, &ngx_posted_events);
173 return;
174 }
175
176 rev->handler(rev);
177 }
178
179
180 static void
181 ngx_mail_init_session_handler(ngx_event_t *rev)
182 {
183 ngx_connection_t *c;
184 ngx_mail_session_t *s;
185
186 c = rev->data;
187 s = c->data;
188
162 #if (NGX_MAIL_SSL) 189 #if (NGX_MAIL_SSL)
163 { 190 {
164 ngx_mail_ssl_conf_t *sslcf; 191 ngx_mail_ssl_conf_t *sslcf;
165 192
166 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); 193 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
167 194
168 if (sslcf->enable || addr_conf->ssl) { 195 if (sslcf->enable || s->ssl) {
169 c->log->action = "SSL handshaking"; 196 c->log->action = "SSL handshaking";
170 197
171 ngx_mail_ssl_init_connection(&sslcf->ssl, c); 198 ngx_mail_ssl_init_connection(&sslcf->ssl, c);
172 return; 199 return;
173 } 200 }