When reading from remote with a timeout, return NULL if nothing received

This commit is contained in:
Deon George 2023-08-10 11:08:55 +10:00
parent 60d17ea297
commit 5a62d69913
1 changed files with 3 additions and 3 deletions

View File

@ -284,10 +284,10 @@ final class SocketClient {
* *
* @param int $timeout How long to wait for data * @param int $timeout How long to wait for data
* @param int $len The amount of data we want * @param int $len The amount of data we want
* @return string * @return string|null
* @throws SocketException * @throws SocketException
*/ */
public function read(int $timeout,int $len=1024): string public function read(int $timeout,int $len=1024): ?string
{ {
// We have data in our buffer // We have data in our buffer
if ($this->rx_left >= $len) { if ($this->rx_left >= $len) {
@ -301,7 +301,7 @@ final class SocketClient {
} }
if ($timeout AND ($this->hasData($timeout) === 0)) if ($timeout AND ($this->hasData($timeout) === 0))
return ''; return NULL;
$buf = ''; $buf = '';