コード例 #1
0
 public function ProcessAsync__Handler($mode, &$data, $key, &$info)
 {
     switch ($mode) {
         case "init":
             if ($info["init"]) {
                 $data = $info["keep"];
             } else {
                 $info["result"] = $this->Process($info["url"], $info["profile"], $info["tempoptions"]);
                 if (!$info["result"]["success"]) {
                     $info["keep"] = false;
                     if (is_callable($info["callback"])) {
                         call_user_func_array($info["callback"], array($key, $info["url"], $info["result"]));
                     }
                 } else {
                     $info["state"] = $info["result"]["state"];
                     // Move to the live queue.
                     $data = true;
                 }
             }
             break;
         case "update":
         case "read":
         case "write":
             if ($info["keep"]) {
                 $info["result"] = $this->ProcessState($info["state"]);
                 if ($info["result"]["success"] || $info["result"]["errorcode"] !== "no_data") {
                     $info["keep"] = false;
                 }
                 if (is_callable($info["callback"])) {
                     call_user_func_array($info["callback"], array($key, $info["url"], $info["result"]));
                 }
                 if ($mode === "update") {
                     $data = $info["keep"];
                 }
             }
             break;
         case "readfps":
             if ($info["state"]["httpstate"] !== false && \CubicleSoft\HTTP::WantRead($info["state"]["httpstate"])) {
                 $data[$key] = $info["state"]["httpstate"]["fp"];
             }
             break;
         case "writefps":
             if ($info["state"]["httpstate"] !== false && \CubicleSoft\HTTP::WantWrite($info["state"]["httpstate"])) {
                 $data[$key] = $info["state"]["httpstate"]["fp"];
             }
             break;
         case "cleanup":
             // When true, caller is removing.  Otherwise, detaching from the queue.
             if ($data === true) {
                 if (isset($info["state"])) {
                     if ($info["state"]["httpstate"] !== false) {
                         \CubicleSoft\HTTP::ForceClose($info["state"]["httpstate"]);
                     }
                     unset($info["state"]);
                 }
                 $info["keep"] = false;
             }
             break;
     }
 }
コード例 #2
0
 public function UpdateStreamsAndTimeout($prefix, &$timeout, &$readfps, &$writefps)
 {
     if ($this->fp !== false) {
         $readfps[$prefix . "http_s"] = $this->fp;
     }
     if ($timeout === false || $timeout > $this->defaulttimeout) {
         $timeout = $this->defaulttimeout;
     }
     $ts = microtime(true);
     foreach ($this->initclients as $id => $client) {
         if ($client->mode === "init") {
             $readfps[$prefix . "http_c_" . $id] = $client->fp;
             if ($timeout > 1) {
                 $timeout = 1;
             }
         }
     }
     foreach ($this->clients as $id => $client) {
         if ($client->httpstate !== false) {
             if ($ts < $client->httpstate["waituntil"] && $timeout > $client->httpstate["waituntil"] - $ts + 0.5) {
                 $timeout = (int) ($client->httpstate["waituntil"] - $ts + 0.5);
                 $client->lastts = $ts;
             } else {
                 if (\CubicleSoft\HTTP::WantRead($client->httpstate)) {
                     $readfps[$prefix . "http_c_" . $id] = $client->fp;
                 } else {
                     if ($client->mode !== "init_response" && ($client->writedata !== "" || $client->httpstate["data"] !== "")) {
                         $writefps[$prefix . "http_c_" . $id] = $client->fp;
                     }
                 }
             }
         }
     }
 }