diff --git a/php5.3/SocketIO.class.php b/php5.3/SocketIO.class.php index 252bbef..2f5172e 100644 --- a/php5.3/SocketIO.class.php +++ b/php5.3/SocketIO.class.php @@ -75,8 +75,8 @@ 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(); @@ -84,11 +84,12 @@ public function loop(&$stay_in_loop = true) { $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() { @@ -96,16 +97,8 @@ public function getFd() { } 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() { @@ -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; }