mirror of https://github.com/vacp2p/nim-quic.git
Introduce sequence of outgoing datagrams
This commit is contained in:
parent
ddd874b6d1
commit
6a54952c8b
|
@ -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:
|
||||
|
|
|
@ -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..<length]
|
||||
result.ecn = ECN(packetInfo.ecn)
|
||||
connection.outgoing.insert(result)
|
||||
|
||||
proc read*(connection: Connection, datagram: DatagramBuffer, ecn = ecnNonCapable) =
|
||||
var packetInfo: ngtcp2_pkt_info
|
||||
|
|
|
@ -6,15 +6,18 @@ proc performHandshake*: tuple[client, server: Connection] =
|
|||
var datagram: Datagram
|
||||
|
||||
let client = newClientConnection(zeroAddress, zeroAddress)
|
||||
datagram = client.write()
|
||||
client.write()
|
||||
datagram = client.outgoing.pop()
|
||||
|
||||
let server = newServerConnection(zeroAddress, zeroAddress, datagram.data)
|
||||
server.read(datagram)
|
||||
|
||||
datagram = server.write()
|
||||
server.write()
|
||||
datagram = server.outgoing.pop()
|
||||
client.read(datagram)
|
||||
|
||||
datagram = client.write()
|
||||
client.write()
|
||||
datagram = client.outgoing.pop()
|
||||
server.read(datagram)
|
||||
|
||||
(client, server)
|
||||
|
|
|
@ -7,11 +7,14 @@ suite "udp":
|
|||
|
||||
test "writes packets to datagrams":
|
||||
let client = newClientConnection(zeroAddress, zeroAddress)
|
||||
check client.write().len > 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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue