Hi,
I am developing my game using cocos2d-x 3.2.
While I’m adapting my game to android 5.0, I encountered a problem related to cocos HttpClient.
With android 5.0, HttpClient’s send method causes block then application is halt.
(With android 4.4.2, it works correctly)
To simplify this problem, I implemented sample code as below.
・AppDelegate.cpp
bool AppDelegate::applicationDidFinishLaunching() {
network::HttpRequest *request = new network::HttpRequest();
request->setUrl("http://www.cocos2d-x.org/");
request->setRequestType(network::HttpRequest::Type::GET);
request->setResponseCallback([this](network::HttpClient *sender, network::HttpResponse *response) {
CCLOG("ResponseCallback called.");
});
network::HttpClient::getInstance()->send(request);
request->release();
return true;
}
However, Response callback set by setResponseCallback() is never called.
As far as I investigate, in HttpClient.cpp, curl_easy_perform method in perform(long *responseCode) causes blocking and never return.
・HttpClient.cpp
/// @param responseCode Null not allowed
bool perform(long *responseCode)
{
if (CURLE_OK != curl_easy_perform(_curl))
return false;
CURLcode code = curl_easy_getinfo(_curl, CURLINFO_RESPONSE_CODE, responseCode);
if (code != CURLE_OK || !(*responseCode >= 200 && *responseCode < 300)) {
CCLOGERROR("Curl curl_easy_getinfo failed: %s", curl_easy_strerror(code));
return false;
}
// Get some mor data.
return true;
}
Could anyone take a look at them and see if you could give me an advice on this situation?
Tested environment is as below.
Device: Both Nexus5(Android-L) and Simulator(Android5.0)
Cocos2dx Version: Both 3.2 and 3.3rc0
NDK Version: r9d