Skip to content

Commit 3343e3c

Browse files
committed
Fix timeouts for reading from sockets with newer PHP 8.1 builds
1 parent 12820c7 commit 3343e3c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Networking changelog
55

66
## 10.2.1 / 2021-06-03
77

8+
* Fixed timeouts for reading from sockets with newer PHP 8.1 builds
9+
(@thekid)
810
* Fixed floating point values for `Socket::setTimeout()` - @thekid
911
* Fixed warning *Declaration of AsyncServer::listen($socket, $protocol)
1012
should be compatible* in PHP 7.0, 7.1 and 7.2

src/main/php/peer/Socket.class.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,12 @@ public function readBinary($maxLen= 4096) {
313313

314314
$res= fread($this->_sock, $maxLen);
315315
if (false === $res || null === $res) {
316-
$e= new SocketException('Read of '.$maxLen.' bytes failed: '.$this->getLastError());
316+
$m= stream_get_meta_data($this->_sock);
317+
if ($m['timed_out']) {
318+
$e= new SocketTimeoutException('Read of '.$maxLen.' bytes failed: '.$this->getLastError(), $this->_timeout);
319+
} else {
320+
$e= new SocketException('Read of '.$maxLen.' bytes failed: '.$this->getLastError());
321+
}
317322
\xp::gc(__FILE__);
318323
throw $e;
319324
} else if ('' === $res) {

0 commit comments

Comments
 (0)