From 67b2382c84c581152c5db55a5da04c1e4e49a45b Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 7 Dec 2018 14:22:47 +1100 Subject: [PATCH] Capture SocketException when server terminated normally. --- app/Console/Commands/Server.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/Server.php b/app/Console/Commands/Server.php index 8810b35..1adee99 100644 --- a/app/Console/Commands/Server.php +++ b/app/Console/Commands/Server.php @@ -8,12 +8,14 @@ namespace App\Console\Commands; -use App\Classes\Frame; use Illuminate\Console\Command; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Support\Facades\Log; use Sock\{SocketClient,SocketServer,SocketException}; +use App\Classes\Frame as FrameClass; +use App\Models\Frame as FrameModel; + class Server extends Command { // Size of Bottom Line Pollution @@ -70,7 +72,16 @@ class Server extends Command $server = new SocketServer(config('app.port'),config('app.bind')); $server->init(); $server->setConnectionHandler([$this,'onConnect']); - $server->listen(); + + try { + $server->listen(); + + } catch (SocketException $e) { + if ($e->getMessage() == 'Can\'t accept connections: "Success"') + Log::debug('Server Terminated.'); + else + Log::emergency('Uncaught Message: '.$e->getMessage()); + } } /** @@ -364,7 +375,7 @@ class Server extends Command $page['frame'] = $pagedata['route1']; $page['index'] = 'a'; - } elseif (\App\Models\Frame::where('frame',$fo->frame())->where('index',$fo->index_next())->exists()) { + } elseif (FrameModel::where('frame',$fo->frame())->where('index',$fo->index_next())->exists()) { $action = ACTION_GOTO; $page['frame'] = array_get($current,'page.frame'); $page['index'] = chr(1 + ord($page['index'])); @@ -402,7 +413,7 @@ class Server extends Command $page['frame'] = $pagedata['route2']; $page['index'] = 'a'; - } elseif (\App\Models\Frame::where('frame',$fo->frame())->where('index',$fo->index_next())->exists()) { + } elseif (FrameModel::where('frame',$fo->frame())->where('index',$fo->index_next())->exists()) { $action = ACTION_GOTO; $page['frame'] = $fo->frame(); $page['index'] = $fo->index_next(); @@ -625,8 +636,8 @@ class Server extends Command try { $fo = $timewarpalt - ? new \App\Classes\Frame(\App\Models\Frame::findOrFail($timewarpalt)) - : (new \App\Models\Frame)->fetch($page['frame'],$page['index']); + ? new FrameClass(FrameModel::findOrFail($timewarpalt)) + : (new FrameModel)->fetch($page['frame'],$page['index']); } catch (ModelNotFoundException $e) { $this->sendBaseline($client,ERR_PAGE);