Giter Site home page Giter Site logo

korlibs-archive / korio Goto Github PK

View Code? Open in Web Editor NEW
362.0 15.0 34.0 3.23 MB

Korio: Kotlin cORoutines I/O : Virtual File System + Async/Sync Streams + Async TCP Client/Server + WebSockets for Multiplatform Kotlin 1.3

Home Page: https://korlibs.soywiz.com/korio/

License: MIT License

kotlin coroutines kotlin-coroutines asynchronous vfs websockets json xml yaml jtransc

korio's Introduction

korio's People

Contributors

soywiz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

korio's Issues

WebSocketClient for iOS DEBUG parameter causes build error

When using WebSocketClient in common library, kotlin compiler generates module headers for iOS app. Uppercased name of 'DEBUG' parameter in constructor causes build error for WebSocketClient and for RawSocketWebSocketClient. I think renaming 'DEBUG' to 'debug' will fix the issue.

Снимок экрана 2020-06-09 в 13 59 02

Resource not found

import com.soywiz.korio.file.std.resourcesVfs is not finding the resource.

The scenario:

  • module1 contains the resource
  • test in module 1 finds the resource correctly

module2 depends on module1

  • contains a main method
  • calls a function on an object in module 1 that accesses the resource
  • com.soywiz.korio.lang.InvalidOperationException: Can't find in ResourcesVfsProviderJvm
    running from InteliJ the error is different,
  • java.io.FileNotFoundException: ....../module2/classes/kotlin/jvm8/main/

seems that it is looking in the module2 classpath rather than the module1 classpath

Support zero-copy transfers using MappedByteBuffer

The library should ensure that a AsyncStream.copyTo from an uncompressed local file (after proper vfs resolving) ends using a common MappedByteBuffer and that directly copies that buffer into a socket or other file. This will allow faster zero-copy transfers with less memory requirements managed by the operating system.

KN multi-threading problems

There are a lot of static members which doesn't mark as @ThreadLocal or @SharedImmutable. So, sometimes in multi-threading env we get an exception like this: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread. Are you planning to solve these problems?

Json can't serialize arrays

Using this code:

class B()
class A(val a: Array)
val encoded = Json.encode(A(arrayOf(B())))

