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

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

View File

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