stanley-king 4 éve
szülő
commit
285c5b0f0e
1 módosított fájl, 19 hozzáadás és 14 törlés
  1. 19 14
      wsd_bridge.php

+ 19 - 14
wsd_bridge.php

@@ -38,22 +38,27 @@ class WSDBridge
             Log::record("Waitting another connect....");
             if (($client = socket_accept($fd)) !== false)
             {
-                Log::record("Client {$client} has connected", Log::DEBUG);
-                socket_set_option($client, SOL_SOCKET, SO_RCVTIMEO, ['sec' => 8, 'usec' => 0]);
-
-                $body = $this->read_order($client);
-                if (!empty($body)) {
-                    Log::record("req:{$body}", Log::DEBUG);
-                    $resp = $this->relay_request($body);
-                    $resp = mb_convert_encoding($resp, 'GBK', 'UTF-8');
-                    socket_write($client, $resp);
-                    Log::record("resp:{$resp}", Log::DEBUG);
-                } else {
-                    Log::record("不合法的包", Log::DEBUG);
+                try
+                {
+                    Log::record("Client {$client} has connected", Log::DEBUG);
+                    socket_set_option($client, SOL_SOCKET, SO_RCVTIMEO, ['sec' => 8, 'usec' => 0]);
+
+                    $body = $this->read_order($client);
+                    if (!empty($body)) {
+                        Log::record("req:{$body}", Log::DEBUG);
+                        $resp = $this->relay_request($body);
+                        $resp = mb_convert_encoding($resp, 'GBK', 'UTF-8');
+                        socket_write($client, $resp);
+                        Log::record("resp:{$resp}", Log::DEBUG);
+                    } else {
+                        Log::record("不合法的包", Log::DEBUG);
+                    }
+                }
+                catch (Exception $ex) {
+                    Log::record(__FUNCTION__ . " " . $ex->getMessage(),Log::ERR);
                 }
-
-                socket_close($client);
             }
+            socket_close($client);
         }
     }