diff src/mail/ngx_mail.c @ 486:6484cbba0222 NGINX_0_7_55

nginx 0.7.55 *) Bugfix: the http_XXX parameters in "proxy_cache_use_stale" and "fastcgi_cache_use_stale" directives did not work. *) Bugfix: fastcgi cache did not cache header only responses. *) Bugfix: of "select() failed (9: Bad file descriptor)" error in nginx/Unix and "select() failed (10022: ...)" error in nginx/Windows. *) Bugfix: a segmentation fault might occur in worker process, if an "debug_connection" directive was used; the bug had appeared in 0.7.54. *) Bugfix: fix ngx_http_image_filter_module building errors. *) Bugfix: the files bigger than 2G could not be transferred using $r->sendfile. Thanks to Maxim Dounin.
author Igor Sysoev <http://sysoev.ru>
date Wed, 06 May 2009 00:00:00 +0400
parents ed5e10fb40fc
children 98143f74eb3d
line wrap: on
line diff
--- a/src/mail/ngx_mail.c
+++ b/src/mail/ngx_mail.c
@@ -70,9 +70,10 @@ ngx_mail_block(ngx_conf_t *cf, ngx_comma
     ngx_conf_t                   pcf;
     ngx_array_t                  in_ports;
     ngx_listening_t             *ls;
-    ngx_mail_listen_t           *imls;
+    ngx_mail_listen_t           *mls;
     ngx_mail_module_t           *module;
-    ngx_mail_in_port_t          *imip;
+    struct sockaddr_in           sin;
+    ngx_mail_in_port_t          *mip;
     ngx_mail_conf_ctx_t         *ctx;
     ngx_mail_conf_in_port_t     *in_port;
     ngx_mail_conf_in_addr_t     *in_addr;
@@ -223,7 +224,7 @@ ngx_mail_block(ngx_conf_t *cf, ngx_comma
         return NGX_CONF_ERROR;
     }
 
-    imls = cmcf->listen.elts;
+    mls = cmcf->listen.elts;
 
     for (l = 0; l < cmcf->listen.nelts; l++) {
 
@@ -231,7 +232,7 @@ ngx_mail_block(ngx_conf_t *cf, ngx_comma
 
         in_port = in_ports.elts;
         for (p = 0; p < in_ports.nelts; p++) {
-            if (in_port[p].port == imls[l].port) {
+            if (in_port[p].port == mls[l].port) {
                 in_port = &in_port[p];
                 goto found;
             }
@@ -242,7 +243,7 @@ ngx_mail_block(ngx_conf_t *cf, ngx_comma
             return NGX_CONF_ERROR;
         }
 
-        in_port->port = imls[l].port;
+        in_port->port = mls[l].port;
 
         if (ngx_array_init(&in_port->addrs, cf->temp_pool, 2,
                            sizeof(ngx_mail_conf_in_addr_t))
@@ -258,11 +259,11 @@ ngx_mail_block(ngx_conf_t *cf, ngx_comma
             return NGX_CONF_ERROR;
         }
 
-        in_addr->addr = imls[l].addr;
-        in_addr->ctx = imls[l].ctx;
-        in_addr->bind = imls[l].bind;
+        in_addr->addr = mls[l].addr;
+        in_addr->ctx = mls[l].ctx;
+        in_addr->bind = mls[l].bind;
 #if (NGX_MAIL_SSL)
-        in_addr->ssl = imls[l].ssl;
+        in_addr->ssl = mls[l].ssl;
 #endif
     }
 
@@ -299,16 +300,17 @@ ngx_mail_block(ngx_conf_t *cf, ngx_comma
                 continue;
             }
 
-            ls = ngx_listening_inet_stream_socket(cf, in_addr[a].addr,
-                                                  in_port[p].port);
+            ngx_memzero(&sin, sizeof(struct sockaddr_in));
+
+            sin.sin_family = AF_INET;
+            sin.sin_addr.s_addr = in_addr[a].addr;
+            sin.sin_port = htons(in_port[p].port);
+
+            ls = ngx_create_listening(cf, &sin, sizeof(struct sockaddr_in));
             if (ls == NULL) {
-                return NGX_CONF_ERROR;
+                return NULL;
             }
 
-            ls->backlog = NGX_LISTEN_BACKLOG;
-            ls->rcvbuf = -1;
-            ls->sndbuf = -1;
-
             ls->addr_ntop = 1;
             ls->handler = ngx_mail_init_connection;
             ls->pool_size = 256;
@@ -318,27 +320,27 @@ ngx_mail_block(ngx_conf_t *cf, ngx_comma
             ls->log.data = &ls->addr_text;
             ls->log.handler = ngx_accept_log_error;
 
-            imip = ngx_palloc(cf->pool, sizeof(ngx_mail_in_port_t));
-            if (imip == NULL) {
+            mip = ngx_palloc(cf->pool, sizeof(ngx_mail_in_port_t));
+            if (mip == NULL) {
                 return NGX_CONF_ERROR;
             }
 
-            ls->servers = imip;
+            ls->servers = mip;
 
             in_addr = in_port[p].addrs.elts;
 
             if (in_addr[a].bind && in_addr[a].addr != INADDR_ANY) {
-                imip->naddrs = 1;
+                mip->naddrs = 1;
                 done = 0;
 
             } else if (in_port[p].addrs.nelts > 1
                        && in_addr[last - 1].addr == INADDR_ANY)
             {
-                imip->naddrs = last;
+                mip->naddrs = last;
                 done = 1;
 
             } else {
-                imip->naddrs = 1;
+                mip->naddrs = 1;
                 done = 0;
             }
 
@@ -346,18 +348,18 @@ ngx_mail_block(ngx_conf_t *cf, ngx_comma
             ngx_log_error(NGX_LOG_ALERT, cf->log, 0,
                           "%ui: %V %d %ui %ui",
                           a, &ls->addr_text, in_addr[a].bind,
-                          imip->naddrs, last);
+                          mip->naddrs, last);
 #endif
 
-            imip->addrs = ngx_pcalloc(cf->pool,
-                                    imip->naddrs * sizeof(ngx_mail_in_addr_t));
-            if (imip->addrs == NULL) {
+            mip->addrs = ngx_pcalloc(cf->pool,
+                                     mip->naddrs * sizeof(ngx_mail_in_addr_t));
+            if (mip->addrs == NULL) {
                 return NGX_CONF_ERROR;
             }
 
-            for (i = 0; i < imip->naddrs; i++) {
-                imip->addrs[i].addr = in_addr[i].addr;
-                imip->addrs[i].ctx = in_addr[i].ctx;
+            for (i = 0; i < mip->naddrs; i++) {
+                mip->addrs[i].addr = in_addr[i].addr;
+                mip->addrs[i].ctx = in_addr[i].ctx;
 
                 text = ngx_pnalloc(cf->pool,
                                    NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1);
@@ -370,11 +372,11 @@ ngx_mail_block(ngx_conf_t *cf, ngx_comma
 
                 len = ngx_sprintf(text + len, ":%d", in_port[p].port) - text;
 
-                imip->addrs[i].addr_text.len = len;
-                imip->addrs[i].addr_text.data = text;
+                mip->addrs[i].addr_text.len = len;
+                mip->addrs[i].addr_text.data = text;
 
 #if (NGX_MAIL_SSL)
-                imip->addrs[i].ssl = in_addr[i].ssl;
+                mip->addrs[i].ssl = in_addr[i].ssl;
 #endif
             }