Skip to content

Commit

Permalink
Fix timeouts for reading from sockets with newer PHP 8.1 builds
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Jun 3, 2021
1 parent 12820c7 commit 3343e3c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Networking changelog

## 10.2.1 / 2021-06-03

* Fixed timeouts for reading from sockets with newer PHP 8.1 builds
(@thekid)
* Fixed floating point values for `Socket::setTimeout()` - @thekid
* Fixed warning *Declaration of AsyncServer::listen($socket, $protocol)
should be compatible* in PHP 7.0, 7.1 and 7.2
Expand Down
7 changes: 6 additions & 1 deletion src/main/php/peer/Socket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,12 @@ public function readBinary($maxLen= 4096) {

$res= fread($this->_sock, $maxLen);
if (false === $res || null === $res) {
$e= new SocketException('Read of '.$maxLen.' bytes failed: '.$this->getLastError());
$m= stream_get_meta_data($this->_sock);
if ($m['timed_out']) {
$e= new SocketTimeoutException('Read of '.$maxLen.' bytes failed: '.$this->getLastError(), $this->_timeout);
} else {
$e= new SocketException('Read of '.$maxLen.' bytes failed: '.$this->getLastError());
}
\xp::gc(__FILE__);
throw $e;
} else if ('' === $res) {
Expand Down

0 comments on commit 3343e3c

Please sign in to comment.