Skip to content

Commit

Permalink
Add UDPServer.stop method to close server (#345)
Browse files Browse the repository at this point in the history
Currently, there's no way to stop the RADIUS server when it was started
programmatically without accessing the private UDPServer.server member.

So, add a stop method to the UDPServer which gracefully closes the
server.
  • Loading branch information
glmdev authored Oct 26, 2022
1 parent 32732b7 commit c5bb731
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/server/UDPServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ export class UDPServer extends events.EventEmitter implements IServer {
return startServer.promise;
}

async stop(): Promise<void> {
const stopServer = newDeferredPromise();
this.server.close(() => {
this.logger.log('UDPServer', `radius server closed`);
stopServer.resolve();
});

return stopServer.promise;
}

private setupListeners() {
this.server.on('message', (message, rinfo) => this.emit('message', message, rinfo));
}
Expand Down

0 comments on commit c5bb731

Please sign in to comment.