struct SessionHandle *data = conn->data;
ssize_t bytes_written;
size_t write_len;
- CURLcode result = CURLE_OK;
+ CURLcode res = CURLE_OK;
char *s;
char *sptr;
va_list ap;
for(;;) {
/* Write the buffer to the socket */
- result = Curl_write(conn, sockfd, sptr, write_len, &bytes_written);
+ res = Curl_write(conn, sockfd, sptr, write_len, &bytes_written);
- if(result)
+ if(CURLE_OK != res)
break;
if(data->set.verbose)
free(s); /* free the output string */
- return result;
+ return res;
}
/*
ssize_t *written)
{
ssize_t bytes_written;
- CURLcode result = CURLE_OK;
+ CURLcode curlcode = CURLE_OK;
int num = (sockfd == conn->sock[SECONDARYSOCKET]);
- bytes_written = conn->send[num](conn, num, mem, len, &result);
+ bytes_written = conn->send[num](conn, num, mem, len, &curlcode);
*written = bytes_written;
if(bytes_written >= 0)
return CURLE_OK;
/* handle CURLE_AGAIN or a send failure */
- switch(result) {
+ switch(curlcode) {
case CURLE_AGAIN:
*written = 0;
return CURLE_OK;
default:
/* we got a specific curlcode, forward it */
- return result;
+ return curlcode;
}
}
ssize_t *written)
{
ssize_t bytes_written;
- CURLcode result;
+ CURLcode retcode;
int num = (sockfd == conn->sock[SECONDARYSOCKET]);
- bytes_written = Curl_send_plain(conn, num, mem, len, &result);
+ bytes_written = Curl_send_plain(conn, num, mem, len, &retcode);
*written = bytes_written;
- return result;
+ return retcode;
}
ssize_t Curl_recv_plain(struct connectdata *conn, int num, char *buf,
}
-/* Curl_client_chop_write() writes chunks of data not larger than
- * CURL_MAX_WRITE_SIZE via client write callback(s) and
- * takes care of pause requests from the callbacks.
+/* Curl_client_write() sends data to the write callback(s)
+
+ The bit pattern defines to what "streams" to write to. Body and/or header.
+ The defines are in sendf.h of course.
+
+ If CURL_DO_LINEEND_CONV is enabled, data is converted IN PLACE to the
+ local character encoding. This is a problem and should be changed in
+ the future to leave the original data alone.
*/
-CURLcode Curl_client_chop_write(struct connectdata *conn,
- int type,
- char * ptr,
- size_t len)
+CURLcode Curl_client_write(struct connectdata *conn,
+ int type,
+ char *ptr,
+ size_t len)
{
struct SessionHandle *data = conn->data;
- curl_write_callback writeheader = NULL;
- curl_write_callback writebody = NULL;
+ size_t wrote;
- if(!len)
- return CURLE_OK;
+ if(0 == len)
+ len = strlen(ptr);
/* If reading is actually paused, we're forced to append this chunk of data
to the already held data, but only if it is the same type as otherwise it
/* update the pointer and the size */
data->state.tempwrite = newptr;
data->state.tempwritesize = newlen;
- return CURLE_OK;
- }
- /* Determine the callback(s) to use. */
- if(type & CLIENTWRITE_BODY)
- writebody = data->set.fwrite_func;
- if((type & CLIENTWRITE_HEADER) &&
- (data->set.fwrite_header || data->set.writeheader)) {
- /*
- * Write headers to the same callback or to the especially setup
- * header callback function (added after version 7.7.1).
- */
- writeheader =
- data->set.fwrite_header? data->set.fwrite_header: data->set.fwrite_func;
+ return CURLE_OK;
}
- /* Chop data, write chunks. */
- while(len) {
- size_t chunklen = len <= CURL_MAX_WRITE_SIZE? len: CURL_MAX_WRITE_SIZE;
-
- if(writebody) {
- size_t wrote = writebody(ptr, 1, chunklen, data->set.out);
+ if(type & CLIENTWRITE_BODY) {
+ if((conn->handler->protocol&PROTO_FAMILY_FTP) &&
+ conn->proto.ftpc.transfertype == 'A') {
+ /* convert from the network encoding */
+ CURLcode rc = Curl_convert_from_network(data, ptr, len);
+ /* Curl_convert_from_network calls failf if unsuccessful */
+ if(rc)
+ return rc;
- if(CURL_WRITEFUNC_PAUSE == wrote) {
- if(conn->handler->flags & PROTOPT_NONETWORK) {
- /* Protocols that work without network cannot be paused. This is
- actually only FILE:// just now, and it can't pause since the
- transfer isn't done using the "normal" procedure. */
- failf(data, "Write callback asked for PAUSE when not supported!");
- return CURLE_WRITE_ERROR;
- }
- else
- return pausewrite(data, type, ptr, len);
- }
- else if(wrote != chunklen) {
- failf(data, "Failed writing body (%zu != %zu)", wrote, chunklen);
- return CURLE_WRITE_ERROR;
- }
+#ifdef CURL_DO_LINEEND_CONV
+ /* convert end-of-line markers */
+ len = convert_lineends(data, ptr, len);
+#endif /* CURL_DO_LINEEND_CONV */
+ }
+ /* If the previous block of data ended with CR and this block of data is
+ just a NL, then the length might be zero */
+ if(len) {
+ wrote = data->set.fwrite_func(ptr, 1, len, data->set.out);
+ }
+ else {
+ wrote = len;
}
- if(writeheader) {
- size_t wrote = writeheader(ptr, 1, chunklen, data->set.writeheader);
-
- if(CURL_WRITEFUNC_PAUSE == wrote)
- /* here we pass in the HEADER bit only since if this was body as well
- then it was passed already and clearly that didn't trigger the
- pause, so this is saved for later with the HEADER bit only */
- return pausewrite(data, CLIENTWRITE_HEADER, ptr, len);
-
- if(wrote != chunklen) {
- failf (data, "Failed writing header");
+ if(CURL_WRITEFUNC_PAUSE == wrote) {
+ if(conn->handler->flags & PROTOPT_NONETWORK) {
+ /* Protocols that work without network cannot be paused. This is
+ actually only FILE:// just now, and it can't pause since the
+ transfer isn't done using the "normal" procedure. */
+ failf(data, "Write callback asked for PAUSE when not supported!");
return CURLE_WRITE_ERROR;
}
+ else
+ return pausewrite(data, type, ptr, len);
+ }
+ else if(wrote != len) {
+ failf(data, "Failed writing body (%zu != %zu)", wrote, len);
+ return CURLE_WRITE_ERROR;
}
-
- ptr += chunklen;
- len -= chunklen;
}
- return CURLE_OK;
-}
-
-
-/* Curl_client_write() sends data to the write callback(s)
-
- The bit pattern defines to what "streams" to write to. Body and/or header.
- The defines are in sendf.h of course.
-
- If CURL_DO_LINEEND_CONV is enabled, data is converted IN PLACE to the
- local character encoding. This is a problem and should be changed in
- the future to leave the original data alone.
- */
-CURLcode Curl_client_write(struct connectdata *conn,
- int type,
- char *ptr,
- size_t len)
-{
- struct SessionHandle *data = conn->data;
-
- if(0 == len)
- len = strlen(ptr);
-
- /* FTP data may need conversion. */
- if((type & CLIENTWRITE_BODY) &&
- (conn->handler->protocol & PROTO_FAMILY_FTP) &&
- conn->proto.ftpc.transfertype == 'A') {
- /* convert from the network encoding */
- CURLcode result = Curl_convert_from_network(data, ptr, len);
- /* Curl_convert_from_network calls failf if unsuccessful */
- if(result)
- return result;
-
-#ifdef CURL_DO_LINEEND_CONV
- /* convert end-of-line markers */
- len = convert_lineends(data, ptr, len);
-#endif /* CURL_DO_LINEEND_CONV */
+ if((type & CLIENTWRITE_HEADER) &&
+ (data->set.fwrite_header || data->set.writeheader) ) {
+ /*
+ * Write headers to the same callback or to the especially setup
+ * header callback function (added after version 7.7.1).
+ */
+ curl_write_callback writeit=
+ data->set.fwrite_header?data->set.fwrite_header:data->set.fwrite_func;
+
+ /* Note: The header is in the host encoding
+ regardless of the ftp transfer mode (ASCII/Image) */
+
+ wrote = writeit(ptr, 1, len, data->set.writeheader);
+ if(CURL_WRITEFUNC_PAUSE == wrote)
+ /* here we pass in the HEADER bit only since if this was body as well
+ then it was passed already and clearly that didn't trigger the pause,
+ so this is saved for later with the HEADER bit only */
+ return pausewrite(data, CLIENTWRITE_HEADER, ptr, len);
+
+ if(wrote != len) {
+ failf (data, "Failed writing header");
+ return CURLE_WRITE_ERROR;
}
+ }
- return Curl_client_chop_write(conn, type, ptr, len);
+ return CURLE_OK;
}
CURLcode Curl_read_plain(curl_socket_t sockfd,
size_t sizerequested, /* max amount to read */
ssize_t *n) /* amount bytes read */
{
- CURLcode result = CURLE_RECV_ERROR;
+ CURLcode curlcode = CURLE_RECV_ERROR;
ssize_t nread = 0;
size_t bytesfromsocket = 0;
char *buffertofill = NULL;
buffertofill = buf;
}
- nread = conn->recv[num](conn, num, buffertofill, bytesfromsocket, &result);
+ nread = conn->recv[num](conn, num, buffertofill, bytesfromsocket, &curlcode);
if(nread < 0)
- return result;
+ return curlcode;
if(pipelining) {
memcpy(buf, conn->master_buffer, nread);
switch (type) {
case CURLINFO_HEADER_IN:
w = "Header";
- /* FALLTHROUGH */
case CURLINFO_DATA_IN:
t = "from";
break;
case CURLINFO_HEADER_OUT:
w = "Header";
- /* FALLTHROUGH */
case CURLINFO_DATA_OUT:
t = "to";
break;