fixed #1475, use vector::insert instead of vector::clear + assign in CCHttpClient::writeData, to prevent losing data

This commit is contained in:
Walzer 2012-09-10 23:17:16 +08:00
parent 07f82af35e
commit 0cd3552ef7
2 changed files with 4 additions and 5 deletions

View File

@ -74,12 +74,10 @@ size_t writeData(void *ptr, size_t size, size_t nmemb, void *stream)
{
std::vector<char> *recvBuffer = (std::vector<char>*)stream;
size_t sizes = size * nmemb;
recvBuffer->clear();
// someone reported a bug of losting data potentially here
// use recvBuffer->insert(recvBuffer->end(), (char*)ptr, (char*)ptr+sizes); can resolve.
recvBuffer->assign((char*)ptr, (char*)ptr + sizes);
// add data to the end of recvBuffer
// write data maybe called more than once in a single request
recvBuffer->insert(recvBuffer->end(), (char*)ptr, (char*)ptr+sizes);
return sizes;
}

View File

@ -55,6 +55,7 @@ public:
/**
* Add a get request to task queue
* @param request a CCHttpRequest object, which includes url, response callback etc.
please make sure request->_requestData is clear before calling "send" here.
* @return NULL
*/
void send(CCHttpRequest* request);