How can I use ktor with native sockets? I tried th...
# ktor
h
How can I use ktor with native sockets? I tried this code, but it fails because I have to use an internal class. So what is the expected API?
Copy code
val selector = SelectorManager(coroutineScope.coroutineContext)
try {
  val socket = PQsocket(conn)
  check(socket >= 0) {
    "Error while connecting to the PostgreSql socket"
  }
  
  while (true) {
    selector.select(
      object : Selectable {
          override val descriptor = socket
      },
      SelectInterest.READ
    )
    // my logic
} finally {
  selector.close()
}
At the end, I just want to use
select(socket)
and execute my logic when getting new input
r
@e5l can you help, please?
e
Hey, we didn't consider using side socket classes with Ktor SelectorManager. Could you log an issue? It should be possible to add
h
So the selector and socket api is only intended to use with internal ktor apis?
e
It's also possible to use it with the public
aSocket
API as in Jvm
h
Do you have a sample? With native select, I would pass the file descriptor, not a port. One possible fix would be removing this (useless) line. I currently don't know how to write a test. https://github.com/ktorio/ktor/blob/24d91c337fe9874ca1b5235ecdb2dbfa52cf11a9/ktor-network/nix/src/io/ktor/network/selector/WorkerSelectorManager.kt#L30