Skip to content

Commit

Permalink
Fix on KorgeIPCSocket
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jun 25, 2024
1 parent d3b01e7 commit 6a51874
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions korge-ipc/src/main/kotlin/korlibs/korge/ipc/KorgeIPCSocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,22 @@ class IPCPacket(
socket.write(head)
}

fun ReadableByteChannel.readFull(dst: ByteBuffer) {
while (dst.remaining() > 0) {
val read = read(dst)
if (read <= 0) error("Couldn't read")
}
}

fun read(socket: SocketChannel): IPCPacket {
val head = ByteBuffer.allocate(8)
socket.read(head)
socket.readFull(head)
head.flip()
val type = head.int
val size = head.int
val data = ByteArray(size)
if (size > 0) {
socket.read(ByteBuffer.wrap(data))
socket.readFull(ByteBuffer.wrap(data))
}
return IPCPacket(type, data)
}
Expand Down

0 comments on commit 6a51874

Please sign in to comment.