Inheritance: extends PHPDaemon\Network\Server
Example #1
0
 /**
  * onRead
  * @return void
  */
 protected function onRead()
 {
     if (!$this->policyReqNotFound) {
         $d = $this->drainIfMatch("<policy-file-request/>");
         if ($d === null) {
             // partially match
             return;
         }
         if ($d) {
             if (($FP = \PHPDaemon\Servers\FlashPolicy\Pool::getInstance($this->pool->config->fpsname->value, false)) && $FP->policyData) {
                 $this->write($FP->policyData . "");
             }
             $this->finish();
             return;
         } else {
             $this->policyReqNotFound = true;
         }
     }
     start:
     if ($this->finished) {
         return;
     }
     if ($this->state === self::STATE_ROOT) {
         if ($this->req !== null) {
             // we have to wait the current request
             return;
         }
         if (!($this->req = $this->newRequest())) {
             $this->finish();
             return;
         }
         $this->state = self::STATE_FIRSTLINE;
     } else {
         if (!$this->req || $this->state === self::STATE_PROCESSING) {
             if (isset($this->bev) && $this->bev->input->length > 0) {
                 Daemon::log('Unexpected input (HTTP request, ' . $this->state . '): ' . json_encode($this->read($this->bev->input->length)));
             }
             return;
         }
     }
     if ($this->state === self::STATE_FIRSTLINE) {
         if (!$this->httpReadFirstline()) {
             return;
         }
         Timer::remove($this->keepaliveTimer);
         $this->state = self::STATE_HEADERS;
     }
     if ($this->state === self::STATE_HEADERS) {
         if (!$this->httpReadHeaders()) {
             return;
         }
         if (!$this->httpProcessHeaders()) {
             $this->finish();
             return;
         }
         $this->state = self::STATE_CONTENT;
     }
     if ($this->state === self::STATE_CONTENT) {
         if (!isset($this->req->attrs->input) || !$this->req->attrs->input) {
             $this->finish();
             return;
         }
         $this->req->attrs->input->readFromBuffer($this->bev->input);
         if (!$this->req->attrs->input->isEOF()) {
             return;
         }
         $this->state = self::STATE_PROCESSING;
         if ($this->freedBeforeProcessing) {
             $this->freeRequest($this->req);
             $this->freedBeforeProcessing = false;
             goto start;
         }
         $this->freezeInput();
         if ($this->req->attrs->inputDone && $this->req->attrs->paramsDone) {
             if ($this->pool->variablesOrder === null) {
                 $this->req->attrs->request = $this->req->attrs->get + $this->req->attrs->post + $this->req->attrs->cookie;
             } else {
                 for ($i = 0, $s = strlen($this->pool->variablesOrder); $i < $s; ++$i) {
                     $char = $this->pool->variablesOrder[$i];
                     if ($char === 'G') {
                         if (is_array($this->req->attrs->get)) {
                             $this->req->attrs->request += $this->req->attrs->get;
                         }
                     } elseif ($char === 'P') {
                         if (is_array($this->req->attrs->post)) {
                             $this->req->attrs->request += $this->req->attrs->post;
                         }
                     } elseif ($char === 'C') {
                         if (is_array($this->req->attrs->cookie)) {
                             $this->req->attrs->request += $this->req->attrs->cookie;
                         }
                     }
                 }
             }
             Daemon::$process->timeLastActivity = time();
         }
     }
 }
Example #2
0
 /**
  * Called when new data received.
  * @return void
  */
 protected function onRead()
 {
     if (!$this->policyReqNotFound) {
         $d = $this->drainIfMatch("<policy-file-request/>");
         if ($d === null) {
             // partially match
             return;
         }
         if ($d) {
             if (($FP = \PHPDaemon\Servers\FlashPolicy\Pool::getInstance($this->pool->config->fpsname->value, false)) && $FP->policyData) {
                 $this->write($FP->policyData . "");
             }
             $this->finish();
             return;
         } else {
             $this->policyReqNotFound = true;
         }
     }
     start:
     if ($this->finished) {
         return;
     }
     if ($this->state === self::STATE_STANDBY) {
         $this->state = self::STATE_FIRSTLINE;
     }
     if ($this->state === self::STATE_FIRSTLINE) {
         if (!$this->httpReadFirstline()) {
             return;
         }
         $this->state = self::STATE_HEADERS;
     }
     if ($this->state === self::STATE_HEADERS) {
         if (!$this->httpReadHeaders()) {
             return;
         }
         if (!$this->httpProcessHeaders()) {
             $this->finish();
             return;
         }
         $this->state = self::STATE_CONTENT;
     }
     if ($this->state === self::STATE_CONTENT) {
         $this->state = self::STATE_PREHANDSHAKE;
     }
     if ($this->state === self::STATE_PREHANDSHAKE) {
         $this->buf .= $this->read(1024);
         if (!$this->handshake()) {
             return;
         }
     }
     if ($this->state === self::STATE_HANDSHAKED) {
         if (!isset($this->protocol)) {
             Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot find session-related websocket protocol for client "' . $this->addr . '"');
             $this->finish();
             return;
         }
         $this->protocol->onRead();
     }
 }
Example #3
0
 /**
  * Called when new data received.
  * @return void
  */
 protected function onRead()
 {
     if (!$this->policyReqNotFound) {
         $d = $this->drainIfMatch("<policy-file-request/>");
         if ($d === null) {
             // partially match
             return;
         }
         if ($d) {
             if (($FP = \PHPDaemon\Servers\FlashPolicy\Pool::getInstance($this->pool->config->fpsname->value, false)) && $FP->policyData) {
                 $this->write($FP->policyData . "");
             }
             $this->finish();
             return;
         } else {
             $this->policyReqNotFound = true;
         }
     }
     start:
     if ($this->finished) {
         return;
     }
     if ($this->state === self::STATE_STANDBY) {
         $this->state = self::STATE_FIRSTLINE;
     }
     if ($this->state === self::STATE_FIRSTLINE) {
         if (!$this->httpReadFirstline()) {
             return;
         }
         $this->state = self::STATE_HEADERS;
     }
     if ($this->state === self::STATE_HEADERS) {
         if (!$this->httpReadHeaders()) {
             return;
         }
         if (!$this->httpProcessHeaders()) {
             $this->finish();
             return;
         }
         $this->state = self::STATE_CONTENT;
     }
     if ($this->state === self::STATE_CONTENT) {
         $this->state = self::STATE_PREHANDSHAKE;
     }
 }