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