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".} {.push locks: "unknown".}
method enter(state: ClosedConnection, connection: QuicConnection) =
connection.closed.fire()
method ids(state: ClosedConnection): seq[ConnectionId] = method ids(state: ClosedConnection): seq[ConnectionId] =
@[] @[]

View File

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

View File

@ -71,6 +71,11 @@ suite "quic connection":
await server.handshake.wait() await server.handshake.wait()
check newId != ConnectionId.default 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": asynctest "raises ConnectionError when closed":
let connection = newQuicClientConnection(zeroAddress, zeroAddress) let connection = newQuicClientConnection(zeroAddress, zeroAddress)
connection.drop() connection.drop()