[nginx] Mail: postponed session initialization under accept mutex.
Maxim Dounin
mdounin at mdounin.ru
Fri Mar 5 15:31:45 UTC 2021
details: https://hg.nginx.org/nginx/rev/d84f13618277
branches:
changeset: 7791:d84f13618277
user: Maxim Dounin <mdounin at mdounin.ru>
date: Fri Mar 05 17:16:19 2021 +0300
description:
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.
diffstat:
src/mail/ngx_mail.h | 1 +
src/mail/ngx_mail_handler.c | 29 ++++++++++++++++++++++++++++-
2 files changed, 29 insertions(+), 1 deletions(-)
diffs (77 lines):
diff -r da0a85e91587 -r d84f13618277 src/mail/ngx_mail.h
--- a/src/mail/ngx_mail.h Fri Mar 05 17:16:17 2021 +0300
+++ b/src/mail/ngx_mail.h Fri Mar 05 17:16:19 2021 +0300
@@ -197,6 +197,7 @@ typedef struct {
ngx_uint_t mail_state;
+ unsigned ssl:1;
unsigned protocol:3;
unsigned blocked:1;
unsigned quit:1;
diff -r da0a85e91587 -r d84f13618277 src/mail/ngx_mail_handler.c
--- a/src/mail/ngx_mail_handler.c Fri Mar 05 17:16:17 2021 +0300
+++ b/src/mail/ngx_mail_handler.c Fri Mar 05 17:16:19 2021 +0300
@@ -11,6 +11,7 @@
#include <ngx_mail.h>
+static void ngx_mail_init_session_handler(ngx_event_t *rev);
static void ngx_mail_init_session(ngx_connection_t *c);
#if (NGX_MAIL_SSL)
@@ -26,6 +27,7 @@ ngx_mail_init_connection(ngx_connection_
{
size_t len;
ngx_uint_t i;
+ ngx_event_t *rev;
ngx_mail_port_t *port;
struct sockaddr *sa;
struct sockaddr_in *sin;
@@ -129,6 +131,10 @@ ngx_mail_init_connection(ngx_connection_
s->main_conf = addr_conf->ctx->main_conf;
s->srv_conf = addr_conf->ctx->srv_conf;
+#if (NGX_MAIL_SSL)
+ s->ssl = addr_conf->ssl;
+#endif
+
s->addr_text = &addr_conf->addr_text;
c->data = s;
@@ -159,13 +165,34 @@ ngx_mail_init_connection(ngx_connection_
c->log_error = NGX_ERROR_INFO;
+ rev = c->read;
+ rev->handler = ngx_mail_init_session_handler;
+
+ if (ngx_use_accept_mutex) {
+ ngx_post_event(rev, &ngx_posted_events);
+ return;
+ }
+
+ rev->handler(rev);
+}
+
+
+static void
+ngx_mail_init_session_handler(ngx_event_t *rev)
+{
+ ngx_connection_t *c;
+ ngx_mail_session_t *s;
+
+ c = rev->data;
+ s = c->data;
+
#if (NGX_MAIL_SSL)
{
ngx_mail_ssl_conf_t *sslcf;
sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
- if (sslcf->enable || addr_conf->ssl) {
+ if (sslcf->enable || s->ssl) {
c->log->action = "SSL handshaking";
ngx_mail_ssl_init_connection(&sslcf->ssl, c);
More information about the nginx-devel
mailing list