Skip to content

A small piece of code reproducing ByteReadChannel bugs #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kobe2000 opened this issue May 17, 2018 · 0 comments
Closed

A small piece of code reproducing ByteReadChannel bugs #363

kobe2000 opened this issue May 17, 2018 · 0 comments
Assignees

Comments

@kobe2000
Copy link

Hi
I reported an issue to ktor framework, which is in fact an known bug in kotlinx.coroutines, so I paste the code here too.

import io.ktor.network.sockets.aSocket
import io.ktor.network.sockets.openReadChannel
import io.ktor.network.sockets.openWriteChannel
import kotlinx.coroutines.experimental.async
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.runBlocking
import java.net.InetSocketAddress

fun main(args: Array<String>) {

    async {
        val server = aSocket().tcp().bind(InetSocketAddress(12000))
        while (true) {
            println("accept")
            val socket = server.accept()
            launch {
                val wc = socket.openWriteChannel(autoFlush = true)
                while (true) {
                    wc.writeByte(1)
                    wc.writeInt(1)
                }
            }
        }
    }

    Thread.sleep(1000)

    runBlocking {
        aSocket().tcp().connect(InetSocketAddress("localhost", 12000)).use { socket ->
            val rc = socket.openReadChannel()
            while (true) {
                check(rc.readByte() == 1.toByte()) { "byte" }
                check(rc.readInt() == 1) { "int" }
            }
        }
    }
}
@cy6erGn0m cy6erGn0m self-assigned this May 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants