Skip to content

Commit 4c4276f

Browse files
committed
WIP fixed start stop of QUICServer and QUICSocket
1 parent 30baf2b commit 4c4276f

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/QUICServer.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,12 @@ class QUICServer {
5555
*/
5656
public minIdleTimeout?: number;
5757

58-
/**
59-
* Resolves once the connection has closed.
60-
*/
61-
public readonly closedP: Promise<void>;
62-
6358
protected logger: Logger;
6459
protected socket: QUICSocket;
6560
protected crypto: QUICServerCrypto;
6661
protected config: QUICConfig;
6762
protected _closed: boolean = false;
63+
protected _closedP: Promise<void>;
6864
protected resolveClosedP: () => void;
6965

7066
/**
@@ -296,7 +292,7 @@ class QUICServer {
296292
this.codeToReason = codeToReason;
297293
this.minIdleTimeout = minIdleTimeout;
298294
const { p: closedP, resolveP: resolveClosedP } = utils.promise();
299-
this.closedP = closedP;
295+
this._closedP = closedP;
300296
this.resolveClosedP = resolveClosedP;
301297
}
302298

@@ -317,6 +313,10 @@ class QUICServer {
317313
return this._closed;
318314
}
319315

316+
public get closedP(): Promise<void> {
317+
return this._closedP;
318+
}
319+
320320
/**
321321
* Starts the QUICServer.
322322
*
@@ -369,6 +369,7 @@ class QUICServer {
369369
if (!this.isSocketShared) {
370370
this.socket.addEventListener(EventAll.name, this.handleEventQUICSocket);
371371
}
372+
this._closed = false;
372373
this.logger.info(`Started ${this.constructor.name} on ${address}`);
373374
}
374375

@@ -425,7 +426,11 @@ class QUICServer {
425426
this.dispatchEvent(new events.EventQUICServerClose());
426427
}
427428
// Wait for the socket to be closed
428-
await this.closedP;
429+
await this._closedP;
430+
// Resets the `closedP`
431+
const { p: closedP, resolveP: resolveClosedP } = utils.promise();
432+
this._closedP = closedP;
433+
this.resolveClosedP = resolveClosedP;
429434
this.removeEventListener(
430435
events.EventQUICServerError.name,
431436
this.handleEventQUICServerError,

src/QUICSocket.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ class QUICSocket {
2929
*/
3030
public connectionMap: QUICConnectionMap = new QUICConnectionMap();
3131

32-
/**
33-
* Resolves once the connection has closed.
34-
*/
35-
public readonly closedP: Promise<void>;
36-
3732
protected logger: Logger;
3833

3934
/**
@@ -52,6 +47,7 @@ class QUICSocket {
5247
protected _port: Port;
5348
protected _type: 'ipv4' | 'ipv6' | 'ipv4&ipv6';
5449
protected _closed: boolean = false;
50+
protected _closedP: Promise<void>;
5551
protected resolveClosedP: () => void;
5652
protected socket: dgram.Socket;
5753
protected socketBind: (port: number, host: string) => Promise<void>;
@@ -179,7 +175,7 @@ class QUICSocket {
179175
this.logger = logger ?? new Logger(this.constructor.name);
180176
this.resolveHostname = resolveHostname;
181177
const { p: closedP, resolveP: resolveClosedP } = utils.promise();
182-
this.closedP = closedP;
178+
this._closedP = closedP;
183179
this.resolveClosedP = resolveClosedP;
184180
}
185181

@@ -218,6 +214,10 @@ class QUICSocket {
218214
return this._closed;
219215
}
220216

217+
public get closedP(): Promise<void> {
218+
return this._closedP;
219+
}
220+
221221
/**
222222
* Starts this QUICSocket.
223223
* This supports hostnames and IPv4 and IPv6 addresses.
@@ -286,12 +286,10 @@ class QUICSocket {
286286
);
287287
}
288288
this.socket.removeListener('error', rejectErrorP);
289-
290289
// The dgram socket's error events might just be informational
291290
// They don't necessarily correspond to an error
292291
// Therefore we don't bother listening for it
293292
// Unless we were propagating default events upwards
294-
295293
const socketAddress = this.socket.address();
296294
// This is the resolved IP, not the original hostname
297295
this._host = socketAddress.address as Host;
@@ -314,6 +312,7 @@ class QUICSocket {
314312
this.handleEventQUICSocketClose,
315313
{ once: true },
316314
);
315+
this._closed = false;
317316
address = utils.buildAddress(this._host, this._port);
318317
this.logger.info(`Started ${this.constructor.name} on ${address}`);
319318
}
@@ -339,7 +338,11 @@ class QUICSocket {
339338
if (!this._closed) {
340339
this.dispatchEvent(new events.EventQUICSocketClose());
341340
}
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;
343346
this.removeEventListener(
344347
events.EventQUICSocketError.name,
345348
this.handleEventQUICSocketError,

0 commit comments

Comments
 (0)