Rename: Connection.read() -> Connection.receive()

This commit is contained in:
Mark Spanbroek 2020-11-02 18:00:54 +01:00 committed by markspanbroek
parent 38433d723f
commit 805fefe50c
4 changed files with 12 additions and 12 deletions

View File

@ -8,7 +8,7 @@ import ngtcp2/streams
export Connection
export newClientConnection
export newServerConnection
export read, write
export receive, write
export isHandshakeCompleted
export waitForHandshake
export Stream

View File

@ -40,7 +40,7 @@ proc waitForHandshake*(connection: Connection) {.async.} =
while not connection.isHandshakeCompleted:
await connection.write()
proc read*(connection: Connection, datagram: DatagramBuffer, ecn = ecnNonCapable) =
proc receive*(connection: Connection, datagram: DatagramBuffer, ecn = ecnNonCapable) =
var packetInfo: ngtcp2_pkt_info
packetInfo.ecn = ecn.uint32
checkResult ngtcp2_conn_read_pkt(
@ -53,5 +53,5 @@ proc read*(connection: Connection, datagram: DatagramBuffer, ecn = ecnNonCapable
)
connection.flowing.fire()
proc read*(connection: Connection, datagram: Datagram) =
connection.read(datagram.data, datagram.ecn)
proc receive*(connection: Connection, datagram: Datagram) =
connection.receive(datagram.data, datagram.ecn)

View File

@ -5,7 +5,7 @@ import addresses
proc sendLoop(source, destination: Connection) {.async.} =
while true:
let datagram = await source.outgoing.get()
destination.read(datagram)
destination.receive(datagram)
proc performHandshake*: Future[tuple[client, server: Connection]] {.async.} =
@ -15,7 +15,7 @@ proc performHandshake*: Future[tuple[client, server: Connection]] {.async.} =
let datagram = await client.outgoing.get()
let server = newServerConnection(zeroAddress, zeroAddress, datagram.data)
server.read(datagram)
server.receive(datagram)
let serverHandshake = server.waitForHandshake()
let clientLoop = sendLoop(client, server)

View File

@ -13,22 +13,22 @@ suite "udp":
let datagram = await client.outgoing.get()
check datagram.len > 0
asynctest "reads packets from datagram":
asynctest "processes received datagrams":
let client = newClientConnection(zeroAddress, zeroAddress)
await client.write()
let datagram = await client.outgoing.get()
let server = newServerConnection(zeroAddress, zeroAddress, datagram.data)
server.read(datagram)
server.receive(datagram)
test "raises error when reading datagram fails":
test "raises error when receiving bad datagram":
let datagram = repeat(0'u8, 4096)
let server = newServerConnection(zeroAddress, zeroAddress, datagram)
expect IOError:
server.read(datagram)
server.receive(datagram)
test "raises error when reading empty datagram":
test "raises error when receiving empty datagram":
let client = newClientConnection(zeroAddress, zeroAddress)
expect IOError:
client.read(@[])
client.receive(@[])