From f64680ec082037ab419d653f6758f99e7ab9a3b1 Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Thu, 28 Apr 2011 09:39:33 +0200
Subject: [PATCH] multi-socks: fix connect to proxy

When connecting to a socks or similar proxy we do the proxy handshake at
once when we know the TCP connect is completed and we only consider the
"connection" complete after the proxy handshake. This fixes test 564
which is now no longer considered disabled.
---
 lib/connect.c       |    8 +++++++-
 lib/multi.c         |    2 --
 tests/data/DISABLED |    1 -
 tests/data/test564  |    7 ++-----
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/lib/connect.c b/lib/connect.c
index 2cd8cd3..732fc67 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -698,7 +698,13 @@ CURLcode Curl_is_connected(struct connectdata *conn,
 
   if(WAITCONN_CONNECTED == rc) {
     if(verifyconnect(sockfd, &error)) {
-      /* we are connected, awesome! */
+      /* we are connected with TCP, awesome! */
+
+      /* see if we need to do any proxy magic first once we connected */
+      code = Curl_connected_proxy(conn);
+      if(code)
+        return code;
+
       conn->bits.tcpconnect = TRUE;
       *connected = TRUE;
       Curl_pgrsTime(data, TIMER_CONNECT); /* connect done */
diff --git a/lib/multi.c b/lib/multi.c
index 9b707ab..aee190c 100644
--- a/lib/multi.c
+++ b/lib/multi.c
@@ -1141,8 +1141,6 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
                                        FIRSTSOCKET,
                                        &connected);
       if(connected) {
-        /* see if we need to do any proxy magic first once we connected */
-        easy->result = Curl_connected_proxy(easy->easy_conn);
 
         if(!easy->result)
           /* if everything is still fine we do the protocol-specific connect
diff --git a/tests/data/DISABLED b/tests/data/DISABLED
index 9ac123b..82123e6 100644
--- a/tests/data/DISABLED
+++ b/tests/data/DISABLED
@@ -2,5 +2,4 @@
 # test cases are run by runtests.pl. Just add the plain test case numbers, one
 # per line.
 # Lines starting with '#' letters are treated as comments.
-564
 811
diff --git a/tests/data/test564 b/tests/data/test564
index 6d0609d..72bf129 100644
--- a/tests/data/test564
+++ b/tests/data/test564
@@ -47,11 +47,8 @@ PWD
 CWD path
 EPSV
 TYPE I
-SIZE 546
-RETR 546
-EPSV
-SIZE 546
-RETR 546
+SIZE 564
+RETR 564
 QUIT
 </protocol>
 <stdout>
-- 
1.7.4.4