Leads to an exception :(

com.soywiz.korio.error.InvalidOperationException: Can't find constructor for class [LExample1$main$1$B; at com.soywiz.korio.error.ErrorKt.invalidOp(error.kt:24) at com.soywiz.korio.error.ErrorKt.invalidOp$default(error.kt:24) at com.soywiz.korio.util.ClassFactory.<init>(ClassFactory.kt:52)

Can't seem to use the library on mingw?

Using Gradle 4.10 with enableFeaturePreview('GRADLE_METADATA') with id 'kotlin-multiplatform' version '1.3.20'

and this dependency setup

     mingwMain {
            dependencies {
                implementation "org.jetbrains.kotlin:kotlin-stdlib"
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native_debug_mingw_x64:1.1.1"
                implementation "com.soywiz:korio:0.20.0"
                implementation "org.jetbrains.kotlinx:atomicfu-windows64:0.12.2"
            }
        }

Kotlin does for the mingw code does not seem to find korio related things at all? Any pointers?

WebSocketClient hang

Reported by Oleg on slack:

fun testMe() = run < Unit > {
    var conn: WebSocketClient
    val j = GlobalScope.launch {
        conn = WebSocketClient("ws://MINI:22237", null, null, "", false)
    }
    GlobalScope.launch {
        println("wait conn")
        j.join()
        println("finish wait conn")
    }
}

As I understood finish wait conn is not printed.

uncaught exception: NotImplementedError: An operation is not implemented: onBinaryMessage, onAnyMessage

Hello. When I try to read the message in a compiled JS file, I get the following error:

uncaught exception: NotImplementedError: An operation is not implemented: onBinaryMessage, onAnyMessage

Can't do it? Here is my code:

myWebSocket = WebSocketClient(url,null,null,"",false)
signalonOpen = MyWebSocketChannel!!.onOpen
signalonBinaryMessage = MyWebSocketChannel!!.onBinaryMessage
val buf = signalonBinaryMessage?.waitOne(timeout = t);

HTTP Client send duplicate headers

com.soywiz.korlibs.korio:korio:1.10.2

I use wireshark to capture the network packages and find the headers are duplicated many times.

I set custom header "user-agent" or "User-Agent", but there still exist the default header "User-Agent: Mozilla/5.0 Korio/1.0.0 (KHTML, like Gecko) Chrome/71.0 Safari/537.0".

java.lang.NoClassDefFoundError: com/soywiz/korio/file/std/LocalVfsJvmKt when using library in Android

Using version 1.11.1

I have a library that uses korio (it's awesome, thanks ;-) ), the plan being to use that library on Android and on the server. The dependency to korio in that library is declared in my build.gradle.kts as follows

kotlin {
    sourceSets {
        main {
            dependencies {
                implementation("com.soywiz.korlibs.korio:korio:1.11.1")
            }
        }
    }
}

with the enableFeaturePreview("GRADLE_METADATA") flag set in the settings.gradle.kts

My android project has the dependency declared via implementation("com.soywiz.korlibs.korio:korio-android:1.11.1")

When I run the tests that use the code I get the following error:

java.lang.NoClassDefFoundError: com/soywiz/korio/file/std/LocalVfsJvmKt

The code in my standalone library that the test bails on is something like:

// all korio related imports below
import com.soywiz.korio.async.toChannel
import com.soywiz.korio.file.VfsFile
import com.soywiz.korio.file.VfsOpenMode
import com.soywiz.korio.file.VfsStat
import com.soywiz.korio.file.std.createZipFromTreeTo
import com.soywiz.korio.file.std.toVfs
import com.soywiz.korio.stream.AsyncInputStream
import com.soywiz.korio.stream.asyncStreamWriter
import com.soywiz.korio.stream.write64LE
import com.soywiz.korio.stream.writeString
// other imports

class SomeFunctionality {

    // other bits

    suspend fun file(name: String, javaFile: java.io.File) {
        val file = javaFile.toVfs()  // error is from here
        require(file.exists() && !file.isDirectory()) { "The file provided either does not exist or is a directory" }
        // the functionality
    }

    // more bits
}

Weirdly, in the android code I add some code like println("DIR = ${theDir.toVfs()}") and it prints out the path just fine.

Have you seen this behaviour before or any ideas how to remedy? I think I'm missing some multiplatform/gradle incantation somewhere

NB I've also tried without the flag set and the dependency declared via implementation("com.soywiz.korlibs.korio:korio:1.11.1") in the dependencies block with the same resulting behaviour.

Concurrency issues with resourcesVfs["IMAGE"].readBitmap() ?

I use a code similar to this:

 override suspend fun initBody() {
        image = preInitializedBitmap ?: resourcesVfs[imageFile].readBitmapOptimized()
        width = image.width * scale
        height = image.height * scale
        shape = BoxShape(width = width, height = height)
        body = world.createBody(bd)
        fixture.density = density
        fixture.shape = shape
        fixture.friction = friction
        fixture.restitution = restitution
        body.createFixture(fixture)
        createView()
        body.setView(view)
    }



    override suspend fun createView() {
        view = Graphics().image(image) {
            position(x, y)
        }.scale(scale).anchor(.5, .5)
        view.apply {
            onOver {
                //writeInfo()
            }
        }
    }

which creates box2d bodies and applies an image to their view. It works well for 1-20 objects. But when I spawn 50 or 100 Bodies with the same image as view, some do really get displayed but then the program crashes:

java.lang.IllegalStateException: Check failed.
at org.jbox2d.dynamics.World.createBody(World.kt:1920)
at engineEmi.Bodies.Image.initBody(Image.kt:41)
at engineEmi.Bodies.Image$initBody$1.invokeSuspend(Image.kt)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
at com.soywiz.korgw.GameWindowCoroutineDispatcher.executePending(GameWindow.kt:83)
at com.soywiz.korgw.DefaultGameWindowJvmKt$DefaultGameWindow$1.loop(DefaultGameWindowJvm.kt:381)
at com.soywiz.korgw.DefaultGameWindowJvmKt$DefaultGameWindow$1$loop$1.invokeSuspend(DefaultGameWindowJvm.kt)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
at kotlinx.coroutines.DispatchedKt.resumeCancellable(Dispatched.kt:185)
at kotlinx.coroutines.ResumeModeKt.resumeMode(ResumeMode.kt:22)
at kotlinx.coroutines.DispatchedKt.resume(Dispatched.kt:272)
at kotlinx.coroutines.DispatchedKt.dispatch(Dispatched.kt:261)
at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:218)
at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:227)
at kotlinx.coroutines.CancellableContinuationImpl.resumeUndispatched(CancellableContinuationImpl.kt:299)
at kotlinx.coroutines.EventLoopImplBase$DelayedResumeTask.run(EventLoop.kt:298)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.kt:116)
at kotlinx.coroutines.DefaultExecutor.run(DefaultExecutor.kt:68)
at java.lang.Thread.run(Thread.java:748)
Exception in thread "kotlinx.coroutines.DefaultExecutor" java.lang.IllegalStateException: Check failed.
at org.jbox2d.dynamics.World.createBody(World.kt:1920)
at engineEmi.Bodies.Image.initBody(Image.kt:41)
at engineEmi.Bodies.Image$initBody$1.invokeSuspend(Image.kt)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
at com.soywiz.korgw.GameWindowCoroutineDispatcher.executePending(GameWindow.kt:83)
at com.soywiz.korgw.DefaultGameWindowJvmKt$DefaultGameWindow$1.loop(DefaultGameWindowJvm.kt:381)
at com.soywiz.korgw.DefaultGameWindowJvmKt$DefaultGameWindow$1$loop$1.invokeSuspend(DefaultGameWindowJvm.kt)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
at kotlinx.coroutines.DispatchedKt.resumeCancellable(Dispatched.kt:185)
at kotlinx.coroutines.ResumeModeKt.resumeMode(ResumeMode.kt:22)
at kotlinx.coroutines.DispatchedKt.resume(Dispatched.kt:272)
at kotlinx.coroutines.DispatchedKt.dispatch(Dispatched.kt:261)
at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:218)
at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:227)
at kotlinx.coroutines.CancellableContinuationImpl.resumeUndispatched(CancellableContinuationImpl.kt:299)
at kotlinx.coroutines.EventLoopImplBase$DelayedResumeTask.run(EventLoop.kt:298)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.kt:116)
at kotlinx.coroutines.DefaultExecutor.run(DefaultExecutor.kt:68)
at java.lang.Thread.run(Thread.java:748)

