TcpConnection

class TcpConnection(socket: Socket)

A TCP connection to a peer (or HTTP tracker). Thin coroutine wrapper over a ktor Socket exposing the two operations the wire protocol needs: read exactly N bytes, and write a frame. Replaces the bespoke async read/write buffers in libtorrent's peer_connection.

Constructors

Link copied to clipboard
constructor(socket: Socket)

Properties

Link copied to clipboard

Functions

Link copied to clipboard

Adapt a proven TcpConnection to the ByteStream seam. The connection itself is untouched; this is a thin forwarding wrapper so production code feeds a real socket into PeerConnection while tests feed a fake.

Link copied to clipboard
fun close()
Link copied to clipboard
suspend fun readExactly(n: Int): ByteArray

Suspends until exactly n bytes have been read, then returns them.

Link copied to clipboard
suspend fun write(bytes: ByteArray)

Write bytes and flush.