|
@@ -42,13 +42,16 @@ class WSDBridge
|
|
|
socket_set_option($client, SOL_SOCKET, SO_RCVTIMEO, ['sec' => 8, 'usec' => 0]);
|
|
|
|
|
|
$body = $this->read_order($client);
|
|
|
- if($body !== false && !empty($body)) {
|
|
|
+ if(!empty($body)) {
|
|
|
Log::record("req:{$body}",Log::DEBUG);
|
|
|
$response = $this->relay_request($body);
|
|
|
socket_write($client,$response);
|
|
|
Log::record("resp:{$response}",Log::DEBUG);
|
|
|
}
|
|
|
-
|
|
|
+ else {
|
|
|
+ Log::record("不合法的包",Log::DEBUG);
|
|
|
+ }
|
|
|
+
|
|
|
socket_close($client);
|
|
|
}
|
|
|
}
|
|
@@ -94,31 +97,27 @@ class WSDBridge
|
|
|
private function read_order($client)
|
|
|
{
|
|
|
$content = '';
|
|
|
- while (true)
|
|
|
- {
|
|
|
- $buf = socket_read($client, 1024);
|
|
|
- if ($buf === false) {
|
|
|
- $error = socket_strerror(socket_last_error($client));
|
|
|
- Log::record("read_order err:{$error}", Log::ERR);
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- $content .= $buf;
|
|
|
- }
|
|
|
-
|
|
|
- if ($this->isbody($content)) {
|
|
|
- return $content;
|
|
|
- }
|
|
|
+ $buf = socket_read($client, 1024);
|
|
|
+ if ($buf === false) {
|
|
|
+ $error = socket_strerror(socket_last_error($client));
|
|
|
+ Log::record("read_order err:{$error}", Log::ERR);
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ $content .= $buf;
|
|
|
+ }
|
|
|
|
|
|
- if(strlen($content) > 1024) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ if ($this->isbody($content)) {
|
|
|
+ return $content;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private function isbody($content)
|
|
|
{
|
|
|
$ret = json_decode($content, true);
|
|
|
- return ($ret !== false);
|
|
|
+ return !empty($ret);
|
|
|
}
|
|
|
}
|
|
|
|