Kotlin 1.30.31

Hi there! What is the status of 1.3.30-31 upgrade?:)
Are you have some plans for it?..

Opening Zip File tells "Not a zip file record 0xFFFFFFFF instead of 0x504B0102

When I try to open a ZIP file created on my mac it will tell:
Caused by: java.lang.IllegalStateException: Not a zip file record 0xFFFFFFFF instead of 0x504B0102
2020-05-13 02:17:23.411 15528-16050/? W/System.err: at com.soywiz.korio.file.std.ZipVfsKt.ZipVfs(ZipVfs.kt:95)
2020-05-13 02:17:23.412 15528-16050/? W/System.err: at com.soywiz.korio.file.std.ZipVfsKt.openAsZip(ZipVfs.kt:260)
2020-05-13 02:17:23.412 15528-16050/? W/System.err: at com.soywiz.korio.file.std.ZipVfsKt.openAsZip(ZipVfs.kt:264)
2020-05-13 02:17:23.412 15528-16050/? W/System.err: at com.soywiz.korio.file.std.ZipVfsKt.openAsZip$default(ZipVfs.kt:263)

What can I do about it? Thanks :)

Unable to make connection to custom port (websocket)

URL parsing seems to be broken. We have websocket on custom port. If I make connection to websocket using WebSocketClient("websocket.domain.com:8080") I got error "IllegalStateException: Unknown ws protocol com". Why uri.scheme becomes "com"? And why default scheme for WebSocketClient is not "ws"?

If I make connection to websocket using WebSocketClient("ws://websocket.domain.com:8080") I got error "UnresolvedAddressException" because connection host in JvmAsyncClient becomes "websocket.domain.com:8080:80".

I think this is caused by incorrect port parsing. Port is ignored on Uri string, and URL.port is always DEFAULT_PORT: https://github.com/korlibs/korio/blob/master/korio/src/commonMain/kotlin/com/soywiz/korio/net/URL.kt#L87 which being replaced by 80/443 in https://github.com/korlibs/korio/blob/master/korio/src/commonMain/kotlin/com/soywiz/korio/net/URL.kt#L23

val port: Int
	get() = if (defaultPort == DEFAULT_PORT) {
		when (scheme) {
			"http", "ws" -> 80
			"https", "wss" -> 443
			else -> -1
		}
	} else {
		defaultPort
	}

And port also can be replaced here: https://github.com/korlibs/korio/blob/master/korio/src/commonMain/kotlin/com/soywiz/korio/net/ws/RawSocketWebSocketClient.kt#L29

val port = uri.defaultPort.takeIf { it != URL.DEFAULT_PORT } ?: if (secure) 443 else 80

Compiler error on 1.3+

It seems korio was built using experimental coroutines rather than the currently stdlib coroutines, causing compiler errors.

Output of gradle build:
> Task :compileKotlin FAILED
w: -Xcoroutines has no effect: coroutines are enabled anyway in 1.3 and beyond
e: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't transform method node:
create (Lcom/soywiz/korio/async/SuspendingSequenceBuilder;Lkotlin/coroutines/experimental/Continuation;)Lkotlin/coroutines/experimental/Continuation;:
  @Lorg/jetbrains/annotations/NotNull;() // invisible
    @Lorg/jetbrains/annotations/NotNull;() // invisible, parameter 0
    @Lorg/jetbrains/annotations/NotNull;() // invisible, parameter 1
   L0
    ALOAD 1
    LDC "$receiver"
    INVOKESTATIC kotlin/jvm/internal/Intrinsics.checkParameterIsNotNull (Ljava/lang/Object;Ljava/lang/String;)V
    ALOAD 2
    LDC "continuation"
    INVOKESTATIC kotlin/jvm/internal/Intrinsics.checkParameterIsNotNull (Ljava/lang/Object;Ljava/lang/String;)V
    NEW xyz/devnullgame/server/entities/Commands$listFiles$$inlined$map$1
    DUP
    ALOAD 0
    GETFIELD xyz/devnullgame/server/entities/Commands$listFiles$$inlined$map$1.receiver$0 : Lcom/soywiz/korio/async/SuspendingSequence;
    ALOAD 2
    INVOKESPECIAL xyz/devnullgame/server/entities/Commands$listFiles$$inlined$map$1.<init> (Lcom/soywiz/korio/async/SuspendingSequence;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/experimental/Continuation;)V
    ASTORE 3
    ALOAD 1
    ALOAD 3
    ALOAD 1
    PUTFIELD xyz/devnullgame/server/entities/Commands$listFiles$$inlined$map$1.p$ : Lcom/soywiz/korio/async/SuspendingSequenceBuilder;
    ALOAD 3
    ASTORE 4
    POP
    ALOAD 4
    ARETURN
   L1
    LOCALVARIABLE $receiver Lcom/soywiz/korio/async/SuspendingSequenceBuilder; L0 L1 1
    LOCALVARIABLE continuation Lkotlin/coroutines/experimental/Continuation; L0 L1 2
    MAXSTACK = 4
    MAXLOCALS = 5

