This commit is contained in:
Tanguy 2023-01-17 17:26:44 +01:00
parent a4e7cdbfc9
commit 1909a7d80b
No known key found for this signature in database
GPG Key ID: 7DD8EC6B6CE6C45E
3 changed files with 15 additions and 5 deletions

View File

@ -10,6 +10,7 @@ export Stream, close, read, write
type
Connection* = ref object of RootObj
udp: DatagramTransport
remote: TransportAddress
quic: QuicConnection
loop: Future[void]
onClose: Opt[proc() {.gcsafe, upraises: [].}]
@ -71,6 +72,7 @@ proc newIncomingConnection*(udp: DatagramTransport,
let connection = IncomingConnection(udp: udp, quic: quic, closed: closed)
proc onDisconnect {.async.} =
await connection.disconnect()
connection.remote = remote
quic.disconnect = Opt.some(onDisconnect)
connection.startSending(remote)
connection
@ -82,6 +84,7 @@ proc newOutgoingConnection*(udp: DatagramTransport,
let connection = OutgoingConnection(udp: udp, quic: quic, closed: closed)
proc onDisconnect {.async.} =
await connection.disconnect()
connection.remote = remote
quic.disconnect = Opt.some(onDisconnect)
connection.startSending(remote)
connection
@ -94,7 +97,7 @@ proc receive*(connection: Connection, datagram: Datagram) =
proc remoteAddress*(connection: Connection): TransportAddress {.
raises: [Defect, TransportOsError].} =
connection.udp.remoteAddress()
connection.remote
proc localAddress*(connection: Connection): TransportAddress {.
raises: [Defect, TransportOsError].} =

View File

@ -4,8 +4,8 @@ import pkg/quic
suite "api":
setup:
let address = initTAddress("127.0.0.1:48579")
var listener = listen(address)
var listener = listen(initTAddress("127.0.0.1:0"))
let address = listener.localAddress
teardown:
waitFor listener.stop()
@ -17,6 +17,11 @@ suite "api":
let outgoing = await dialing
let incoming = await accepting
check:
outgoing.remoteAddress.port == address.port
outgoing.localAddress.port == incoming.remoteAddress.port
incoming.localAddress.port == address.port
await outgoing.drop()
await incoming.drop()

View File

@ -7,8 +7,10 @@ import ../helpers/udp
suite "listener":
setup:
let address = initTAddress("127.0.0.1:45346")
var listener = newListener(address)
var listener = newListener(initTAddress("127.0.0.1:0"))
let address = listener.localAddress
check address.port != Port(0)
teardown:
waitFor listener.stop()