diff --git a/ChangeLog.md b/ChangeLog.md index 6d1fbfe..08e89c1 100755 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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 diff --git a/src/main/php/peer/Socket.class.php b/src/main/php/peer/Socket.class.php index aae2446..5f17259 100755 --- a/src/main/php/peer/Socket.class.php +++ b/src/main/php/peer/Socket.class.php @@ -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) {