1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +00:00

complete native integration

This commit is contained in:
InsanusMokrassar 2023-04-18 12:40:45 +06:00
parent 05c99642cb
commit 999efc64eb
7 changed files with 16 additions and 34 deletions

View File

@ -11,8 +11,8 @@ import kotlinx.serialization.json.Json
/**
* Represents default [BaseRequestsExecutor] working on [Ktor](https://ktor.io) [HttpClient]
*
* * On JS and JVM platforms it is [dev.inmo.tgbotapi.bot.ktor.base.DefaultKtorRequestsExecutor]
* * On LinuxX64 and MingwX64 it is [dev.inmo.tgbotapi.bot.ktor.base.MultipleClientKtorRequestsExecutor]
* * On JS, JVM and MingwX64 platforms it is [dev.inmo.tgbotapi.bot.ktor.base.DefaultKtorRequestsExecutor]
* * On LinuxX64 it is [dev.inmo.tgbotapi.bot.ktor.base.MultipleClientKtorRequestsExecutor]
*/
expect class KtorRequestsExecutor (
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,

View File

@ -17,13 +17,11 @@ import kotlinx.serialization.json.Json
/**
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
* platforms should return [HttpClient.config] call
* platforms and MingwX64 should return [client]
*
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
* On MingwX64 it will create copy with WinHttp engine or throw an exception if engine is different with WinHttp
*
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64 or non WinHttp-based [HttpClient]
* on MingwX64
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64
*/
internal expect inline fun platformClientCopy(client: HttpClient): HttpClient
@ -31,7 +29,7 @@ internal expect inline fun platformClientCopy(client: HttpClient): HttpClient
* Will use its parameters of constructor to create several [DefaultKtorRequestsExecutor] and use them in [execute]
* and [close] operations
*
* This [BaseRequestsExecutor] has been created for native targets due to their inability of requests paralleling
* This [BaseRequestsExecutor] has been created for LinuxX64 target due to its inability of requests paralleling
*
* Under the hood on each [execute] it will take [DefaultKtorRequestsExecutor] and mark it as busy, execute
* [Request], free up taken [DefaultKtorRequestsExecutor] and return (or throw) the result of execution

View File

@ -4,12 +4,10 @@ import io.ktor.client.*
/**
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
* platforms should return [HttpClient.config] call
* platforms and MingwX64 should return [client]
*
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
* On MingwX64 it will create copy with WinHttp engine or throw an exception if engine is different with WinHttp
*
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64 or non WinHttp-based [HttpClient]
* on MingwX64
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64
*/
internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = client.config { }

View File

@ -4,12 +4,10 @@ import io.ktor.client.*
/**
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
* platforms should return [HttpClient.config] call
* platforms and MingwX64 should return [client]
*
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
* On MingwX64 it will create copy with WinHttp engine or throw an exception if engine is different with WinHttp
*
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64 or non WinHttp-based [HttpClient]
* on MingwX64
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64
*/
internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = client.config { }

View File

@ -5,13 +5,11 @@ import io.ktor.client.engine.curl.*
/**
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
* platforms should return [client]
* platforms and MingwX64 should return [client]
*
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
* On MingwX64 it will create copy with WinHttp engine or throw an exception if engine is different with WinHttp
*
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64 or non WinHttp-based [HttpClient]
* on MingwX64
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64
*/
internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = (client.engineConfig as? CurlClientEngineConfig) ?.let {
lateinit var config: HttpClientConfig<out CurlClientEngineConfig>

View File

@ -1,5 +1,5 @@
package dev.inmo.tgbotapi.bot.ktor
import dev.inmo.tgbotapi.bot.ktor.base.MultipleClientKtorRequestsExecutor
import dev.inmo.tgbotapi.bot.ktor.base.DefaultKtorRequestsExecutor
actual typealias KtorRequestsExecutor = MultipleClientKtorRequestsExecutor
actual typealias KtorRequestsExecutor = DefaultKtorRequestsExecutor

View File

@ -5,20 +5,10 @@ import io.ktor.client.engine.winhttp.*
/**
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
* platforms should return [client]
* platforms and MingwX64 should return [client]
*
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
* On MingwX64 it will create copy with WinHttp engine or throw an exception if engine is different with WinHttp
*
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64 or non WinHttp-based [HttpClient]
* on MingwX64
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64
*/
internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = (client.engineConfig as? WinHttpClientEngineConfig) ?.let { engineConfig ->
lateinit var config: HttpClientConfig<out WinHttpClientEngineConfig>
client.config {
config = this as HttpClientConfig<out WinHttpClientEngineConfig>
}.close()
HttpClient(WinHttp) {
this.plusAssign(config)
}
} ?: throw IllegalArgumentException("On LinuxX64 TelegramBotAPI currently support only Curl Ktor HttpClient engine")
internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = client.config { }