diff src/http/ngx_http_upstream.c @ 220:559bc7ec214e NGINX_0_3_57

nginx 0.3.57 *) Feature: the $ssl_client_serial variable. *) Bugfix: in the "!-e" operator of the "if" directive. Thanks to Andrian Budanstov. *) Bugfix: while a client certificate verification nginx did not send to a client the required certificates information. *) Bugfix: the $document_root variable did not support the variables in the "root" directive.
author Igor Sysoev <http://sysoev.ru>
date Wed, 09 Aug 2006 00:00:00 +0400
parents fa32d59d9a15
children dd6c66b5b0e2
line wrap: on
line diff
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -769,7 +769,8 @@ ngx_http_upstream_reinit(ngx_http_reques
 static void
 ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u)
 {
-    int                rc;
+    int                rc, err;
+    socklen_t          len;
     ngx_connection_t  *c;
 
     c = u->peer.connection;
@@ -777,20 +778,43 @@ ngx_http_upstream_send_request(ngx_http_
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
                    "http upstream send request");
 
+    if (!u->request_sent) {
+
 #if (NGX_HAVE_KQUEUE)
 
-    if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT)
-        && !u->request_sent
-        && c->write->pending_eof)
-    {
-        (void) ngx_connection_error(c, c->write->kq_errno,
+        if (ngx_event_flags & NGX_USE_KQUEUE_EVENT)  {
+            if (c->write->pending_eof) {
+                (void) ngx_connection_error(c, c->write->kq_errno,
                                     "kevent() reported that connect() failed");
-        ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
-        return;
+                ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
+                return;
+            }
+
+        } else
+#endif
+        {
+            err = 0;
+            len = sizeof(int);
+
+            /*
+             * BSDs and Linux return 0 and set a pending error in err
+             * Solaris returns -1 and sets errno
+             */
+
+            if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len)
+                == -1)
+            {
+                err = ngx_errno;
+            }
+
+            if (err) {
+                (void) ngx_connection_error(c, err, "connect() failed");
+                ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
+                return;
+            }
+        }
     }
 
-#endif
-
     c->log->action = "sending request to upstream";
 
     rc = ngx_output_chain(&u->output, u->request_sent ? NULL : u->request_bufs);