Skip to content

Commit 23e4bc5

Browse files
authored
Remove custom timeout (#21)
* remove time_out, use swoole set * update write_timeout
1 parent 05cff54 commit 23e4bc5

File tree

6 files changed

+6
-11
lines changed

6 files changed

+6
-11
lines changed

docs/en/client.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ An array of client options, you can set the following options:
1616
$config = [
1717
'host' => '127.0.0.1',
1818
'port' => 1883,
19-
'time_out' => 5,
2019
'user_name' => '',
2120
'password' => '',
2221
'client_id' => '',

docs/zh-cn/client.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Simps\MQTT\Client::__construct(array $config, array $swConfig = [], int $type =
1616
$config = [
1717
'host' => '127.0.0.1', // MQTT服务端IP
1818
'port' => 1883, // MQTT服务端端口
19-
'time_out' => 5, // 连接MQTT服务端超时时间,默认0.5秒
2019
'user_name' => '', // 用户名
2120
'password' => '', // 密码
2221
'client_id' => '', // 客户端id

examples/bootstrap.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@
2727
const SWOOLE_MQTT_CONFIG = [
2828
'open_mqtt_protocol' => true,
2929
'package_max_length' => 2 * 1024 * 1024,
30+
'connect_timeout' => 1.0,
31+
'write_timeout' => 5.0,
32+
'read_timeout' => 0.5,
3033
];
3134

3235
function getTestConnectConfig(string $host = '127.0.0.1')
3336
{
3437
return [
3538
'host' => $host,
3639
'port' => 1883,
37-
'time_out' => 5,
3840
'user_name' => 'username',
3941
'password' => 'password',
4042
'client_id' => \Simps\MQTT\Client::genClientID(),
@@ -47,7 +49,6 @@ function getTestMQTT5ConnectConfig(string $host = '127.0.0.1')
4749
return [
4850
'host' => $host,
4951
'port' => 1883,
50-
'time_out' => 5,
5152
'user_name' => 'username',
5253
'password' => 'password',
5354
'client_id' => \Simps\MQTT\Client::genClientID(),

examples/ssl_ca.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
$config = [
1919
'host' => 'test.mosquitto.org',
2020
'port' => 8883,
21-
'time_out' => 5,
2221
'user_name' => '',
2322
'password' => '',
2423
'client_id' => Client::genClientID(),

examples/ssl_ca_client.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
$config = [
1919
'host' => 'test.mosquitto.org',
2020
'port' => 8884,
21-
'time_out' => 5,
2221
'user_name' => '',
2322
'password' => '',
2423
'client_id' => Client::genClientID(),

src/Client.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ class Client
2525
private $config = [
2626
'host' => '127.0.0.1',
2727
'port' => 1883,
28-
'time_out' => 0.5,
29-
'select_time_out' => 0.5,
3028
'user_name' => '',
3129
'password' => '',
3230
'client_id' => '',
@@ -62,7 +60,7 @@ public function __construct(
6260
if (!empty($swConfig)) {
6361
$this->client->set($swConfig);
6462
}
65-
if (!$this->client->connect($this->config['host'], $this->config['port'], $this->config['time_out'])) {
63+
if (!$this->client->connect($this->config['host'], $this->config['port'])) {
6664
$this->reConnect();
6765
}
6866
}
@@ -166,7 +164,7 @@ private function reConnect()
166164
sleep(3);
167165
}
168166
$this->client->close();
169-
$result = $this->client->connect($this->config['host'], $this->config['port'], $this->config['time_out']);
167+
$result = $this->client->connect($this->config['host'], $this->config['port']);
170168
++$reConnectTime;
171169
}
172170
$this->connect((bool) $this->connectData['clean_session'] ?? true, $this->connectData['will'] ?? []);
@@ -221,7 +219,7 @@ protected function getResponse()
221219
} else {
222220
$write = $error = [];
223221
$read = [$this->client];
224-
$n = swoole_client_select($read, $write, $error, $this->config['select_time_out']);
222+
$n = swoole_client_select($read, $write, $error);
225223
if ($n > 0) {
226224
$response = $this->client->recv();
227225
} else {

0 commit comments

Comments
 (0)