36 lines
1.0 KiB
Kotlin
36 lines
1.0 KiB
Kotlin
package com.example.tgwsproxy
|
|
|
|
import com.sun.jna.Library
|
|
import com.sun.jna.Native
|
|
import com.sun.jna.Pointer
|
|
|
|
interface ProxyLibrary : Library {
|
|
companion object {
|
|
val INSTANCE = Native.load("tgwsproxy", ProxyLibrary::class.java) as ProxyLibrary
|
|
}
|
|
|
|
fun StartProxy(host: String, port: Int, dcIps: String, verbose: Int): Int
|
|
fun StopProxy(): Int
|
|
fun SetPoolSize(size: Int)
|
|
fun GetStats(): Pointer?
|
|
fun FreeString(p: Pointer)
|
|
}
|
|
|
|
object NativeProxy {
|
|
fun startProxy(host: String, port: Int, dcIps: String, verbose: Int): Int {
|
|
return ProxyLibrary.INSTANCE.StartProxy(host, port, dcIps, verbose)
|
|
}
|
|
fun stopProxy(): Int {
|
|
return ProxyLibrary.INSTANCE.StopProxy()
|
|
}
|
|
fun setPoolSize(size: Int) {
|
|
ProxyLibrary.INSTANCE.SetPoolSize(size)
|
|
}
|
|
fun getStats(): String? {
|
|
val ptr = ProxyLibrary.INSTANCE.GetStats() ?: return null
|
|
val res = ptr.getString(0)
|
|
ProxyLibrary.INSTANCE.FreeString(ptr)
|
|
return res
|
|
}
|
|
}
|