小弟新手学mfc,用多线程抓网页内容,在用curl的CURLOPT_WRITEFUNCTION 回调的时候发生问题了,
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
回调函数:
size_t opp::my_fwrite(void *buffer, size_t size, size_t nmemb, void *userp)因为是静态函数,我不知道怎么传一个flag进去,所以无法得知是哪个线程的,这时就会串数据,有什么办法能解决么?
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
回调函数:
size_t opp::my_fwrite(void *buffer, size_t size, size_t nmemb, void *userp)因为是静态函数,我不知道怎么传一个flag进去,所以无法得知是哪个线程的,这时就会串数据,有什么办法能解决么?
文档里都有
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &p);
这个CURLOPT_WRITEDATA 的参数指针p就是回调里的void *userp指针咯??。。
The callback function will be passed as much data as possible in all invokes, but you cannot possibly make any assumptions. It may be one byte, it may be thousands. The maximum amount of data that can be passed to the write callback is defined in the curl.h header file: CURL_MAX_WRITE_SIZE.CURLOPT_WRITEDATAData pointer to pass to the file write function. If you use the CURLOPT_WRITEFUNCTION option, this is the pointer you'll get as input. If you don't use a callback, you must pass a 'FILE *' as libcurl will pass this to fwrite() when writing data.The internal CURLOPT_WRITEFUNCTION will write the data to the FILE * given with this option, or to stdout if this option hasn't been set.If you're using libcurl as a win32 DLL, you MUST use the CURLOPT_WRITEFUNCTION if you set this option or you will experience crashes.This option is also known with the older name CURLOPT_FILE, the name CURLOPT_WRITEDATA was introduced in 7.9.7.