1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

FTP: do the HTTP CONNECT for data connection blocking

** WORK-AROUND **

The introduced non-blocking general behaviour for Curl_proxyCONNECT()
didn't work for the data connection establishment unless it was very
fast. The newly introduced function argument makes it operate in a more
blocking manner, more like it used to work in the past. This blocking
approach is only used when the FTP data connecting through HTTP proxy.

Blocking like this is bad. A better fix would make it work more
asynchronously.

Bug: https://github.com/bagder/curl/issues/278
This commit is contained in:
Daniel Stenberg 2015-06-17 00:30:06 +02:00
parent 85739723ba
commit b88f980a74
3 changed files with 19 additions and 12 deletions

View File

@ -1887,7 +1887,7 @@ static CURLcode proxy_magic(struct connectdata *conn,
memset(&http_proxy, 0, sizeof(http_proxy)); memset(&http_proxy, 0, sizeof(http_proxy));
data->req.protop = &http_proxy; data->req.protop = &http_proxy;
result = Curl_proxyCONNECT(conn, SECONDARYSOCKET, newhost, newport); result = Curl_proxyCONNECT(conn, SECONDARYSOCKET, newhost, newport, TRUE);
data->req.protop = ftp_save; data->req.protop = ftp_save;
@ -3645,7 +3645,7 @@ static CURLcode ftp_do_more(struct connectdata *conn, int *completep)
if(conn->tunnel_state[SECONDARYSOCKET] == TUNNEL_CONNECT) { if(conn->tunnel_state[SECONDARYSOCKET] == TUNNEL_CONNECT) {
/* As we're in TUNNEL_CONNECT state now, we know the proxy name and port /* As we're in TUNNEL_CONNECT state now, we know the proxy name and port
aren't used so we blank their arguments. TODO: make this nicer */ aren't used so we blank their arguments. TODO: make this nicer */
result = Curl_proxyCONNECT(conn, SECONDARYSOCKET, NULL, 0); result = Curl_proxyCONNECT(conn, SECONDARYSOCKET, NULL, 0, FALSE);
return result; return result;
} }

View File

@ -68,7 +68,7 @@ CURLcode Curl_proxy_connect(struct connectdata *conn)
conn->data->req.protop = &http_proxy; conn->data->req.protop = &http_proxy;
connkeep(conn, "HTTP proxy CONNECT"); connkeep(conn, "HTTP proxy CONNECT");
result = Curl_proxyCONNECT(conn, FIRSTSOCKET, result = Curl_proxyCONNECT(conn, FIRSTSOCKET,
conn->host.name, conn->remote_port); conn->host.name, conn->remote_port, FALSE);
conn->data->req.protop = prot_save; conn->data->req.protop = prot_save;
if(CURLE_OK != result) if(CURLE_OK != result)
return result; return result;
@ -85,12 +85,16 @@ CURLcode Curl_proxy_connect(struct connectdata *conn)
* Curl_proxyCONNECT() requires that we're connected to a HTTP proxy. This * Curl_proxyCONNECT() requires that we're connected to a HTTP proxy. This
* function will issue the necessary commands to get a seamless tunnel through * function will issue the necessary commands to get a seamless tunnel through
* this proxy. After that, the socket can be used just as a normal socket. * this proxy. After that, the socket can be used just as a normal socket.
*
* 'blocking' set to TRUE means that this function will do the entire CONNECT
* + response in a blocking fashion. Should be avoided!
*/ */
CURLcode Curl_proxyCONNECT(struct connectdata *conn, CURLcode Curl_proxyCONNECT(struct connectdata *conn,
int sockindex, int sockindex,
const char *hostname, const char *hostname,
int remote_port) int remote_port,
bool blocking)
{ {
int subversion=0; int subversion=0;
struct SessionHandle *data=conn->data; struct SessionHandle *data=conn->data;
@ -225,12 +229,14 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
return CURLE_RECV_ERROR; return CURLE_RECV_ERROR;
} }
if(0 == Curl_socket_ready(tunnelsocket, CURL_SOCKET_BAD, 0)) if(!blocking) {
/* return so we'll be called again polling-style */ if(0 == Curl_socket_ready(tunnelsocket, CURL_SOCKET_BAD, 0))
return CURLE_OK; /* return so we'll be called again polling-style */
else { return CURLE_OK;
DEBUGF(infof(data, else {
"Read response immediately from proxy CONNECT\n")); DEBUGF(infof(data,
"Read response immediately from proxy CONNECT\n"));
}
} }
/* at this point, the tunnel_connecting phase is over. */ /* at this point, the tunnel_connecting phase is over. */

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -26,7 +26,8 @@
/* ftp can use this as well */ /* ftp can use this as well */
CURLcode Curl_proxyCONNECT(struct connectdata *conn, CURLcode Curl_proxyCONNECT(struct connectdata *conn,
int tunnelsocket, int tunnelsocket,
const char *hostname, int remote_port); const char *hostname, int remote_port,
bool blocking);
/* Default proxy timeout in milliseconds */ /* Default proxy timeout in milliseconds */
#define PROXY_TIMEOUT (3600*1000) #define PROXY_TIMEOUT (3600*1000)