@@ -29,11 +29,6 @@ class QUICSocket {
29
29
*/
30
30
public connectionMap : QUICConnectionMap = new QUICConnectionMap ( ) ;
31
31
32
- /**
33
- * Resolves once the connection has closed.
34
- */
35
- public readonly closedP : Promise < void > ;
36
-
37
32
protected logger : Logger ;
38
33
39
34
/**
@@ -52,6 +47,7 @@ class QUICSocket {
52
47
protected _port : Port ;
53
48
protected _type : 'ipv4' | 'ipv6' | 'ipv4&ipv6' ;
54
49
protected _closed : boolean = false ;
50
+ protected _closedP : Promise < void > ;
55
51
protected resolveClosedP : ( ) => void ;
56
52
protected socket : dgram . Socket ;
57
53
protected socketBind : ( port : number , host : string ) => Promise < void > ;
@@ -179,7 +175,7 @@ class QUICSocket {
179
175
this . logger = logger ?? new Logger ( this . constructor . name ) ;
180
176
this . resolveHostname = resolveHostname ;
181
177
const { p : closedP , resolveP : resolveClosedP } = utils . promise ( ) ;
182
- this . closedP = closedP ;
178
+ this . _closedP = closedP ;
183
179
this . resolveClosedP = resolveClosedP ;
184
180
}
185
181
@@ -218,6 +214,10 @@ class QUICSocket {
218
214
return this . _closed ;
219
215
}
220
216
217
+ public get closedP ( ) : Promise < void > {
218
+ return this . _closedP ;
219
+ }
220
+
221
221
/**
222
222
* Starts this QUICSocket.
223
223
* This supports hostnames and IPv4 and IPv6 addresses.
@@ -286,12 +286,10 @@ class QUICSocket {
286
286
) ;
287
287
}
288
288
this . socket . removeListener ( 'error' , rejectErrorP ) ;
289
-
290
289
// The dgram socket's error events might just be informational
291
290
// They don't necessarily correspond to an error
292
291
// Therefore we don't bother listening for it
293
292
// Unless we were propagating default events upwards
294
-
295
293
const socketAddress = this . socket . address ( ) ;
296
294
// This is the resolved IP, not the original hostname
297
295
this . _host = socketAddress . address as Host ;
@@ -314,6 +312,7 @@ class QUICSocket {
314
312
this . handleEventQUICSocketClose ,
315
313
{ once : true } ,
316
314
) ;
315
+ this . _closed = false ;
317
316
address = utils . buildAddress ( this . _host , this . _port ) ;
318
317
this . logger . info ( `Started ${ this . constructor . name } on ${ address } ` ) ;
319
318
}
@@ -339,7 +338,11 @@ class QUICSocket {
339
338
if ( ! this . _closed ) {
340
339
this . dispatchEvent ( new events . EventQUICSocketClose ( ) ) ;
341
340
}
342
- await this . closedP ;
341
+ await this . _closedP ;
342
+ // Resets the `closedP`
343
+ const { p : closedP , resolveP : resolveClosedP } = utils . promise ( ) ;
344
+ this . _closedP = closedP ;
345
+ this . resolveClosedP = resolveClosedP ;
343
346
this . removeEventListener (
344
347
events . EventQUICSocketError . name ,
345
348
this . handleEventQUICSocketError ,
0 commit comments