Element is unknownThe root cause java.lang.AssertionError was thrown at: org.jetbrains.kotlin.codegen.optimization.MethodVerifier.transform(MethodVerifier.kt:28)
        at org.jetbrains.kotlin.codegen.TransformationMethodVisitor.visitEnd(TransformationMethodVisitor.kt:92)
        at org.jetbrains.org.objectweb.asm.MethodVisitor.visitEnd(MethodVisitor.java:778)
        at org.jetbrains.org.objectweb.asm.MethodVisitor.visitEnd(MethodVisitor.java:778)
        at org.jetbrains.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:813)
        at org.jetbrains.kotlin.codegen.inline.DeferredMethodVisitor.visitEnd(DeferredMethodVisitor.kt:31)
        at org.jetbrains.kotlin.codegen.inline.AnonymousObjectTransformer.doTransform(AnonymousObjectTransformer.kt:175)
        at org.jetbrains.kotlin.codegen.inline.MethodInliner$doInline$lambdaInliner$1.handleAnonymousObjectRegeneration(MethodInliner.kt:183)
        at org.jetbrains.kotlin.codegen.inline.MethodInliner$doInline$lambdaInliner$1.anew(MethodInliner.kt:207)
        at org.jetbrains.org.objectweb.asm.commons.InstructionAdapter.visitTypeInsn(InstructionAdapter.java:472)
        at org.jetbrains.org.objectweb.asm.tree.TypeInsnNode.accept(TypeInsnNode.java:77)
        at org.jetbrains.org.objectweb.asm.tree.InsnList.accept(InsnList.java:144)
        at org.jetbrains.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:792)
        at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.kt:389)
        at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.kt:97)
        at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.kt:70)
        at org.jetbrains.kotlin.codegen.inline.InlineCodegen.inlineCall(InlineCodegen.kt:261)
        at org.jetbrains.kotlin.codegen.inline.InlineCodegen.performInline(InlineCodegen.kt:142)
        at org.jetbrains.kotlin.codegen.inline.PsiInlineCodegen.genCallInner(PsiInlineCodegen.kt:67)
        at org.jetbrains.kotlin.codegen.CallGenerator$DefaultImpls.genCall(CallGenerator.kt:115)
        at org.jetbrains.kotlin.codegen.inline.PsiInlineCodegen.genCall(PsiInlineCodegen.kt:31)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2533)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2476)
        at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:41)
        at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:13)
        at org.jetbrains.kotlin.codegen.OperationStackValue.putSelector(StackValue.kt:79)
        at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:122)
        at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:115)
        at org.jetbrains.kotlin.codegen.StackValue.moveToTopOfStack(StackValue.java:103)
        at org.jetbrains.kotlin.codegen.CallReceiver.putSelector(CallReceiver.java:171)
        at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:122)
        at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:115)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.putReceiverAndInlineMarkerIfNeeded(ExpressionCodegen.java:2565)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2495)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2476)
        at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:41)
        at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:13)
        at org.jetbrains.kotlin.codegen.OperationStackValue.putSelector(StackValue.kt:79)
        at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:122)
        at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:115)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.initializeLocalVariable(ExpressionCodegen.java:4354)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.visitProperty(ExpressionCodegen.java:4221)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.visitProperty(ExpressionCodegen.java:112)
        at org.jetbrains.kotlin.psi.KtProperty.accept(KtProperty.java:58)
        at org.jetbrains.kotlin.codegen.CodegenStatementVisitor.visitKtElement(CodegenStatementVisitor.java:31)
        at org.jetbrains.kotlin.codegen.CodegenStatementVisitor.visitKtElement(CodegenStatementVisitor.java:22)
        at org.jetbrains.kotlin.psi.KtVisitor.visitExpression(KtVisitor.java:182)
        at org.jetbrains.kotlin.psi.KtVisitor.visitDeclaration(KtVisitor.java:29)
        at org.jetbrains.kotlin.psi.KtVisitor.visitNamedDeclaration(KtVisitor.java:398)
        at org.jetbrains.kotlin.psi.KtVisitor.visitProperty(KtVisitor.java:57)
        at org.jetbrains.kotlin.psi.KtProperty.accept(KtProperty.java:58)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:302)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.genStatement(ExpressionCodegen.java:407)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.generateBlock(ExpressionCodegen.java:1269)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.generateBlock(ExpressionCodegen.java:1214)
        at org.jetbrains.kotlin.codegen.CodegenStatementVisitor.visitBlockExpression(CodegenStatementVisitor.java:56)
        at org.jetbrains.kotlin.codegen.CodegenStatementVisitor.visitBlockExpression(CodegenStatementVisitor.java:22)
        at org.jetbrains.kotlin.psi.KtBlockExpression.accept(KtBlockExpression.java:78)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:302)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.genStatement(ExpressionCodegen.java:407)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:364)
        at org.jetbrains.kotlin.codegen.ExpressionCodegen.returnExpression(ExpressionCodegen.java:1701)
        at org.jetbrains.kotlin.codegen.coroutines.SuspendFunctionGenerationStrategy.doGenerateBody(SuspendFunctionGenerationStrategy.kt:112)
        at org.jetbrains.kotlin.codegen.FunctionGenerationStrategy$CodegenBased.generateBody(FunctionGenerationStrategy.java:84)
        at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:666)
        at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:473)
        at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:260)
        at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:176)
        at org.jetbrains.kotlin.codegen.FunctionCodegen.gen(FunctionCodegen.java:147)
        at org.jetbrains.kotlin.codegen.MemberCodegen.genSimpleMember(MemberCodegen.java:197)
        at org.jetbrains.kotlin.codegen.ClassBodyCodegen.generateDeclaration(ClassBodyCodegen.java:166)
        at org.jetbrains.kotlin.codegen.ClassBodyCodegen.generateBody(ClassBodyCodegen.java:86)
        at org.jetbrains.kotlin.codegen.MemberCodegen.generate(MemberCodegen.java:129)
        at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:302)
        at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:286)
        at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateClassesAndObjectsInFile(PackageCodegenImpl.java:118)
        at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateFile(PackageCodegenImpl.java:137)
        at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:68)
        at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generatePackage(CodegenFactory.kt:96)
        at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generateModule(CodegenFactory.kt:67)
        at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.doGenerateFiles(KotlinCodegenFacade.java:47)
        at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:39)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:637)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:195)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:165)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:55)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:84)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:42)
        at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:104)
        at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:349)
        at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:105)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:237)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:37)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:79)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:91)
        at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:606)
        at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:99)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1645)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
        at sun.rmi.transport.Transport$1.run(Transport.java:200)
        at sun.rmi.transport.Transport$1.run(Transport.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.AssertionError: AFTER mandatory stack transformations: incorrect bytecode
        at org.jetbrains.kotlin.codegen.optimization.MethodVerifier.transform(MethodVerifier.kt:28)
        at org.jetbrains.kotlin.codegen.optimization.transformer.CompositeMethodTransformer.transform(CompositeMethodTransformer.kt:25)
        at org.jetbrains.kotlin.codegen.optimization.OptimizationMethodVisitor.performTransformations(OptimizationMethodVisitor.kt:62)
        at org.jetbrains.kotlin.codegen.TransformationMethodVisitor.visitEnd(TransformationMethodVisitor.kt:70)
        ... 113 more
Caused by: java.lang.RuntimeException: org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException: Error at instruction 13: Cannot pop operand off an empty stack.
        at org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer.runAnalyzer(MethodTransformer.java:34)
        at org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer.analyze(MethodTransformer.java:44)
        at org.jetbrains.kotlin.codegen.optimization.MethodVerifier.transform(MethodVerifier.kt:26)
        ... 116 more
Caused by: org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException: Error at instruction 13: Cannot pop operand off an empty stack.
        at org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer.analyze(Analyzer.java:295)
        at org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer.runAnalyzer(MethodTransformer.java:31)
        ... 118 more
Caused by: java.lang.IndexOutOfBoundsException: Cannot pop operand off an empty stack.
        at org.jetbrains.org.objectweb.asm.tree.analysis.Frame.pop(Frame.java:226)
        at org.jetbrains.org.objectweb.asm.tree.analysis.Frame.execute(Frame.java:295)
        at org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer.analyze(Analyzer.java:187)
        ... 119 more


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileKotlin'.
> Compilation error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
1 actionable task: 1 executed

Error when trying to instantiate RawSocketWebSocketClient

Reported here: https://korlibs.soywiz.com/faq/#comment-4835281266

Hello. I am trying to create an instance of the RawSocketWebSocketClient
(RawSocketWebSocketClient(url,null, null, null, false);)
class in my multi-platform project.
But the generated JS script (in the browser) throws an error:\

TypeError: "require_req is not a function"

require_node@file:///Z:/home/proectName.com/www/JSOCKET....
NodeJsAsyncClient@file:///Z:/home/proectName.com/www/JSOCKET....
require_node@file:///Z:/home/proectName.com/www/JSOCKET....
NodeJsAsyncClient@file:///Z:/home/proectName.com/www/JSOCKET....
proectName

What license?

What is the exact license for Korio?

Right now the Contributing page just states some marketing terms like free of charge or suggest changes but no actual license.

Personally I would recommend the Apache 2.0 License or BSD 3-clause licenses, as they provide the most freedom without the cancer that is "copyleft".

java.lang.NoSuchMethodError: com.soywiz.korio.net.ws.WebSocketsJvmKt

Hi Carlos,

Currently looking into your KorGE tutorials and trying to add a websocket into my game using korio.

Here's the error message after the app starts

java.lang.NoSuchMethodError: com.soywiz.korio.net.ws.WebSocketsJvmKt.WebSocketClient$default(Ljava/lang/String;Ljava/util/List;Ljava/lang/String;Ljava/lang/String;ZLkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
	at MainScene.sceneInit(Main.kt:38)
	at com.soywiz.korge.scene.SceneContainer$_changeTo$3.invokeSuspend(SceneContainer.kt:118)
	at com.soywiz.korge.scene.SceneContainer$_changeTo$3.invoke(SceneContainer.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:91)
	at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:177)

Here's my code:

class MainScene : Scene() {
    var ws:WebSocketClient? = null
    override suspend fun Container.sceneInit() {
        text("Hello there!")

        ws = WebSocketClient("ws://127.0.0.1:7777/ws/")
        val ws = ws!!

        ws.onBinaryMessage {
            val w = Wire.protoUnmarshal(it)
            println(w)
        }
        println("sending to ws...")
        ws.send(Wire(login = Login()).protoMarshal())
    }
}

inside the build.gradle file I have the following dependencies

		jvmCompile "com.soywiz.korlibs.korio:korio:1.9.8"
		jvmCompile "com.soywiz.korlibs.korio:korio-jvm:1.9.8"

Rethink streams

https://github.com/soywiz/korio/blob/c3d96d26d093d2b893c673824acbceb45c3ecd51/korio/src/com/soywiz/korio/stream/AsyncStream.kt#L13

// @TODO: Rethink this!
// @TODO: All AsyncStreams should be this, so we can clone it just creating a class with the pointers
// @TODO: Similar to what VfsFile is for Vfs

Cloning requires special handling. What if the base class for streams doesn't have notion of pointers? So you should extend AsyncStreamBase but use AsyncStream that is a AsyncStreamBase + file pointer. This way you would be able to clone AsyncStream without having to have special treatment for each descendant class.

Websockets clients doenst work

Hi there! I've just try to use your websocket multiplatform and got a lot of queestions.
First of all, you have a ignored test for com.soywiz.korio.net.ws.WebSocketTest. If I try to change the implementation, I always stay in infinity loop in com/soywiz/korio/net/ws/RawSocketWebSocketClient.kt#connect:127
Secondly: implementation for windows doesn't work at all. I had to change something in com.soywiz.korio.net.NativeSocket#connect, and I want to discuss it :)
All of this situation seems strange. May be I dont understand some approaches...))) Please give me feedback ASAP

