Merge branch 'v3.6.0' into merge_v3.6

This commit is contained in:
minggo
2022-08-08 10:49:46 +08:00
267 changed files with 3152 additions and 1543 deletions

View File

@@ -33,6 +33,7 @@
#include <sstream>
#include "application/ApplicationManager.h"
#include "base/Log.h"
#include "base/ThreadPool.h"
#include "base/UTF8.h"
#include "base/std/container/queue.h"
#include "platform/FileUtils.h"
@@ -52,6 +53,7 @@ using HttpCookies = ccstd::vector<ccstd::string>;
using HttpCookiesIter = HttpCookies::iterator;
static HttpClient *gHttpClient = nullptr; // pointer to singleton
static LegacyThreadPool *gThreadPool = nullptr;
struct CookiesInfo {
ccstd::string domain;
@@ -121,8 +123,8 @@ public:
if (!headers.empty()) {
/* append custom headers one by one */
for (auto &header : headers) {
int len = header.length();
int pos = header.find(':');
uint32_t len = header.length();
uint32_t pos = header.find(':');
if (-1 == pos || pos >= len) {
continue;
}
@@ -213,7 +215,7 @@ public:
"sendRequest",
"(Ljava/net/HttpURLConnection;[B)V")) {
jbyteArray bytearray;
ssize_t dataSize = request->getRequestDataSize();
auto dataSize = static_cast<ssize_t>(request->getRequestDataSize());
bytearray = methodInfo.env->NewByteArray(dataSize);
methodInfo.env->SetByteArrayRegion(bytearray, 0, dataSize, reinterpret_cast<const jbyte *>(request->getRequestData()));
methodInfo.env->CallStaticVoidMethod(
@@ -595,13 +597,13 @@ void HttpClient::processResponse(HttpResponse *response, char *responseMessage)
return;
}
int64_t responseCode = -1;
long responseCode = -1L; // NOLINT
int retValue = 0;
HttpURLConnection urlConnection(this);
if (!urlConnection.init(request)) {
response->setSucceed(false);
response->setErrorBuffer("HttpURLConnetcion init failed");
response->setErrorBuffer("HttpURLConnection init failed");
return;
}
@@ -633,7 +635,7 @@ void HttpClient::processResponse(HttpResponse *response, char *responseMessage)
if (0 != suc) {
response->setSucceed(false);
response->setErrorBuffer("connect failed");
response->setResponseCode(static_cast<long>(responseCode));
response->setResponseCode(responseCode);
return;
}
@@ -683,7 +685,7 @@ void HttpClient::processResponse(HttpResponse *response, char *responseMessage)
urlConnection.disconnect();
// write data to HttpResponse
response->setResponseCode(static_cast<long>(responseCode));
response->setResponseCode(responseCode);
if (responseCode == -1) {
response->setSucceed(false);
@@ -831,6 +833,10 @@ HttpClient::HttpClient()
_cookie(nullptr),
_requestSentinel(ccnew HttpRequest()) {
CC_LOG_DEBUG("In the constructor of HttpClient!");
_requestSentinel->addRef();
if (gThreadPool == nullptr) {
gThreadPool = LegacyThreadPool::newFixedThreadPool(4);
}
increaseThreadCount();
_scheduler = CC_CURRENT_ENGINE()->getScheduler();
}
@@ -882,8 +888,8 @@ void HttpClient::sendImmediate(HttpRequest *request) {
// Create a HttpResponse object, the default setting is http access failed
auto *response = ccnew HttpResponse(request);
response->addRef(); // NOTE: RefCounted object's reference count is changed to 0 now. so needs to addRef after ccnew.
auto t = std::thread(&HttpClient::networkThreadAlone, this, request, response);
t.detach();
gThreadPool->pushTask([this, request, response](int /*tid*/) { HttpClient::networkThreadAlone(request, response); });
}
// Poll and notify main thread if responses exists in queue