Skip to content

Commit

Permalink
update mqtt
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Sep 9, 2020
1 parent 8c518e8 commit 7bbcdf4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Server/MqttServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function onReceive($server, $fd, $fromId, $data)
} else {
$server->close($fd);
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
$server->close($fd);
}
}
Expand Down
21 changes: 1 addition & 20 deletions src/Server/Protocol/MQTT.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,6 @@ class MQTT

const DISCONNECT = 14; // 客户端到服务端 客户端断开连接

/**
* 检查包长
*
* @param string $buffer
* @return int
*/
public static function input($buffer)
{
$length = strlen($buffer);
$bodyLength = static::getBodyLength($buffer, $headBytes);
$totalLength = $bodyLength + $headBytes;
if ($length < $totalLength) {
return 0;
}

return $totalLength;
}

/**
* 打包Mqtt数据包.
*
Expand Down Expand Up @@ -397,8 +379,7 @@ public static function readString(&$buffer)
$tmp = unpack('n', $buffer);
$length = $tmp[1];
if ($length + 2 > strlen($buffer)) {
// throw new RuntimeException('buffer:' . bin2hex($buffer) . " length:{$length} not enough for unpackString");
return '';
throw new RuntimeException('buffer:' . bin2hex($buffer) . " length:{$length} not enough for unpackString");
}

$string = substr($buffer, 2, $length);
Expand Down

0 comments on commit 7bbcdf4

Please sign in to comment.