2019-09-01 17:31:24 +00:00
|
|
|
## Nim-LibP2P
|
2019-09-24 17:48:23 +00:00
|
|
|
## Copyright (c) 2019 Status Research & Development GmbH
|
2019-09-01 17:31:24 +00:00
|
|
|
## Licensed under either of
|
|
|
|
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
## at your option.
|
|
|
|
## This file may not be copied, modified, or distributed except according to
|
|
|
|
## those terms.
|
|
|
|
|
2020-04-14 13:21:16 +00:00
|
|
|
import oids
|
|
|
|
import chronicles, chronos
|
2019-09-01 17:31:24 +00:00
|
|
|
|
2019-12-10 20:50:35 +00:00
|
|
|
type
|
2019-09-01 17:31:24 +00:00
|
|
|
LPStream* = ref object of RootObj
|
2019-12-04 04:44:54 +00:00
|
|
|
isClosed*: bool
|
|
|
|
closeEvent*: AsyncEvent
|
2020-04-14 13:21:16 +00:00
|
|
|
when chronicles.enabledLogLevel == LogLevel.TRACE:
|
|
|
|
oid*: Oid
|
2019-09-01 17:31:24 +00:00
|
|
|
|
|
|
|
LPStreamError* = object of CatchableError
|
|
|
|
LPStreamIncompleteError* = object of LPStreamError
|
|
|
|
LPStreamIncorrectError* = object of Defect
|
|
|
|
LPStreamLimitError* = object of LPStreamError
|
|
|
|
LPStreamReadError* = object of LPStreamError
|
|
|
|
par*: ref Exception
|
|
|
|
LPStreamWriteError* = object of LPStreamError
|
|
|
|
par*: ref Exception
|
2019-12-10 20:50:35 +00:00
|
|
|
LPStreamEOFError* = object of LPStreamError
|
2019-09-01 17:31:24 +00:00
|
|
|
|
2019-09-01 21:56:00 +00:00
|
|
|
proc newLPStreamReadError*(p: ref Exception): ref Exception {.inline.} =
|
|
|
|
var w = newException(LPStreamReadError, "Read stream failed")
|
2019-09-01 17:31:24 +00:00
|
|
|
w.msg = w.msg & ", originated from [" & $p.name & "] " & p.msg
|
|
|
|
w.par = p
|
|
|
|
result = w
|
|
|
|
|
|
|
|
proc newLPStreamWriteError*(p: ref Exception): ref Exception {.inline.} =
|
|
|
|
var w = newException(LPStreamWriteError, "Write stream failed")
|
|
|
|
w.msg = w.msg & ", originated from [" & $p.name & "] " & p.msg
|
|
|
|
w.par = p
|
|
|
|
result = w
|
|
|
|
|
|
|
|
proc newLPStreamIncompleteError*(): ref Exception {.inline.} =
|
|
|
|
result = newException(LPStreamIncompleteError, "Incomplete data received")
|
|
|
|
|
|
|
|
proc newLPStreamLimitError*(): ref Exception {.inline.} =
|
|
|
|
result = newException(LPStreamLimitError, "Buffer limit reached")
|
|
|
|
|
|
|
|
proc newLPStreamIncorrectError*(m: string): ref Exception {.inline.} =
|
|
|
|
result = newException(LPStreamIncorrectError, m)
|
|
|
|
|
2019-12-10 20:50:35 +00:00
|
|
|
proc newLPStreamEOFError*(): ref Exception {.inline.} =
|
|
|
|
result = newException(LPStreamEOFError, "Stream EOF!")
|
2019-09-04 06:40:11 +00:00
|
|
|
|
2019-12-10 20:50:35 +00:00
|
|
|
method closed*(s: LPStream): bool {.base, inline.} =
|
2019-12-04 04:44:54 +00:00
|
|
|
s.isClosed
|
|
|
|
|
2020-03-27 14:25:52 +00:00
|
|
|
method read*(s: LPStream,
|
|
|
|
n = -1):
|
|
|
|
Future[seq[byte]] {.base, async.} =
|
2019-10-03 19:29:58 +00:00
|
|
|
doAssert(false, "not implemented!")
|
2019-09-01 17:31:24 +00:00
|
|
|
|
2020-03-27 14:25:52 +00:00
|
|
|
method readExactly*(s: LPStream,
|
|
|
|
pbytes: pointer,
|
|
|
|
nbytes: int):
|
|
|
|
Future[void] {.base, async.} =
|
2019-10-03 19:29:58 +00:00
|
|
|
doAssert(false, "not implemented!")
|
2019-09-01 17:31:24 +00:00
|
|
|
|
2020-03-27 14:25:52 +00:00
|
|
|
method readLine*(s: LPStream,
|
|
|
|
limit = 0,
|
|
|
|
sep = "\r\n"):
|
|
|
|
Future[string]
|
2019-12-04 04:44:54 +00:00
|
|
|
{.base, async.} =
|
2019-10-03 19:29:58 +00:00
|
|
|
doAssert(false, "not implemented!")
|
2019-09-01 17:31:24 +00:00
|
|
|
|
2020-03-27 14:25:52 +00:00
|
|
|
method readOnce*(s: LPStream,
|
|
|
|
pbytes: pointer,
|
|
|
|
nbytes: int):
|
|
|
|
Future[int]
|
2019-12-04 04:44:54 +00:00
|
|
|
{.base, async.} =
|
2019-10-03 19:29:58 +00:00
|
|
|
doAssert(false, "not implemented!")
|
2019-09-01 17:31:24 +00:00
|
|
|
|
|
|
|
method readUntil*(s: LPStream,
|
2020-03-27 14:25:52 +00:00
|
|
|
pbytes: pointer,
|
|
|
|
nbytes: int,
|
|
|
|
sep: seq[byte]):
|
|
|
|
Future[int]
|
2019-12-04 04:44:54 +00:00
|
|
|
{.base, async.} =
|
2019-10-03 19:29:58 +00:00
|
|
|
doAssert(false, "not implemented!")
|
2019-09-01 17:31:24 +00:00
|
|
|
|
|
|
|
method write*(s: LPStream, pbytes: pointer, nbytes: int)
|
2019-12-04 04:44:54 +00:00
|
|
|
{.base, async.} =
|
2019-10-03 19:29:58 +00:00
|
|
|
doAssert(false, "not implemented!")
|
2019-09-01 17:31:24 +00:00
|
|
|
|
|
|
|
method write*(s: LPStream, msg: string, msglen = -1)
|
2019-12-04 04:44:54 +00:00
|
|
|
{.base, async.} =
|
2019-10-03 19:29:58 +00:00
|
|
|
doAssert(false, "not implemented!")
|
2019-09-01 17:31:24 +00:00
|
|
|
|
|
|
|
method write*(s: LPStream, msg: seq[byte], msglen = -1)
|
2019-12-04 04:44:54 +00:00
|
|
|
{.base, async.} =
|
2019-10-03 19:29:58 +00:00
|
|
|
doAssert(false, "not implemented!")
|
2019-09-01 17:31:24 +00:00
|
|
|
|
|
|
|
method close*(s: LPStream)
|
2019-12-04 04:44:54 +00:00
|
|
|
{.base, async.} =
|
2019-10-03 19:29:58 +00:00
|
|
|
doAssert(false, "not implemented!")
|