Пример #1
0
 /**
  * Waits for particular PDU (with known command id and sequence no) for some period of time ($to).
  * All unmatched PDUs go to $this->pdu_inc array
  * @access public
  * @param int $cmd Command id
  * @param int $sqn Sequence no
  * @param int $to Timeout (miliseconds)
  * @return mixed PDU on success, FALSE on error
  */
 public function pdu_wait_for($cmd, $sqn = null, $to = 60000)
 {
     if ($this->state != CSS_CONNECTED) {
         return false;
     }
     l('Will wait for ' . $this->translate_cmd($cmd) . ' with sqn no ' . $sqn);
     list($usec, $sec) = explode(' ', microtime());
     $now = $start = $sec + $usec;
     while ($now - $start < $to / 1000) {
         if (false !== ($pdu = $this->pdu_read())) {
             $hdr = $this->sunpack('Nlen/Ncmd/Nstat/Nsqn', substr($pdu, 0, 16));
             l('Got ' . $this->translate_cmd($hdr['cmd']) . ' (' . $hdr['cmd'] . ') with sqn no ' . $hdr['sqn']);
             if ($hdr['cmd'] == $cmd && ($hdr['sqn'] == $sqn || $sqn == null)) {
                 l('Thats it. Returned.');
                 return $pdu;
             } elseif ($hdr['cmd'] == 0x15) {
                 // Got ENQUIRELINK - replying
                 if (!$this->send(NIMF_esme::form_pdu(ENQUIRELINK | ACK, array('sqn' => $hdr['sqn'])))) {
                     l('Could not send ENQUIRELINK_ACK');
                 }
             } else {
                 $this->pdu_inc[] = $pdu;
             }
         } else {
             if ($this->state != CSS_CONNECTED) {
                 l('Disconnection happened.');
                 return false;
             }
         }
         list($usec, $sec) = explode(' ', microtime());
         $now = $sec + $usec;
     }
     l('PDU we were waiting for didn\'t arrive.');
     return false;
 }