Skip to content

Commit

Permalink
Raise exceptions if fwrite() returns 0
Browse files Browse the repository at this point in the history
Fixes thousands of repeated warning messages being raised, see xp-forge/rest-client#29
  • Loading branch information
thekid committed Sep 26, 2022
1 parent e45481c commit fd372aa
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/php/peer/Socket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,17 +351,19 @@ public function eof() {
* @throws peer.SocketException in case of an error
*/
public function write($str) {
$len= strlen($str);
if (null === $this->_sock) {
throw new SocketException('Write of '.strlen($str).' bytes to socket failed: Socket closed');
throw new SocketException('Write of '.$len.' bytes to socket failed: Socket closed');
}

if (false === ($bytesWritten= fputs($this->_sock, $str, $len= strlen($str)))) {
$w= fwrite($this->_sock, $str, $len);
if (false === $w || 0 === $w) {
$e= new SocketException('Write of '.$len.' bytes to socket failed: '.$this->getLastError());
\xp::gc(__FILE__);
throw $e;
}

return $bytesWritten;
return $w;
}

/**
Expand Down

0 comments on commit fd372aa

Please sign in to comment.