QuicConnection fires event when closed

This commit is contained in:
Mark Spanbroek 2020-12-17 09:28:45 +01:00 committed by markspanbroek
parent 2161c3b769
commit b156e2c8f7
3 changed files with 12 additions and 2 deletions

View File

@ -13,6 +13,9 @@ proc newClosedConnection*: ClosedConnection =
{.push locks: "unknown".}
method enter(state: ClosedConnection, connection: QuicConnection) =
connection.closed.fire()
method ids(state: ClosedConnection): seq[ConnectionId] =
@[]

View File

@ -7,8 +7,9 @@ type
QuicConnection* = ref object
state: ConnectionState
outgoing*: AsyncQueue[Datagram]
handshake*: AsyncEvent
incoming*: AsyncQueue[Stream]
handshake*: AsyncEvent
closed*: AsyncEvent
ConnectionState* = ref object of RootObj
IdCallback* = proc(id: ConnectionId)
ConnectionError* = object of IOError
@ -51,8 +52,9 @@ proc newQuicConnection*(state: ConnectionState): QuicConnection =
let connection = QuicConnection(
state: state,
outgoing: newAsyncQueue[Datagram](),
incoming: newAsyncQueue[Stream](),
handshake: newAsyncEvent(),
incoming: newAsyncQueue[Stream]()
closed: newAsyncEvent()
)
state.enter(connection)
connection

View File

@ -71,6 +71,11 @@ suite "quic connection":
await server.handshake.wait()
check newId != ConnectionId.default
asynctest "fires event when closed":
let client = newQuicClientConnection(zeroAddress, zeroAddress)
client.drop()
check client.closed.isSet()
asynctest "raises ConnectionError when closed":
let connection = newQuicClientConnection(zeroAddress, zeroAddress)
connection.drop()