Length Prefixed stream implementation
Types
InvalidVarintError = object of LPStreamError
- Source Edit
LPStream = ref object of RootObj closeEvent*: AsyncEvent isClosed*: bool isEof*: bool objName*: string oid*: Oid dir*: Direction closedWithEOF: bool
- Source Edit
LPStreamClosedError = object of LPStreamEOFError
- Source Edit
LPStreamConnDownError = object of LPStreamEOFError
- Source Edit
LPStreamEOFError = object of LPStreamError
- Source Edit
LPStreamError = object of LPError
- Source Edit
LPStreamIncompleteError = object of LPStreamError
- Source Edit
LPStreamLimitError = object of LPStreamError
- Source Edit
LPStreamRemoteClosedError = object of LPStreamEOFError
- Source Edit
LPStreamResetError = object of LPStreamEOFError
- Source Edit
MaxSizeError = object of LPStreamError
- Source Edit
StreamTracker = ref object of TrackerBase opened*: uint64 closed*: uint64
- Source Edit
Procs
proc closeWithEOF(s: LPStream): InternalRaisesFuture[void, void] {.public(), stackTrace: false, ...raises: [], gcsafe, gcsafe, raises: [], gcsafe, raises: [], tags: [RootEffect].}
-
Close the stream and wait for EOF - use this with half-closed streams where an EOF is expected to arrive from the other end.
Note - this should only be used when there has been an in-protocol notification that no more data will arrive and that the only thing left for the other end to do is to close the stream gracefully.
In particular, it must not be used when there is another concurrent read ongoing (which may be the case during cancellations)!
Source Edit proc join(s: LPStream): InternalRaisesFuture[void, (CancelledError,)] {. public(), stackTrace: false, ...raises: [], gcsafe, gcsafe, raises: [], gcsafe, raises: [], tags: [].}
- Source Edit
proc newLPStreamClosedError(): ref LPStreamClosedError {....gcsafe, raises: [], tags: [].}
- Source Edit
proc newLPStreamConnDownError(parentException: ref Exception = nil): ref LPStreamConnDownError {. ...gcsafe, raises: [], tags: [].}
- Source Edit
proc newLPStreamEOFError(): ref LPStreamEOFError {....gcsafe, raises: [], tags: [].}
- Source Edit
proc newLPStreamIncompleteError(): ref LPStreamIncompleteError {....gcsafe, raises: [], tags: [].}
- Source Edit
proc newLPStreamLimitError(): ref LPStreamLimitError {....gcsafe, raises: [], tags: [].}
- Source Edit
proc newLPStreamRemoteClosedError(): ref LPStreamRemoteClosedError {....gcsafe, raises: [], tags: [].}
- Source Edit
proc newLPStreamResetError(): ref LPStreamResetError {....gcsafe, raises: [], tags: [].}
- Source Edit
proc readExactly(s: LPStream; pbytes: pointer; nbytes: int): InternalRaisesFuture[ void, (CancelledError, LPStreamError)] {.public(), stackTrace: false, ...raises: [], gcsafe, gcsafe, raises: [], gcsafe, raises: [], tags: [RootEffect].}
- Waits for nbytes to be available, then read them and return them Source Edit
proc readLine(s: LPStream; limit = 0; sep = "\r\n"): InternalRaisesFuture[ string, (CancelledError, LPStreamError)] {.public(), stackTrace: false, ...raises: [], gcsafe, gcsafe, raises: [], gcsafe, raises: [], tags: [RootEffect].}
- Reads up to limit bytes are read, or a sep is found Source Edit
proc readLp(s: LPStream; maxSize: int): InternalRaisesFuture[seq[byte], (CancelledError, LPStreamError)] {.public(), stackTrace: false, ...raises: [], gcsafe, gcsafe, raises: [], gcsafe, raises: [], tags: [RootEffect].}
- read length prefixed msg, with the length encoded as a varint Source Edit
proc readVarint(conn: LPStream): InternalRaisesFuture[uint64, (CancelledError, LPStreamError)] {.public(), stackTrace: false, ...raises: [], gcsafe, gcsafe, raises: [], gcsafe, raises: [], tags: [RootEffect].}
- Source Edit
proc write(s: LPStream; msg: string): InternalRaisesFuture[void, (CancelledError, LPStreamError)] {.public(), stackTrace: false, ...raises: [], gcsafe, gcsafe, raises: [], gcsafe, raises: [], tags: [].}
- Source Edit
proc writeLp(s: LPStream; msg: openArray[byte]): InternalRaisesFuture[void, (CancelledError, LPStreamError)] {.public(), stackTrace: false, ...raises: [], gcsafe, gcsafe, raises: [], gcsafe, raises: [], tags: [].}
- Source Edit
proc writeLp(s: LPStream; msg: string): InternalRaisesFuture[void, (CancelledError, LPStreamError)] {.public(), stackTrace: false, ...raises: [], gcsafe, gcsafe, raises: [], gcsafe, raises: [], tags: [].}
- Source Edit
Methods
method close(s: LPStream): InternalRaisesFuture[void, void] {.base, public(), stackTrace: false, ...raises: [], gcsafe, gcsafe, raises: [], gcsafe, raises: [], tags: [].}
- Source Edit
method closeImpl(s: LPStream): InternalRaisesFuture[void, void] {.base, stackTrace: false, ...raises: [], gcsafe, gcsafe, raises: [], gcsafe, raises: [], tags: [].}
- Source Edit
method initStream(s: LPStream) {.base, ...gcsafe, raises: [], tags: [TimeEffect].}
- Source Edit
method readOnce(s: LPStream; pbytes: pointer; nbytes: int): InternalRaisesFuture[ int, (CancelledError, LPStreamError)] {.base, public(), stackTrace: false, ...raises: [], gcsafe, gcsafe, raises: [], gcsafe, raises: [], tags: [].}
- Source Edit
method write(s: LPStream; msg: seq[byte]): InternalRaisesFuture[void, (CancelledError, LPStreamError)] {.base, public(), stackTrace: false, ...raises: [], gcsafe, gcsafe, raises: [], gcsafe, raises: [], tags: [].}
- Source Edit
Templates
template formatItIMPL(it: LPStream): auto
- Source Edit