Some problem with linux target.

Hi, @soywiz. I got some problem when trying to create shared library from your korio linux part.

`ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol __environ; recompile with -fPIC

defined in /Users/igor_kuzminykh/.konan/dependencies/target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/sysroot/lib64/libc.so.6
referenced by Types.kt:187 (/Users/teamcity/buildAgent/work/4d622a065c544371/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Types.kt:187)
/var/folders/81/1x8w9mxd38n8ynv7r2z3vfdh0000gp/T/konan_temp6619027810560038268/result.o:(platform_posix_kniBridge42)
e: /Users/igor_kuzminykh/.konan/dependencies/clang-llvm-apple-8.0.0-darwin-macos/bin/ld.lld invocation reported errors`

Do you know what specific things can breed this error? I investigate your repo and didn't find any specific things for build linux. May be it related with your CI env?

JVM Test error : java.nio.channels.UnresolvedAddressException

Hello. Tell me why I get this JVM Test error when I try to get WebSocketClient:
val url = "ws://localhostname:3456"
val c: WebSocketClient = RawSocketWebSocketClient(url,null, null, null, false)
...java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Net.java:101)...

And one more thing: can I get RawSocketWebSocketClient из WebSocketClient ? For instance:
val url = "ws://localhostname:3456"
val c: RawSocketWebSocketClient = RawSocketWebSocketClient(url,null, null, null, false) as RawSocketWebSocketClient

