The read callback can now return CURL_READFUNC_ABORT to stop a transfer.

This commit is contained in:
Daniel Stenberg 2004-06-21 14:07:38 +00:00
parent 8d2120566e
commit 8e28721057
3 changed files with 21 additions and 5 deletions

View File

@ -218,7 +218,12 @@ static CURLcode file_upload(struct connectdata *conn)
Curl_pgrsSetUploadSize(data, data->set.infilesize); Curl_pgrsSetUploadSize(data, data->set.infilesize);
while (res == CURLE_OK) { while (res == CURLE_OK) {
nread = Curl_fillreadbuffer(conn, BUFSIZE); int readcount;
res = Curl_fillreadbuffer(conn, BUFSIZE, &readcount);
if(res)
return res;
nread = (size_t)readcount;
if (nread <= 0) if (nread <= 0)
break; break;

View File

@ -125,8 +125,9 @@ static struct timeval notimeout={0,0};
* This function will call the read callback to fill our buffer with data * This function will call the read callback to fill our buffer with data
* to upload. * 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 buffersize = bytes;
int nread; int nread;
@ -139,6 +140,11 @@ int Curl_fillreadbuffer(struct connectdata *conn, int bytes)
nread = conn->fread(conn->upload_fromhere, 1, nread = conn->fread(conn->upload_fromhere, 1,
buffersize, conn->fread_in); 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(!conn->bits.forbidchunk && conn->bits.upload_chunky) {
/* if chunked Transfer-Encoding */ /* if chunked Transfer-Encoding */
char hexbuffer[11]; char hexbuffer[11];
@ -161,7 +167,10 @@ int Curl_fillreadbuffer(struct connectdata *conn, int bytes)
nread+=2; /* for the added CRLF */ nread+=2; /* for the added CRLF */
} }
return nread;
*nreadp = nread;
return CURLE_OK;
} }
/* /*
@ -1131,7 +1140,9 @@ CURLcode Curl_readwrite(struct connectdata *conn,
break; break;
} }
nread = Curl_fillreadbuffer(conn, BUFSIZE); result = Curl_fillreadbuffer(conn, BUFSIZE, &nread);
if(result)
return result;
} }
else else
nread = 0; /* we're done uploading/reading */ nread = 0; /* we're done uploading/reading */

View File

@ -35,7 +35,7 @@ void Curl_single_fdset(struct connectdata *conn,
int *max_fd); int *max_fd);
CURLcode Curl_readwrite_init(struct connectdata *conn); CURLcode Curl_readwrite_init(struct connectdata *conn);
int Curl_fillreadbuffer(struct connectdata *conn, int bytes); CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp);
/* This sets up a forthcoming transfer */ /* This sets up a forthcoming transfer */
CURLcode CURLcode