Skip to content

Commit

Permalink
Fixed buzy loop (temporary fix for duoshuo#41
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-lb committed Mar 25, 2015
1 parent 701576b commit 48a5a26
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Connection/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function getOptions() {
public function read($length) {
$data = socket_read($this->_socket, $length);

if ($data === false){
if ($data === false || ($length > 0 && $data === '')){
$errorCode = socket_last_error($this->_socket);
throw new SocketException(socket_strerror($errorCode), $errorCode);
}
Expand All @@ -89,7 +89,7 @@ public function read($length) {
while($remainder > 0) {
$readData = socket_read($this->_socket, $remainder);

if ($readData === false){
if ($readData === false || ($length > 0 && $data === '')){
$errorCode = socket_last_error($this->_socket);
throw new SocketException(socket_strerror($errorCode), $errorCode);
}
Expand Down

2 comments on commit 48a5a26

@shen2
Copy link

@shen2 shen2 commented on 48a5a26 Mar 26, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid your fix has another problem.
line:52 should be $readData, not $data. $remainder, not $length

Will socket_last_error($this->_socket) return a error code?

@arnaud-lb
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will socket_last_error($this->_socket) return a error code?

No, in this case socket_last_error() returns 0

Please sign in to comment.