TcpClient in windows seems to have issues

Korio version=1.6.4

Using this simple code:

    GlobalScope.async {
        val tcpClient = createTcpClient(false)
        tcpClient.connect("172.65.204.172", 12995)
        if(tcpClient.connected){
            println("We are connected!")
            tcpClient.write(dataBytes)
            val result = tcpClient.readAll()
        }
    }

Will casts kotlin.IllegalStateException: WSA error(connect): 10051 on Windows.
This will work on mac, but instead it does not seem to write/read any of the data the server should get/send back

Missing query params on websocket connection

I need to make websocket connection to a service passing some parameters in url:
WebSocketClient("ws://myserver/wsHub?id=someId")

but Korio uses only path from url on connection, and misses query params:
add("GET ${urlUrl.path} HTTP/1.1") in RawSocketWebSocketClient.kt:83

Provide SSL/TLS/HTTPS on native targets

Explanation runBlockingNoSuspensions ()

Hello. Explanation, please, to me the purpose of the function runBlockingNoSuspensions ().
I assume that it makes asynchronous function calls synchronous.
But when I run the function main():

val connection: RawSocketWebSocketClient

fun setConn(connectionIpAddress: String, сonnPort: Int):RawSocketWebSocketClient = runBlockingNoSuspensions{
var cl = createTcpClient()
cl.connect(connectionIpAddress, сonnPort)
val s = RawSocketWebSocketClient(
GlobalScope.coroutineContext, cl!!, URL.invoke(""), null, false, null, ""
)
return@runBlockingNoSuspensions s
}

fun main(){
  GlobalScope.launch { 
  val connection = setConn("localHostName",22236)
  println(connection.host)
  }
}

I get an error:
com.soywiz.korio.lang.InvalidOperationException: runBlockingNoSuspensions was not completed synchronously! suspendCount=1

RawSocketWebSocketClient.read() blocked Thread

