public function update($time) { if (!$this->isActive and $this->lastUpdate + 10 < $time) { $this->disconnect("超时"); return; } $this->isActive = \false; if (\count($this->ACKQueue) > 0) { $pk = new ACK(); $pk->packets = $this->ACKQueue; $this->sendPacket($pk); $this->ACKQueue = []; } if (\count($this->NACKQueue) > 0) { $pk = new NACK(); $pk->packets = $this->NACKQueue; $this->sendPacket($pk); $this->NACKQueue = []; } if (\count($this->packetToSend) > 0) { $limit = 16; foreach ($this->packetToSend as $k => $pk) { $pk->sendTime = $time; $pk->encode(); $this->recoveryQueue[$pk->seqNumber] = $pk; unset($this->packetToSend[$k]); $this->sendPacket($pk); if (--$limit <= 0) { break; } } if (\count($this->packetToSend) > self::$WINDOW_SIZE) { $this->packetToSend = []; } } if (\count($this->needACK) > 0) { foreach ($this->needACK as $identifierACK => $indexes) { if (\count($indexes) === 0) { unset($this->needACK[$identifierACK]); $this->sessionManager->notifyACK($this, $identifierACK); } } } foreach ($this->recoveryQueue as $seq => $pk) { if ($pk->sendTime < \time() - 8) { $this->packetToSend[] = $pk; unset($this->recoveryQueue[$seq]); } else { break; } } foreach ($this->receivedWindow as $seq => $bool) { if ($seq < $this->windowStart) { unset($this->receivedWindow[$seq]); } else { break; } } $this->sendQueue(); }
public function update($time) { if (!$this->isActive and $this->lastUpdate + 10 < $time) { $this->disconnect("timeout"); return; } $this->isActive = false; if (count($this->ACKQueue) > 0) { $pk = new ACK(); $pk->packets = $this->ACKQueue; $this->sendPacket($pk); $this->ACKQueue = []; } if (count($this->NACKQueue) > 0) { $pk = new NACK(); $pk->packets = $this->NACKQueue; $this->sendPacket($pk); $this->NACKQueue = []; } if (count($this->packetToSend) > 0) { foreach ($this->packetToSend as $k => $pk) { $pk->seqNumber = $this->sendSeqNumber++; $pk->sendTime = microtime(true); $pk->encode(); $this->recoveryQueue[$pk->seqNumber] = $pk; unset($this->packetToSend[$k]); $this->sendPacket($pk); break; } } if (count($this->needACK) > 0) { foreach ($this->needACK as $identifierACK => $indexes) { if (count($indexes) === 0) { unset($this->needACK[$identifierACK]); $this->sessionManager->notifyACK($this, $identifierACK); } } } foreach ($this->receivedWindow as $seq => $bool) { if ($seq < $this->windowStart) { unset($this->receivedWindow[$seq]); } else { break; } } $this->sendQueue(); }