/** * Call this to close the connection. * * @return void */ public function close() { $this->_connected = false; $this->_handler->disconnect(); socket_close($this->_socket); $this->_socket = false; }
/** * This will process activity in all peers. Called from process(). * * @return void */ public function processPeers() { // Control peers. if (count($this->_peers) < 1) { return; } $now = $this->getMicrotime(); foreach ($this->_peers as $peerName => $peer) { if (!$peer->hasActivity()) { continue; } $buffer = ''; $len = 1; $len = $peer->read($buffer, $len, true); if ($len > 0) { if ($len >= $this->_readLen) { $this->_handler->handleData($peer); $this->_peersLastDataReceived[$peerName] = $now; } } else { $peer->disconnect(); $this->_freePeer($peer); $this->_handler->disconnect($peer); } } foreach ($this->_peers as $peerName => $peer) { $peerTime = $this->_peersLastDataReceived[$peerName]; if ($now - $peerTime > $this->_rTo) { if ($this->_rTo > 0) { $peer->disconnect(); $this->_freePeer($peer); $this->_handler->readTimeout($peer); } $this->_peersLastDataReceived[$peerName] = $now; } } }