aboutsummaryrefslogtreecommitdiff
path: root/lib/transfer.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/transfer.c')
-rw-r--r--lib/transfer.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/lib/transfer.c b/lib/transfer.c
index 71338977d..aed230a17 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -2060,7 +2060,32 @@ Curl_connect_host(struct SessionHandle *data,
return res;
}
+/* Returns TRUE and sets '*url' if a request retry is wanted */
+bool Curl_retry_request(struct connectdata *conn,
+ char **url)
+{
+ bool retry = FALSE;
+ if((conn->keep.bytecount+conn->headerbytecount == 0) &&
+ conn->bits.reuse) {
+ /* We got no data and we attempted to re-use a connection. This might
+ happen if the connection was left alive when we were done using it
+ before, but that was closed when we wanted to read from it again. Bad
+ luck. Retry the same request on a fresh connect! */
+ infof(conn->data, "Connection died, retrying a fresh connect\n");
+ *url = strdup(conn->data->change.url);
+
+ conn->bits.close = TRUE; /* close this connection */
+ conn->bits.retry = TRUE; /* mark this as a connection we're about
+ to retry. Marking it this way should
+ prevent i.e HTTP transfers to return
+ error just because nothing has been
+ transfered! */
+ retry = TRUE;
+ }
+
+ return retry;
+}
/*
* Curl_perform() is the internal high-level function that gets called by the
@@ -2106,31 +2131,12 @@ CURLcode Curl_perform(struct SessionHandle *data)
if(res == CURLE_OK && !data->set.source_url) {
res = Transfer(conn); /* now fetch that URL please */
if(res == CURLE_OK) {
+ retry = Curl_retry_request(conn, &newurl);
- retry = FALSE;
-
- if((conn->keep.bytecount+conn->headerbytecount == 0) &&
- conn->bits.reuse) {
- /* We got no data and we attempted to re-use a connection. This
- might happen if the connection was left alive when we were done
- using it before, but that was closed when we wanted to read
- from it again. Bad luck. Retry the same request on a fresh
- connect! */
- infof(data, "Connection died, retrying a fresh connect\n");
- newurl = strdup(conn->data->change.url);
-
- conn->bits.close = TRUE; /* close this connection */
- conn->bits.retry = TRUE; /* mark this as a connection we're about
- to retry. Marking it this way should
- prevent i.e HTTP transfers to return
- error just because nothing has been
- transfered! */
- retry = TRUE;
- }
- else
+ if(!retry)
/*
- * We must duplicate the new URL here as the connection data
- * may be free()ed in the Curl_done() function.
+ * We must duplicate the new URL here as the connection data may
+ * be free()ed in the Curl_done() function.
*/
newurl = conn->newurl?strdup(conn->newurl):NULL;
}