mirror of https://github.com/vacp2p/nim-quic.git
QuicConnection fires event when closed
This commit is contained in:
parent
2161c3b769
commit
b156e2c8f7
|
@ -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] =
|
||||
@[]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue