sendf() now deals with Curl_write() returning -1 properly, which it might
do if the write would've blocked
This commit is contained in:
parent
c819e234b8
commit
bc9705f758
32
lib/sendf.c
32
lib/sendf.c
@ -163,23 +163,45 @@ CURLcode Curl_sendf(int sockfd, struct connectdata *conn,
|
|||||||
{
|
{
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
ssize_t bytes_written;
|
ssize_t bytes_written;
|
||||||
CURLcode result;
|
ssize_t write_len;
|
||||||
|
CURLcode res;
|
||||||
char *s;
|
char *s;
|
||||||
|
char *sptr;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
s = vaprintf(fmt, ap); /* returns an allocated string */
|
s = vaprintf(fmt, ap); /* returns an allocated string */
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
if(!s)
|
if(!s)
|
||||||
return 0; /* failure */
|
return CURLE_OUT_OF_MEMORY; /* failure */
|
||||||
|
|
||||||
if(data->set.verbose)
|
if(data->set.verbose)
|
||||||
fprintf(data->set.err, "> %s", s);
|
fprintf(data->set.err, "> %s", s);
|
||||||
|
|
||||||
/* Write the buffer to the socket */
|
bytes_written=0;
|
||||||
result = Curl_write(conn, sockfd, s, strlen(s), &bytes_written);
|
write_len = strlen(s);
|
||||||
|
sptr = s;
|
||||||
|
|
||||||
|
do {
|
||||||
|
/* Write the buffer to the socket */
|
||||||
|
res = Curl_write(conn, sockfd, sptr, write_len, &bytes_written);
|
||||||
|
|
||||||
|
if(CURLE_OK != res)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(bytes_written != write_len) {
|
||||||
|
/* if not all was written at once, we must advance the pointer, decrease
|
||||||
|
the size left and try again! */
|
||||||
|
write_len -= bytes_written;
|
||||||
|
sptr += bytes_written;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
} while(1);
|
||||||
|
|
||||||
free(s); /* free the output string */
|
free(s); /* free the output string */
|
||||||
|
|
||||||
return result;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user