Example #1
0
 protected function sendPacketOfCurrentProcess(Session $session, Packet $packet)
 {
     $previousReachable = $this->isFdReachable($session->getFd());
     $session->setReachable($previousReachable);
     if (false !== $this->dispatchSend($session, $packet)) {
         // if send buffer is full or other reason, send will failed, so second dispatch packet and tell them session not reachable
         $data = $packet->convertToArray();
         $data[$this->sessionKey] = $session->getSessionId();
         $packetStr = json_encode($data);
         $encodedPacketStr = $this->wsBuffProcessor->encode($packetStr);
         if (!$this->instance->send($session->getFd(), $encodedPacketStr) && $previousReachable) {
             $session->setReachable(false);
             Logger::addInfo('send directly failed, dispatch again (fd:' . $session->getFd() . ') ');
             $this->dispatchSend($session, $packet);
         } else {
             Logger::addInfo('send directly success (fd:' . $session->getFd() . ') |' . $encodedPacketStr . '|' . $packetStr . '|');
         }
     } else {
         Logger::addInfo('send dispatch failed (fd:' . $session->getFd() . ') ');
     }
 }
Example #2
0
 public function isSessionReachable(Session $session)
 {
     /* @var SwooleSession $session */
     return $session && $this->isFdReachable($session->getFd());
 }
Example #3
0
 public function isValidSession(Session $session)
 {
     return null !== $session && $session->getFd() && $session->getUserId() && $session->getSessionId();
 }