Added better checking of return codes when we send data to sockets/connections
This commit is contained in:
parent
7e6a36ea7b
commit
69d5d88259
84
lib/http.c
84
lib/http.c
@ -125,22 +125,27 @@ send_buffer *add_buffer_init(void)
|
|||||||
* add_buffer_send() sends a buffer and frees all associated memory.
|
* add_buffer_send() sends a buffer and frees all associated memory.
|
||||||
*/
|
*/
|
||||||
static
|
static
|
||||||
size_t add_buffer_send(int sockfd, struct connectdata *conn, send_buffer *in)
|
CURLcode add_buffer_send(int sockfd, struct connectdata *conn, send_buffer *in,
|
||||||
|
long *bytes_written)
|
||||||
{
|
{
|
||||||
size_t amount;
|
size_t amount;
|
||||||
|
CURLcode result;
|
||||||
|
|
||||||
if(conn->data->set.verbose) {
|
if(conn->data->set.verbose) {
|
||||||
fputs("> ", conn->data->set.err);
|
fputs("> ", conn->data->set.err);
|
||||||
/* this data _may_ contain binary stuff */
|
/* this data _may_ contain binary stuff */
|
||||||
fwrite(in->buffer, in->size_used, 1, conn->data->set.err);
|
fwrite(in->buffer, in->size_used, 1, conn->data->set.err);
|
||||||
}
|
}
|
||||||
|
|
||||||
Curl_write(conn, sockfd, in->buffer, in->size_used, &amount);
|
result = Curl_write(conn, sockfd, in->buffer, in->size_used, &amount);
|
||||||
|
|
||||||
if(in->buffer)
|
if(in->buffer)
|
||||||
free(in->buffer);
|
free(in->buffer);
|
||||||
free(in);
|
free(in);
|
||||||
|
|
||||||
return amount;
|
*bytes_written = amount;
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -251,19 +256,25 @@ CURLcode Curl_ConnectHTTPProxyTunnel(struct connectdata *conn,
|
|||||||
int httperror=0;
|
int httperror=0;
|
||||||
int subversion=0;
|
int subversion=0;
|
||||||
struct SessionHandle *data=conn->data;
|
struct SessionHandle *data=conn->data;
|
||||||
|
CURLcode result;
|
||||||
|
|
||||||
infof(data, "Establish HTTP proxy tunnel to %s:%d\n", hostname, remote_port);
|
infof(data, "Establish HTTP proxy tunnel to %s:%d\n", hostname, remote_port);
|
||||||
|
|
||||||
/* OK, now send the connect request to the proxy */
|
/* OK, now send the connect request to the proxy */
|
||||||
Curl_sendf(tunnelsocket, conn,
|
result =
|
||||||
"CONNECT %s:%d HTTP/1.0\015\012"
|
Curl_sendf(tunnelsocket, conn,
|
||||||
"%s"
|
"CONNECT %s:%d HTTP/1.0\015\012"
|
||||||
"%s"
|
"%s"
|
||||||
"\r\n",
|
"%s"
|
||||||
hostname, remote_port,
|
"\r\n",
|
||||||
(conn->bits.proxy_user_passwd)?conn->allocptr.proxyuserpwd:"",
|
hostname, remote_port,
|
||||||
(data->set.useragent?conn->allocptr.uagent:"")
|
(conn->bits.proxy_user_passwd)?conn->allocptr.proxyuserpwd:"",
|
||||||
);
|
(data->set.useragent?conn->allocptr.uagent:"")
|
||||||
|
);
|
||||||
|
if(result) {
|
||||||
|
failf(data, "Failed sending CONNECT to proxy");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/* wait for the proxy to send us a HTTP/1.0 200 OK header */
|
/* wait for the proxy to send us a HTTP/1.0 200 OK header */
|
||||||
while(GetLine(tunnelsocket, data->state.buffer, conn)) {
|
while(GetLine(tunnelsocket, data->state.buffer, conn)) {
|
||||||
@ -740,14 +751,16 @@ CURLcode Curl_http(struct connectdata *conn)
|
|||||||
Curl_pgrsSetUploadSize(data, http->postsize);
|
Curl_pgrsSetUploadSize(data, http->postsize);
|
||||||
|
|
||||||
/* fire away the whole request to the server */
|
/* fire away the whole request to the server */
|
||||||
data->info.request_size =
|
result = add_buffer_send(conn->firstsocket, conn, req_buffer,
|
||||||
add_buffer_send(conn->firstsocket, conn, req_buffer);
|
&data->info.request_size);
|
||||||
|
if(result)
|
||||||
/* setup variables for the upcoming transfer */
|
failf(data, "Failed sending POST request");
|
||||||
result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE,
|
else
|
||||||
&http->readbytecount,
|
/* setup variables for the upcoming transfer */
|
||||||
conn->firstsocket,
|
result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE,
|
||||||
&http->writebytecount);
|
&http->readbytecount,
|
||||||
|
conn->firstsocket,
|
||||||
|
&http->writebytecount);
|
||||||
if(result) {
|
if(result) {
|
||||||
Curl_formclean(http->sendit); /* free that whole lot */
|
Curl_formclean(http->sendit); /* free that whole lot */
|
||||||
return result;
|
return result;
|
||||||
@ -768,14 +781,16 @@ CURLcode Curl_http(struct connectdata *conn)
|
|||||||
Curl_pgrsSetUploadSize(data, data->set.infilesize);
|
Curl_pgrsSetUploadSize(data, data->set.infilesize);
|
||||||
|
|
||||||
/* this sends the buffer and frees all the buffer resources */
|
/* this sends the buffer and frees all the buffer resources */
|
||||||
data->info.request_size =
|
result = add_buffer_send(conn->firstsocket, conn, req_buffer,
|
||||||
add_buffer_send(conn->firstsocket, conn, req_buffer);
|
&data->info.request_size);
|
||||||
|
if(result)
|
||||||
/* prepare for transfer */
|
failf(data, "Faied sending POST request");
|
||||||
result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE,
|
else
|
||||||
&http->readbytecount,
|
/* prepare for transfer */
|
||||||
conn->firstsocket,
|
result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE,
|
||||||
&http->writebytecount);
|
&http->readbytecount,
|
||||||
|
conn->firstsocket,
|
||||||
|
&http->writebytecount);
|
||||||
if(result)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
@ -825,12 +840,15 @@ CURLcode Curl_http(struct connectdata *conn)
|
|||||||
add_buffer(req_buffer, "\r\n", 2);
|
add_buffer(req_buffer, "\r\n", 2);
|
||||||
|
|
||||||
/* issue the request */
|
/* issue the request */
|
||||||
data->info.request_size =
|
result = add_buffer_send(conn->firstsocket, conn, req_buffer,
|
||||||
add_buffer_send(conn->firstsocket, conn, req_buffer);
|
&data->info.request_size);
|
||||||
|
|
||||||
/* HTTP GET/HEAD download: */
|
if(result)
|
||||||
result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE, bytecount,
|
failf(data, "Failed sending HTTP request");
|
||||||
-1, NULL); /* nothing to upload */
|
else
|
||||||
|
/* HTTP GET/HEAD download: */
|
||||||
|
result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE, bytecount,
|
||||||
|
-1, NULL); /* nothing to upload */
|
||||||
}
|
}
|
||||||
if(result)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user