Added better checking of return codes when we send data to sockets/connections

This commit is contained in:
Daniel Stenberg 2001-10-31 14:57:00 +00:00
parent 7e6a36ea7b
commit 69d5d88259

View File

@ -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,10 +256,12 @@ 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 */
result =
Curl_sendf(tunnelsocket, conn, Curl_sendf(tunnelsocket, conn,
"CONNECT %s:%d HTTP/1.0\015\012" "CONNECT %s:%d HTTP/1.0\015\012"
"%s" "%s"
@ -264,6 +271,10 @@ CURLcode Curl_ConnectHTTPProxyTunnel(struct connectdata *conn,
(conn->bits.proxy_user_passwd)?conn->allocptr.proxyuserpwd:"", (conn->bits.proxy_user_passwd)?conn->allocptr.proxyuserpwd:"",
(data->set.useragent?conn->allocptr.uagent:"") (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,9 +751,11 @@ 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)
failf(data, "Failed sending POST request");
else
/* setup variables for the upcoming transfer */ /* setup variables for the upcoming transfer */
result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE, result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE,
&http->readbytecount, &http->readbytecount,
@ -768,9 +781,11 @@ 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)
failf(data, "Faied sending POST request");
else
/* prepare for transfer */ /* prepare for transfer */
result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE, result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE,
&http->readbytecount, &http->readbytecount,
@ -825,9 +840,12 @@ 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);
if(result)
failf(data, "Failed sending HTTP request");
else
/* HTTP GET/HEAD download: */ /* HTTP GET/HEAD download: */
result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE, bytecount, result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE, bytecount,
-1, NULL); /* nothing to upload */ -1, NULL); /* nothing to upload */