summaryrefslogtreecommitdiff
path: root/lib/gopher.c
diff options
context:
space:
mode:
authorCameron Kaiser <ckaiser@floodgap.com>2010-08-23 14:30:59 -0700
committerDaniel Stenberg <daniel@haxx.se>2010-08-25 14:21:25 +0200
commit67d16160184493c6717e4e572fafed7467af4983 (patch)
tree9061513b563f8fc19b8d47c0606e03d7b3e90819 /lib/gopher.c
parent65629f2915d1b23193fbe4fb3697702ce2fc7e87 (diff)
downloadcurl-67d16160184493c6717e4e572fafed7467af4983.tar.gz
Gopher using Curl_write; test suite (4 tests)
Diffstat (limited to 'lib/gopher.c')
-rw-r--r--lib/gopher.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/gopher.c b/lib/gopher.c
index d1ca440e5..2fab6dabe 100644
--- a/lib/gopher.c
+++ b/lib/gopher.c
@@ -121,8 +121,8 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
curl_off_t *bytecount = &data->req.bytecount;
char *path = data->state.path;
-
char *sel;
+ ssize_t amount, k;
*done = TRUE; /* unconditionally */
@@ -149,12 +149,29 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
return CURLE_OUT_OF_MEMORY;
}
- result = Curl_sendf(sockfd, conn, "%s\r\n", sel);
-
- if(result) {
+ /* We use Curl_write instead of Curl_sendf to make sure the entire buffer
+ is sent, which could be sizeable with long selectors. */
+ k = strlen(sel);
+ for(;;) {
+ result = Curl_write(conn, sockfd, sel, k, &amount);
+ if (CURLE_OK == result) { /* Which may not have written it all! */
+ k -= amount;
+ sel += amount;
+ if (k < 1)
+ break; /* but it did write it all */
+ } else {
+ failf(data, "Failed sending Gopher request");
+ return result;
+ }
+ }
+ /* We can use Curl_sendf to send the terminal \r\n relatively safely and
+ save allocing another string/doing another _write loop. */
+ result = Curl_sendf(sockfd, conn, "\r\n");
+ if (result != CURLE_OK) {
failf(data, "Failed sending Gopher request");
return result;
}
+
Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount,
-1, NULL); /* no upload */
return CURLE_OK;