release 0.2.4
This commit is contained in:
parent
1f7e7f88fa
commit
18c878dfb5
6
.idea/artifacts/kiloparsec_js_0_1_2_SNAPSHOT.xml
generated
Normal file
6
.idea/artifacts/kiloparsec_js_0_1_2_SNAPSHOT.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="kiloparsec-js-0.1.2-SNAPSHOT">
|
||||
<output-path>$PROJECT_DIR$/build/libs</output-path>
|
||||
<root id="archive" name="kiloparsec-js-0.1.2-SNAPSHOT.jar" />
|
||||
</artifact>
|
||||
</component>
|
8
.idea/artifacts/kiloparsec_js_0_2_2_SNAPSHOT.xml
generated
Normal file
8
.idea/artifacts/kiloparsec_js_0_2_2_SNAPSHOT.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="kiloparsec-js-0.2.2-SNAPSHOT">
|
||||
<output-path>$PROJECT_DIR$/build/libs</output-path>
|
||||
<root id="archive" name="kiloparsec-js-0.2.2-SNAPSHOT.jar">
|
||||
<element id="module-output" name="kiloparsec.jsMain" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
8
.idea/artifacts/kiloparsec_js_0_2_3.xml
generated
Normal file
8
.idea/artifacts/kiloparsec_js_0_2_3.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="kiloparsec-js-0.2.3">
|
||||
<output-path>$PROJECT_DIR$/build/libs</output-path>
|
||||
<root id="archive" name="kiloparsec-js-0.2.3.jar">
|
||||
<element id="module-output" name="kiloparsec.jsMain" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
6
.idea/artifacts/kiloparsec_jvm_0_1_2_SNAPSHOT.xml
generated
Normal file
6
.idea/artifacts/kiloparsec_jvm_0_1_2_SNAPSHOT.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="kiloparsec-jvm-0.1.2-SNAPSHOT">
|
||||
<output-path>$PROJECT_DIR$/build/libs</output-path>
|
||||
<root id="archive" name="kiloparsec-jvm-0.1.2-SNAPSHOT.jar" />
|
||||
</artifact>
|
||||
</component>
|
8
.idea/artifacts/kiloparsec_jvm_0_2_2_SNAPSHOT.xml
generated
Normal file
8
.idea/artifacts/kiloparsec_jvm_0_2_2_SNAPSHOT.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="kiloparsec-jvm-0.2.2-SNAPSHOT">
|
||||
<output-path>$PROJECT_DIR$/build/libs</output-path>
|
||||
<root id="archive" name="kiloparsec-jvm-0.2.2-SNAPSHOT.jar">
|
||||
<element id="module-output" name="kiloparsec.jvmMain" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
8
.idea/artifacts/kiloparsec_jvm_0_2_3.xml
generated
Normal file
8
.idea/artifacts/kiloparsec_jvm_0_2_3.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="kiloparsec-jvm-0.2.3">
|
||||
<output-path>$PROJECT_DIR$/build/libs</output-path>
|
||||
<root id="archive" name="kiloparsec-jvm-0.2.3.jar">
|
||||
<element id="module-output" name="kiloparsec.jvmMain" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
5
.idea/misc.xml
generated
5
.idea/misc.xml
generated
@ -1,7 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17 (5)" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -6,7 +6,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "net.sergeych"
|
||||
version = "0.2.2-SNAPSHOT"
|
||||
version = "0.2.4"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@ -17,13 +17,8 @@ repositories {
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
js(IR) {
|
||||
js {
|
||||
browser {
|
||||
// commonWebpackConfig {
|
||||
// cssSupport {
|
||||
// enabled.set(true)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
// val hostOs = System.getProperty("os.name")
|
||||
@ -39,16 +34,15 @@ kotlin {
|
||||
// else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
|
||||
// }
|
||||
|
||||
// macosArm64()
|
||||
// iosX64()
|
||||
// iosArm64()
|
||||
// iosSimulatorArm64()
|
||||
macosArm64()
|
||||
iosX64()
|
||||
iosArm64()
|
||||
iosSimulatorArm64()
|
||||
linuxX64()
|
||||
linuxArm64()
|
||||
// macosX64()
|
||||
macosX64()
|
||||
|
||||
|
||||
val ktor_version = "2.3.6"
|
||||
val ktor_version = "2.3.12"
|
||||
|
||||
sourceSets {
|
||||
all {
|
||||
@ -64,17 +58,20 @@ kotlin {
|
||||
|
||||
// api("com.ionspin.kotlin:bignum:0.3.9")
|
||||
api("io.ktor:ktor-client-core:$ktor_version")
|
||||
|
||||
// api("net.sergeych:mp_bintools:0.1.1")
|
||||
// api("net.sergeych:mp_stools:1.4.7")
|
||||
api("net.sergeych:crypto2:0.4.1-SNAPSHOT")
|
||||
api("net.sergeych:crypto2:0.4.2")
|
||||
}
|
||||
}
|
||||
// val ktorSocketMain by creating {
|
||||
// dependsOn(commonMain)
|
||||
// dependencies {
|
||||
// implementation("io.ktor:ktor-network:$ktor_version")
|
||||
// }
|
||||
// }
|
||||
val commonTest by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("test"))
|
||||
implementation("org.slf4j:slf4j-simple:2.0.9")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.1")
|
||||
}
|
||||
}
|
||||
val jvmMain by getting {
|
||||
@ -85,6 +82,7 @@ kotlin {
|
||||
implementation("io.ktor:ktor-server-netty:$ktor_version")
|
||||
api("io.ktor:ktor-client-cio:$ktor_version")
|
||||
}
|
||||
// dependsOn(ktorSocketMain)
|
||||
}
|
||||
val jvmTest by getting
|
||||
val jsMain by getting {
|
||||
@ -93,12 +91,10 @@ kotlin {
|
||||
}
|
||||
}
|
||||
val jsTest by getting
|
||||
// val nativeMain by getting {
|
||||
// dependencies {
|
||||
// implementation("io.ktor:ktor-client-cio:$ktor_version")
|
||||
// }
|
||||
// }
|
||||
// val nativeTest by getting
|
||||
|
||||
// for (pm in listOf(linuxMain, macosMain, iosMain, mingwMain))
|
||||
// pm { dependsOn(ktorSocketMain) }
|
||||
|
||||
}
|
||||
|
||||
publishing {
|
||||
|
37
src/commonMain/kotlin/net/sergeych/kiloparsec/AsyncVarint.kt
Normal file
37
src/commonMain/kotlin/net/sergeych/kiloparsec/AsyncVarint.kt
Normal file
@ -0,0 +1,37 @@
|
||||
package net.sergeych.kiloparsec
|
||||
|
||||
import io.ktor.utils.io.*
|
||||
|
||||
object AsyncVarint {
|
||||
suspend fun encodeUnsigned(value: ULong, output: ByteWriteChannel) {
|
||||
var rest = value
|
||||
do {
|
||||
val x = (rest and 127u).toInt()
|
||||
rest = rest shr 7
|
||||
if (rest > 0u)
|
||||
output.writeByte(x or 0x80)
|
||||
else
|
||||
output.writeByte(x)
|
||||
|
||||
} while (rest > 0u)
|
||||
}
|
||||
|
||||
suspend fun decodeUnsigned(source: ByteReadChannel): ULong {
|
||||
var result: ULong = 0u
|
||||
var count = 0
|
||||
while (true) {
|
||||
val x = source.readUByte().toInt()
|
||||
result = result or ((x and 0x7F).toULong() shl count)
|
||||
if ((x and 0x80) == 0)
|
||||
break
|
||||
count += 7
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun ByteReadChannel.readUByte(): UByte = this.readByte().toUByte()
|
||||
|
||||
suspend fun ByteWriteChannel.writeByte(byte: Int) {
|
||||
this.writeByte(byte.toByte())
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package net.sergeych.kiloparsec
|
||||
|
||||
/**
|
||||
* The local interface to provice functions, register errors for Kiloparsec users. Use it
|
||||
* The local interface to provide functions, register errors for Kiloparsec users. Use it
|
||||
* with [KiloClient], [KiloClientConnection], [KiloServerConnection], etc.
|
||||
*
|
||||
* BAse implementation registers relevant exceptions.
|
||||
|
@ -22,12 +22,14 @@ actual fun acceptTcpDevice(port: Int): Flow<InetTransportDevice> {
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
println("0 --- $port")
|
||||
val connectedSocket = suspendCancellableCoroutine { continuation ->
|
||||
continuation.invokeOnCancellation {
|
||||
socket.close()
|
||||
}
|
||||
socket.accept(continuation, ContinuationHandler())
|
||||
}
|
||||
println("1 ---")
|
||||
emit(asyncSocketToDevice(connectedSocket))
|
||||
}
|
||||
}
|
||||
|
@ -100,16 +100,9 @@ class ClientTest {
|
||||
on(cmdCheckConnected) { connectedCalled }
|
||||
on(cmdClose) {
|
||||
throw LocalInterface.BreakConnectionException()
|
||||
// if( closeCounter < 2 ) {
|
||||
// println("-------------------------- call close!")
|
||||
// throw RemoteInterface.ClosedException()
|
||||
// }
|
||||
// else {
|
||||
// println("close counter $closeCounter, ignoring")
|
||||
// }
|
||||
}
|
||||
}
|
||||
// val server = setupWebsoketServer()
|
||||
|
||||
val ns: NettyApplicationEngine = embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = {
|
||||
setupWebsocketServer(serverInterface) { Session() }
|
||||
}).start(wait = false)
|
||||
|
@ -10,6 +10,7 @@ import net.sergeych.kiloparsec.adapter.toNetworkAddress
|
||||
import net.sergeych.kiloparsec.decodeFromUByteArray
|
||||
import net.sergeych.kiloparsec.encodeToUByteArray
|
||||
import net.sergeych.mp_logger.Log
|
||||
import net.sergeych.mp_logger.LogTag
|
||||
import net.sergeych.synctools.ProtectedOp
|
||||
import net.sergeych.synctools.invoke
|
||||
import kotlin.test.Test
|
||||
@ -43,8 +44,11 @@ class NetworkTest {
|
||||
val op = ProtectedOp()
|
||||
var pills = setOf<String>()
|
||||
val j = launch {
|
||||
println("serf")
|
||||
serverFlow.collect { device ->
|
||||
println("serf 0")
|
||||
launch {
|
||||
println("serf 1")
|
||||
device.output.send("Hello, world!".encodeToUByteArray())
|
||||
device.output.send("Great".encodeToUByteArray())
|
||||
while (true) {
|
||||
@ -63,13 +67,22 @@ class NetworkTest {
|
||||
}
|
||||
yield()
|
||||
run {
|
||||
val s = connectTcpDevice("127.0.1.1:17171".toNetworkAddress())
|
||||
assertEquals("Hello, world!", s.input.receive().decodeFromUByteArray())
|
||||
assertEquals("Great", s.input.receive().decodeFromUByteArray())
|
||||
s.output.send("Goodbye".encodeToUByteArray())
|
||||
s.output.send("die1".encodeToUByteArray())
|
||||
s.close()
|
||||
try {
|
||||
println("pre-con")
|
||||
val s = connectTcpDevice("127.0.1.1:17171".toNetworkAddress())
|
||||
println("2")
|
||||
assertEquals("Hello, world!", s.input.receive().decodeFromUByteArray())
|
||||
assertEquals("Great", s.input.receive().decodeFromUByteArray())
|
||||
s.output.send("Goodbye".encodeToUByteArray())
|
||||
s.output.send("die1".encodeToUByteArray())
|
||||
s.close()
|
||||
}
|
||||
catch(t: Throwable) {
|
||||
t.printStackTrace()
|
||||
throw t
|
||||
}
|
||||
}
|
||||
println("pre-con2")
|
||||
val s1 = connectTcpDevice("127.0.1.1:17171".toNetworkAddress())
|
||||
assertEquals("Hello, world!", s1.input.receive().decodeFromUByteArray())
|
||||
assertEquals("Great", s1.input.receive().decodeFromUByteArray())
|
||||
|
43
src/ktorSocketMain/kotlin/adapter/socketClient.kt
Normal file
43
src/ktorSocketMain/kotlin/adapter/socketClient.kt
Normal file
@ -0,0 +1,43 @@
|
||||
package net.sergeych.kiloparsec.adapter
|
||||
|
||||
import io.ktor.network.selector.*
|
||||
import io.ktor.network.sockets.*
|
||||
import io.ktor.util.network.*
|
||||
import io.ktor.utils.io.*
|
||||
import io.ktor.utils.io.core.*
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import net.sergeych.kiloparsec.AsyncVarint
|
||||
import net.sergeych.mp_logger.LogTag
|
||||
import kotlin.io.use
|
||||
|
||||
//class SocketNetworkAddress(override val host: String, override val port: Int) : NetworkAddress
|
||||
//
|
||||
//actual fun NetworkAddress(host: String, port: Int): NetworkAddress = SocketNetworkAddress(host, port)
|
||||
//
|
||||
//fun acceptTcpSocketDevice(port: Int): Flow<InetTransportDevice> {
|
||||
// val selectorManager = SelectorManager(Dispatchers.IO)
|
||||
// val serverSocket = aSocket(selectorManager).tcp().bind("127.0.0.1", port)
|
||||
// val log = LogTag("TCPS${}")
|
||||
// return flow {
|
||||
// serverSocket.accept().use { sock ->
|
||||
// val closed = CompletableDeferred<Boolean>()
|
||||
// val scope = coroutineScope {
|
||||
// val networkAddress = sock.remoteAddress.toJavaAddress().let { NetworkAddress(it.hostname, it.port) }
|
||||
// val inputBlocks = Channel<UByteArray>(4096)
|
||||
// sock.launch {
|
||||
// val sockInput = sock.openReadChannel()
|
||||
// while (isActive && sock.isActive) {
|
||||
// try {
|
||||
// val size = AsyncVarint.decodeUnsigned(sockInput)
|
||||
// } catch (e: Exception) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
Loading…
x
Reference in New Issue
Block a user