aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-03-13 13:09:37 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-03-13 13:09:37 +0000
commitbc9705f7583c7ef6ed4fd0566ba45846606dc025 (patch)
tree3e148c9cbd891b3e7b2ec53bdc0d1e7dbf0b8a80
parentc819e234b8980fd0484848c1e16c70c2890b55c6 (diff)
sendf() now deals with Curl_write() returning -1 properly, which it might
do if the write would've blocked
-rw-r--r--lib/sendf.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/sendf.c b/lib/sendf.c
index 1079067d7..6aee7ce9c 100644
--- a/lib/sendf.c
+++ b/lib/sendf.c
@@ -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;
}
/*