From 6a54952c8be91d1e1436bb3fb0338eefb2bbe654 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Mon, 2 Nov 2020 14:56:28 +0100 Subject: [PATCH] Introduce sequence of outgoing datagrams --- quic/ngtcp2/connection.nim | 2 ++ quic/ngtcp2/udp.nim | 4 +++- tests/helpers/connections.nim | 9 ++++++--- tests/quic/testUdp.nim | 7 +++++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/quic/ngtcp2/connection.nim b/quic/ngtcp2/connection.nim index 9682736..412d2a0 100644 --- a/quic/ngtcp2/connection.nim +++ b/quic/ngtcp2/connection.nim @@ -1,4 +1,5 @@ import ngtcp2 +import ../datagram import path type @@ -7,6 +8,7 @@ type conn*: ptr ngtcp2_conn path*: Path buffer*: array[4096, byte] + outgoing*: seq[Datagram] proc `=destroy`*(connection: var ConnectionObj) = if connection.conn != nil: diff --git a/quic/ngtcp2/udp.nim b/quic/ngtcp2/udp.nim index 011aeb4..2425f1d 100644 --- a/quic/ngtcp2/udp.nim +++ b/quic/ngtcp2/udp.nim @@ -7,7 +7,7 @@ import connection import path import errors -proc write*(connection: Connection): Datagram = +proc write*(connection: Connection) = var packetInfo: ngtcp2_pkt_info let length = ngtcp2_conn_write_stream( connection.conn, @@ -22,8 +22,10 @@ proc write*(connection: Connection): Datagram = 0, getMonoTime().ticks.uint ) + var result: Datagram result.data = connection.buffer[0.. 0 + client.write() + let datagram = client.outgoing.pop() + check datagram.len > 0 test "reads packets from datagram": let client = newClientConnection(zeroAddress, zeroAddress) - let datagram = client.write() + client.write() + let datagram = client.outgoing.pop() let server = newServerConnection(zeroAddress, zeroAddress, datagram.data) server.read(datagram)