Hello. When I try to read data from a socket,
my thread freezes. (data comes in - that's for sure). Here is my code:

private suspend fun conn(connectionDNSName :String, connPort :Int){
val cl = createTcpClient()
cl.connect(connectionDNSName, connPort)
val mySocket = RawSocketWebSocketClient(
GlobalScope.coroutineContext, cl, URL.invoke(""), null, false, null, "")
//val r = MySocketChannel.readBinary() -- freezes
//val r = MySocketChannel..client.readAll() -- freezes
//val r = MySocketChannel..client.readAvailable() -- freezes

}

And one more question:
can I get RawSocketWebSocketClient from WebSocketClient ? For instance:
val url = "ws://hostname:3456"
val c: RawSocketWebSocketClient = WebSocketClient(url) as RawSocketWebSocketClient
And work with him as with RawSocketWebSocketClient.

How to manipulate local files?

Hi,

korio is awesome! But I still didn't find out how to manipulate local files.
I suppose maybe in someway like VfsFile("path").writeText("content")?
Could you please show me some clues or sample code?

Thank you!

The replacement coroutines library inside is inconsistent with the Kotlin API

Is there a reason to differ from the Kotlin Coroutines API at this point in time? It's confusing to drop into this, or try to use this code mixed with other coroutines code using the Kotlinx library for coroutines. Imports get funky, method parameters differ, contexts aren't shared.

What's the thought process for this?

Korio NIO async server resets connections under client pressure

Change the AsyncServerTest to have 500 or so clients and it'll start having peer resets on connection.

package whatever;

import com.soywiz.korio.async.await
import com.soywiz.korio.async.spawn
import com.soywiz.korio.async.syncTest
import com.soywiz.korio.net.AsyncClient
import com.soywiz.korio.net.AsyncServer
import com.soywiz.korio.stream.readString
import com.soywiz.korio.stream.writeString
import org.junit.Assert
import org.junit.Test
import java.util.*
import java.util.concurrent.atomic.AtomicInteger

class AsyncClientServerTest {

    companion object {
        val UUIDLength = 36
    }

    @Test
    fun testClientServer() = syncTest {
        val server  = AsyncServer(port = 0)
        val counter = AtomicInteger()

        val clientsCount  = 500
        val correctEchoes = LinkedList<Boolean>()

        val clients = (1..clientsCount).map {
            spawn {
                val client = AsyncClient.createAndConnect("127.0.0.1", server.port)

                val msg = UUID.randomUUID().toString()
                client.writeString(msg)
                val echo = client.readString(UUIDLength)

                correctEchoes.add(msg == echo)
            }
        }

        for (client in server.listen()) {
            val msg = client.readString(UUIDLength)
            client.writeString(msg)

            if (counter.incrementAndGet() == clientsCount) {
                break
            }
        }

        clients.await()

        Assert.assertEquals(clientsCount, counter.get())
        Assert.assertEquals(clientsCount, correctEchoes.size)
        Assert.assertTrue(correctEchoes.all { it })
    }


}

@Post and @Param annotations does not work on POST Requests

 @Route(Http.Methods.POST, "/api/v1/user")
    suspend fun createUser(response: Http.Response, @Post("nickName") nickName: String): String {

        response.header("Content-Type", "application/json; charset=utf-8")

        return Json.encode(User(nickName))
    }

nickName is ever empty

Reading/Writing structs

It would be great to be able to read write binary classes/data classes describing its structure like C# marshaling.

annotation class Struct(val size: Int)
annotation class Element(val offset: Int, val size: Int = -1)

object Structs {
}

fun SyncStream.writeStruct(value: Any) {
}

inline fun <reified T : Any> SyncStream.readStruct(): T = readStruct(T::class.java)

inline fun <reified T : Any> SyncStream.readStruct(clazz: Class<*>): T {
	noImpl
}

TypeError: this.resultContinuation_0 is undefined...

Hello. I am trying to use WebSocket in my project.
But, the compiled JS script in the browser gives me such an error.
Here is my code:

private const val STANDART_TIME_OUT: Double = 5000.0
private val STANDART_TIME_OUT_SPAN = TimeSpan(STANDART_TIME_OUT)

class Connection(u: String) {
private val url = u
private lateinit var myConnection :Deferred
private lateinit var mySocketChannel :WebSocketClient
private lateinit var signalonOpen :Signal

init {
    if(connectionDNSName.isNotEmpty()){
        myConnection = GlobalScope.async{ setConn() }}
    }
}

 private suspend fun setConn(){
    try {
        mySocketChannel = WebSocketClient(url,null,null,"",false)
        signalonOpen = MySocketChannel.onOpen
    }
    catch (e: Exception)
    {
        println(e.toString())
    }
}

@JsName("waitConn")
suspend fun waitConn(){
    signalonOpen.waitOne(STANDART_TIME_OUT_SPAN)
}

@JsName("send_data")
suspend fun send_data(){
    if(myConnection.isActive)
        {myConnection.await()}
	mySocketChannel.send("Hello Soywiz")
}

And here is how I try to use this cad in the browser:

 <html>
   <head>
      <meta charset="UTF-8">
   </head>
   
   <body>
      <p>Before script...</p>
	  <script src="MyProect.js"></script>
      <script type="text/javascript">
	      async function f() {
		     var c = new myProectName.Connection("localhost",22236);
			 c.waitConn();
			 c.send_data();}
		  f();
	   </script>
	   <p>...After script</p>
   </body>
</html>

Here is the error I get:

TypeError: this.resultContinuation_0 is undefined...

I found that this is due to calls to wait functions. Maybe I'm doing something wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.