From b5c62baab7dbd8b615f3cb0f7032315f3ec3d79e Mon Sep 17 00:00:00 2001 From: Md Habibur Rahman <81873266+yourchocomate@users.noreply.github.com> Date: Thu, 14 Mar 2024 14:57:44 +0600 Subject: [PATCH] Fix: Resolved errors and added support for windows platform (#76) --- .../Reverb/Console/Commands/StartServer.php | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Servers/Reverb/Console/Commands/StartServer.php b/src/Servers/Reverb/Console/Commands/StartServer.php index 01ec2c11..864c251f 100644 --- a/src/Servers/Reverb/Console/Commands/StartServer.php +++ b/src/Servers/Reverb/Console/Commands/StartServer.php @@ -147,13 +147,19 @@ protected function ensurePulseEventsAreCollected(LoopInterface $loop, int $inter */ public function getSubscribedSignals(): array { - return [SIGINT, SIGTERM]; + if (! windows_os()) { + return [SIGINT, SIGTERM, SIGTSTP]; + } + + $this->handleSignalWindows(); + + return []; } /** * Handle the signals sent to the server. */ - public function handleSignal(int $signal, int|false $previousExitCode = 0): int|false + public function handleSignal(int $signal = 0, int|false $previousExitCode = 0): int|false { $this->components->info('Gracefully terminating connections.'); @@ -161,4 +167,15 @@ public function handleSignal(int $signal, int|false $previousExitCode = 0): int| return $previousExitCode; } + + /** + * Handle the signals sent to the server on Windows. + */ + + public function handleSignalWindows(): void + { + if(function_exists('sapi_windows_set_ctrl_handler')) { + sapi_windows_set_ctrl_handler(fn () => exit($this->handleSignal())); + } + } }