rename readerwriter to stream

This commit is contained in:
Dmitriy Ryajov 2019-08-27 15:45:21 -06:00
parent d23398f498
commit 3d7f657ce8
5 changed files with 63 additions and 12 deletions

View File

@ -8,9 +8,9 @@
## those terms. ## those terms.
import chronos import chronos
import readerwriter import stream
type ChronosStream* = ref object of ReadWrite type ChronosStream* = ref object of LPStream
reader: AsyncStreamReader reader: AsyncStreamReader
writer: AsyncStreamWriter writer: AsyncStreamWriter
server: StreamServer server: StreamServer

View File

@ -8,16 +8,16 @@
## those terms. ## those terms.
import chronos import chronos
import peerinfo, multiaddress, readerwriter, peerinfo, varint, vbuffer import peerinfo, multiaddress, stream, peerinfo, varint, vbuffer
const DefaultReadSize: uint = 64*1024 const DefaultReadSize: uint = 64*1024
type type
Connection* = ref object of ReadWrite Connection* = ref object of LPStream
peerInfo*: PeerInfo peerInfo*: PeerInfo
stream: ReadWrite stream: LPStream
proc newConnection*(stream: ReadWrite): Connection = proc newConnection*(stream: LPStream): Connection =
## create a new Connection for the specified async reader/writer ## create a new Connection for the specified async reader/writer
new result new result
result.stream = stream result.stream = stream

51
libp2p/stream.nim Normal file
View File

@ -0,0 +1,51 @@
## Nim-LibP2P
## Copyright (c) 2018 Status Research & Development GmbH
## 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.
import chronos
type LPStream* = ref object of RootObj
closed*: bool
method read*(s: LPStream, n = -1): Future[seq[byte]]
{.base, async.} =
discard
method readExactly*(s: LPStream, pbytes: pointer, nbytes: int): Future[void]
{.base, async.} =
discard
method readLine*(s: LPStream, limit = 0, sep = "\r\n"): Future[string]
{.base, async.} =
discard
method readOnce*(s: LPStream, pbytes: pointer, nbytes: int): Future[int]
{.base, async.} =
discard
method readUntil*(s: LPStream,
pbytes: pointer, nbytes: int,
sep: seq[byte]): Future[int]
{.base, async.} =
discard
method write*(s: LPStream, pbytes: pointer, nbytes: int)
{.base, async.} =
discard
method write*(s: LPStream, msg: string, msglen = -1)
{.base, async.} =
discard
method write*(s: LPStream, msg: seq[byte], msglen = -1)
{.base, async.} =
discard
method close*(s: LPStream)
{.base, async.} =
discard

View File

@ -8,7 +8,7 @@
## those terms. ## those terms.
import chronos import chronos
import peerinfo, connection, multiaddress, multicodec, readerwriter import peerinfo, connection, multiaddress, multicodec
type type
ConnHandler* = proc (conn: Connection): Future[void] {.gcsafe.} ConnHandler* = proc (conn: Connection): Future[void] {.gcsafe.}

View File

@ -1,12 +1,12 @@
import unittest, strutils, sequtils, sugar import unittest, strutils, sequtils, sugar
import chronos import chronos
import ../libp2p/connection, ../libp2p/multistreamselect, import ../libp2p/connection, ../libp2p/multistreamselect,
../libp2p/readerwriter, ../libp2p/connection, ../libp2p/multiaddress, ../libp2p/stream, ../libp2p/connection, ../libp2p/multiaddress,
../libp2p/transport, ../libp2p/tcptransport ../libp2p/transport, ../libp2p/tcptransport
## Mock stream for select test ## Mock stream for select test
type type
TestSelectStream = ref object of ReadWrite TestSelectStream = ref object of LPStream
step*: int step*: int
method readExactly*(s: TestSelectStream, method readExactly*(s: TestSelectStream,
@ -41,7 +41,7 @@ proc newTestSelectStream(): TestSelectStream =
## Mock stream for handles test ## Mock stream for handles test
type type
TestHandlesStream = ref object of ReadWrite TestHandlesStream = ref object of LPStream
step*: int step*: int
method readExactly*(s: TestHandlesStream, method readExactly*(s: TestHandlesStream,
@ -78,7 +78,7 @@ proc newTestHandlesStream(): TestHandlesStream =
type type
LsHandler = proc(procs: seq[byte]): Future[void] LsHandler = proc(procs: seq[byte]): Future[void]
TestLsStream = ref object of ReadWrite TestLsStream = ref object of LPStream
step*: int step*: int
ls*: LsHandler ls*: LsHandler
@ -121,7 +121,7 @@ proc newTestLsStream(ls: LsHandler): TestLsStream =
type type
NaHandler = proc(procs: string): Future[void] NaHandler = proc(procs: string): Future[void]
TestNaStream = ref object of ReadWrite TestNaStream = ref object of LPStream
step*: int step*: int
na*: NaHandler na*: NaHandler