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

sendf() now deals with Curl_write() returning -1 properly, which it might

do if the write would've blocked
This commit is contained in:
Daniel Stenberg 2002-03-13 13:09:37 +00:00
parent c819e234b8
commit bc9705f758

View File

@ -163,23 +163,45 @@ CURLcode Curl_sendf(int sockfd, struct connectdata *conn,
{
struct SessionHandle *data = conn->data;
ssize_t bytes_written;
CURLcode result;
ssize_t write_len;
CURLcode res;
char *s;
char *sptr;
va_list ap;
va_start(ap, fmt);
s = vaprintf(fmt, ap); /* returns an allocated string */
va_end(ap);
if(!s)
return 0; /* failure */
return CURLE_OUT_OF_MEMORY; /* failure */
if(data->set.verbose)
fprintf(data->set.err, "> %s", s);
/* Write the buffer to the socket */
result = Curl_write(conn, sockfd, s, strlen(s), &bytes_written);
bytes_written=0;
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 */
return result;
return res;
}
/*