Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 bugfixes and an improvement #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions php5.3/SocketIO.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,37 +75,30 @@ public function send_json($obj) {
}

public function loop(&$stay_in_loop = true) {
while($stay_in_loop) {
if ($this->stamp < (time()-$this->session[1]-5)) {
do {
if ($this->stamp < (time()-$this->session[1]+5)) {
// heartbeat time
$this->raw_send('2::');
$this->stamp = time();
}

$r = array($this->fd);
$w = null; $e = null;
$n = stream_select($r, $w, $e, 5);
$n = @stream_select($r, $w, $e, 5);
if ($n == 0) continue;

$this->prvHandleData();
}
} while($stay_in_loop);

}

public function getFd() {
return $this->fd;
}

public function handleData() {
if ($this->stamp < (time()-$this->session[1]-5)) {
// heartbeat time
$this->raw_send('2::');
$this->stamp = time();
}
$r = array($this->fd);
$w = null; $e = null;
$n = stream_select($r, $w, $e, 0);
if ($n == 0) continue;
$this->prvHandleData();
$f = false;
$this->loop($f);
}

private function prvHandleData() {
Expand Down Expand Up @@ -167,7 +160,7 @@ protected function raw_read() {
}
if ($pos === false) {
$tmp = fread($this->fd, 4096);
if ($tmp === false) throw new \Exception('Lost connection?');
if ($tmp === false || feof($this->fd)) throw new \Exception('Lost connection?');
$this->buf .= $tmp;
continue;
}
Expand Down