Skip to content

Commit 0021340

Browse files
authored
Fix: check for EOF when reading from socket (#215)
Currently, we only check for EOF when reading in blocking mode. The client uses non-blocking reads most of the time though, such that we need to also check for EOF in those cases.
1 parent 8295cea commit 0021340

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/MqttClient.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,14 @@ protected function readFromSocketWithAutoReconnect(int $limit = self::SOCKET_REA
11911191
*/
11921192
protected function readFromSocket(int $limit = self::SOCKET_READ_BUFFER_SIZE, bool $withoutBlocking = false): string
11931193
{
1194+
if (feof($this->socket)) {
1195+
$this->logger->error('The socket has been closed (by the broker) and reached EOF.');
1196+
throw new DataTransferException(
1197+
DataTransferException::EXCEPTION_RX_DATA,
1198+
'The socket has reached EOF which indicates it has been closed by the broker.'
1199+
);
1200+
}
1201+
11941202
if ($withoutBlocking) {
11951203
$result = fread($this->socket, $limit);
11961204

0 commit comments

Comments
 (0)