diff --git a/include/eepp/network/http.hpp b/include/eepp/network/http.hpp index 689e7cef8..7cc2d03df 100644 --- a/include/eepp/network/http.hpp +++ b/include/eepp/network/http.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -580,7 +581,7 @@ class EE_API Http : NonCopyable { * @param host The scheme + hostname + port represented as an URI. * @param proxy The client proxy if any, scheme + hostname + post as URI. */ - bool exists( const URI& host, const URI& proxy = URI() ) const; + bool exists( const URI& host, const URI& proxy = URI() ); /** @return An HTTP Client to the host and proxy ( creates one if no one is found ) * @param host The scheme + hostname + port represented as an URI. @@ -589,7 +590,8 @@ class EE_API Http : NonCopyable { Http* get( const URI& host, const URI& proxy = URI() ); protected: - std::map mHttps; + Mutex mMutex; + UnorderedMap mHttps; static std::string getHostKey( const URI& host, const URI& proxy ); @@ -645,6 +647,9 @@ class EE_API Http : NonCopyable { /** It will try to get the proxy from the environment variables. */ static URI getEnvProxyURI(); + /** Set the thread pool to consume for async requests, otherwise it will use its own */ + static void setThreadPool( std::shared_ptr pool ); + private: class AsyncRequest : public Thread { public: diff --git a/src/eepp/network/http.cpp b/src/eepp/network/http.cpp index 1384d761f..a4aac26cf 100644 --- a/src/eepp/network/http.cpp +++ b/src/eepp/network/http.cpp @@ -549,6 +549,8 @@ void Http::Response::parseFields( std::istream& in ) { static Http::Pool sGlobalHttpPool = Http::Pool(); +static std::shared_ptr sGlobalThreadPool = nullptr; + Http::Response Http::request( const URI& uri, Request::Method method, const Time& timeout, const Http::Request::ProgressCallback& progressCallback, const Http::Request::FieldTable& headers, const std::string& body, @@ -1095,6 +1097,10 @@ Http::Response Http::downloadRequest( const Http::Request& request, std::string return downloadRequest( request, file, timeout ); } +void Http::setThreadPool( std::shared_ptr pool ) { + sGlobalThreadPool = pool; +} + Http::AsyncRequest::AsyncRequest( Http* http, const Http::AsyncResponseCallback& cb, Http::Request request, Time timeout ) : mHttp( http ), @@ -1295,15 +1301,17 @@ void Http::sendAsyncRequest( const Http::AsyncResponseCallback& cb, const Http:: emscripten_async_wget2_got_data, emscripten_async_wget2_got_error_data, NULL ); #else + if ( sGlobalThreadPool ) { + sGlobalThreadPool->run( [this, cb, request, timeout] { + AsyncRequest asyncRequest( this, cb, request, timeout ); + asyncRequest.run(); + } ); + return; + } AsyncRequest* thread = eeNew( AsyncRequest, ( this, cb, request, timeout ) ); - thread->launch(); - - // Clean old threads Lock l( mThreadsMutex ); - removeOldThreads(); - mThreads.push_back( thread ); #endif } @@ -1322,15 +1330,17 @@ void Http::downloadAsyncRequest( const Http::AsyncResponseCallback& cb, emscripten_async_wget2_got_data, emscripten_async_wget2_got_error_data, NULL ); #else + if ( sGlobalThreadPool ) { + sGlobalThreadPool->run( [this, cb, request, &writeTo, timeout] { + AsyncRequest asyncRequest( this, cb, request, writeTo, timeout ); + asyncRequest.run(); + } ); + return; + } AsyncRequest* thread = eeNew( AsyncRequest, ( this, cb, request, writeTo, timeout ) ); - thread->launch(); - - // Clean old threads Lock l( mThreadsMutex ); - removeOldThreads(); - mThreads.push_back( thread ); #endif } @@ -1349,15 +1359,17 @@ void Http::downloadAsyncRequest( const Http::AsyncResponseCallback& cb, emscripten_async_wget2_got_file, emscripten_async_wget2_got_error_file, NULL ); #else + if ( sGlobalThreadPool ) { + sGlobalThreadPool->run( [this, cb, request, writePath, timeout] { + AsyncRequest asyncRequest( this, cb, request, writePath, timeout ); + asyncRequest.run(); + } ); + return; + } AsyncRequest* thread = eeNew( AsyncRequest, ( this, cb, request, writePath, timeout ) ); - thread->launch(); - - // Clean old threads Lock l( mThreadsMutex ); - removeOldThreads(); - mThreads.push_back( thread ); #endif } @@ -1455,6 +1467,7 @@ Http::Pool::~Pool() { } void Http::Pool::clear() { + Lock l( mMutex ); for ( auto& connection : mHttps ) { Http* con = connection.second; @@ -1474,18 +1487,23 @@ String::HashType Http::Pool::getHostHash( const URI& host, const URI& proxy ) { return String::hash( Http::Pool::getHostKey( host, proxy ) ); } -bool Http::Pool::exists( const URI& host, const URI& proxy ) const { +bool Http::Pool::exists( const URI& host, const URI& proxy ) { + Lock l( mMutex ); return mHttps.find( getHostHash( host, proxy ) ) != mHttps.end(); } Http* Http::Pool::get( const URI& host, const URI& proxy ) { - auto hostInstance = mHttps.find( Http::Pool::getHostHash( host, proxy ) ); + { + Lock l( mMutex ); + auto hostInstance = mHttps.find( Http::Pool::getHostHash( host, proxy ) ); - if ( hostInstance != mHttps.end() ) { - return hostInstance->second; + if ( hostInstance != mHttps.end() ) { + return hostInstance->second; + } } Http* http = eeNew( Http, ( host.getHost(), host.getPort(), host.getScheme() == "https" ) ); + Lock l( mMutex ); mHttps[getHostHash( host, proxy )] = http; return http; } diff --git a/src/eepp/system/functionstring.cpp b/src/eepp/system/functionstring.cpp index 4d9929301..bf8a43549 100644 --- a/src/eepp/system/functionstring.cpp +++ b/src/eepp/system/functionstring.cpp @@ -61,7 +61,7 @@ FunctionString FunctionString::parse( const std::string& function ) { lastWasBackslash = '\\' == curChar; } - curParameter = String::trim( curParameter ); + String::trimInPlace( curParameter ); if ( !curParameter.empty() ) { parameters.push_back( curParameter ); diff --git a/src/eepp/ui/uimessagebox.cpp b/src/eepp/ui/uimessagebox.cpp index e08d22c97..8738b4d04 100644 --- a/src/eepp/ui/uimessagebox.cpp +++ b/src/eepp/ui/uimessagebox.cpp @@ -114,6 +114,10 @@ void UIMessageBox::setTheme( UITheme* theme ) { mTextBox->setTheme( theme ); mButtonOK->setTheme( theme ); mButtonCancel->setTheme( theme ); + if ( mTextInput ) + mTextInput->setTheme( theme ); + if ( mTextEdit ) + mTextEdit->setTheme( theme ); if ( getTranslatorString( "@string/msg_box_retry", "Retry" ) != mButtonOK->getText() ) { Drawable* okIcon = getUISceneNode()->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ); diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 1afee2b2f..5e9d7f3db 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -3341,6 +3341,7 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe const std::string& css, bool health, const std::string& healthLang, FeaturesHealth::OutputFormat healthFormat, const std::string& fileToOpen, bool stdOutLogs, bool disableFileLogs, bool openClean, bool portable ) { + Http::setThreadPool( mThreadPool ); DisplayManager* displayManager = Engine::instance()->getDisplayManager(); Display* currentDisplay = displayManager->getDisplayIndex( 0 ); mPortableMode = portable; diff --git a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp index 8692de2be..063a1d17d 100644 --- a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp +++ b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp @@ -206,8 +206,7 @@ UISceneNode* LSPDocumentClient::getUISceneNode() { return server->getManager()->getPluginManager()->getUISceneNode(); } -static SyntaxStyleType semanticTokenTypeToSyntaxType( const std::string& type, - const SyntaxDefinition& ) { +static SyntaxStyleType semanticTokenTypeToSyntaxType( const std::string& type ) { switch ( String::hash( type ) ) { case SemanticTokenTypes::Namespace: case SemanticTokenTypes::Type: @@ -323,9 +322,7 @@ void LSPDocumentClient::highlight() { auto* line = &tokenizerLines[currentLine]; if ( type >= 0 && type < (int)caps.legend.tokenTypes.size() ) { const auto& ltype = caps.legend.tokenTypes[type]; - line->tokens.push_back( - { semanticTokenTypeToSyntaxType( ltype, mDoc->getSyntaxDefinition() ), start, - len } ); + line->tokens.push_back( { semanticTokenTypeToSyntaxType( ltype ), start, len } ); } else { line->tokens.push_back( { SyntaxStyleTypes::Normal, start, len } ); }