ByteStream

interface ByteStream

The minimal byte-duplex a PeerConnection needs: read exactly N bytes, write a frame. This is the seam between the protocol state machine and the concrete socket. libtorrent keeps the equivalent inside peer_connection's m_recv_buffer and send_buffer code, which couples the protocol to Boost.Asio. Separating it lets you test PeerConnection against an in-memory duplex with no live sockets.

TcpConnection (session.net) already provides exactly these two operations; the asByteStream adapter wraps one without modifying it.

Inheritors

Properties

Link copied to clipboard
abstract val remoteAddress: String

A human-readable identifier for the remote end, for logging.

Functions

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

Suspend until exactly n bytes have been read, then return them.

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

Write bytes in full (and flush, for a socket implementation).