From 8e287210577223b7d6dfb66034eca77c24a58b7f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 21 Jun 2004 14:07:38 +0000 Subject: The read callback can now return CURL_READFUNC_ABORT to stop a transfer. --- lib/transfer.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'lib/transfer.c') diff --git a/lib/transfer.c b/lib/transfer.c index 9ce78c552..1da2cc9c1 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -125,8 +125,9 @@ static struct timeval notimeout={0,0}; * This function will call the read callback to fill our buffer with data * to upload. */ -int Curl_fillreadbuffer(struct connectdata *conn, int bytes) +CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp) { + struct SessionHandle *data = conn->data; int buffersize = bytes; int nread; @@ -139,6 +140,11 @@ int Curl_fillreadbuffer(struct connectdata *conn, int bytes) nread = conn->fread(conn->upload_fromhere, 1, buffersize, conn->fread_in); + if(nread == CURL_READFUNC_ABORT) { + failf(data, "operation aborted by callback\n"); + return CURLE_ABORTED_BY_CALLBACK; + } + if(!conn->bits.forbidchunk && conn->bits.upload_chunky) { /* if chunked Transfer-Encoding */ char hexbuffer[11]; @@ -161,7 +167,10 @@ int Curl_fillreadbuffer(struct connectdata *conn, int bytes) nread+=2; /* for the added CRLF */ } - return nread; + + *nreadp = nread; + + return CURLE_OK; } /* @@ -1131,7 +1140,9 @@ CURLcode Curl_readwrite(struct connectdata *conn, break; } - nread = Curl_fillreadbuffer(conn, BUFSIZE); + result = Curl_fillreadbuffer(conn, BUFSIZE, &nread); + if(result) + return result; } else nread = 0; /* we're done uploading/reading */ -- cgit v1.2.3