当前位置: 首页>>代码示例>>PHP>>正文


PHP binarySubstr函数代码示例

本文整理汇总了PHP中binarySubstr函数的典型用法代码示例。如果您正苦于以下问题:PHP binarySubstr函数的具体用法?PHP binarySubstr怎么用?PHP binarySubstr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了binarySubstr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: touch

 public function touch()
 {
     if (!$this->cursor || $this->cursor->destroyed) {
         $tag = $this;
         $this->appInstance->db->{$this->appInstance->config->dbname->value . '.muchatevents'}->find(function ($cursor) use($tag) {
             $tag->cursor = $cursor;
             foreach ($cursor->items as $k => &$item) {
                 if ($item['type'] === 'kickUsers') {
                     foreach ($tag->sessions as $id => $v) {
                         $sess = $tag->appInstance->sessions[$id];
                         if ($sess->username !== null && $tag->appInstance->compareMask($sess->username, $item['users'])) {
                             $sess->removeTags(array($tag->tag), true);
                             $sess->sysMsg('You were kicked from #' . $tag->tag . '.' . ($item['reason'] !== '' ? ' Reason: ' . $item['reason'] : ''));
                             $sess->send(array('type' => 'youWereKicked', 'reason' => $item['reason']));
                             $tag->appInstance->broadcastEvent(array('type' => 'msg', 'mtype' => 'system', 'text' => ' Kicked: ' . $sess->username . ($item['reason'] !== '' ? ', reason: ' . $item['reason'] : ''), 'color' => 'green', 'tags' => $tag->tag));
                         }
                     }
                 } elseif ($item['type'] === 'forceChangeNick') {
                     foreach ($tag->sessions as $id => $v) {
                         $sess = $tag->appInstance->sessions[$id];
                         if ($sess->username !== null && $sess->username === $item['username']) {
                             $sess->setUsername($item['changeto'], true);
                         }
                     }
                 } else {
                     $item['_id'] = (string) $item['_id'];
                     if (isset($item['sid'])) {
                         $item['sid'] = (string) $item['sid'];
                     }
                     $packet = Session::serialize($item);
                     foreach ($tag->sessions as $id => $v) {
                         $s = $tag->appInstance->sessions[$id];
                         if (is_string($item['tags'])) {
                             $item['tags'] = array($item['tags']);
                         }
                         if (in_array('%private', $item['tags'])) {
                             if (!isset($item['to'])) {
                                 continue;
                             }
                             if (!in_array($s->username, $item['to']) && $s->username != $item['from']) {
                                 continue;
                             }
                         }
                         if ($s->putMsgId($item['_id'])) {
                             $s->client->sendFrame($packet);
                         }
                     }
                 }
                 unset($cursor->items[$k]);
             }
         }, array('tailable' => true, 'sort' => array('$natural' => 1), 'where' => array('ts' => array('$gt' => microtime(true)), 'tags' => array('$in' => binarySubstr($this->tag, 0, 1) == '%' ? array($this->tag) : array($this->tag, '%all')))));
     } elseif (!$this->cursor->session->busy) {
         try {
             $this->cursor->getMore();
         } catch (ConnectionFinished $e) {
             $this->cursor = false;
         }
     }
 }
开发者ID:kakserpom,项目名称:WakePHP,代码行数:59,代码来源:Tag.php

示例2: gets

 public function gets()
 {
     $p = strpos($this->buf, "\n");
     if ($p === FALSE) {
         return FALSE;
     }
     $r = binarySubstr($this->buf, 0, $p + 1);
     $this->buf = binarySubstr($this->buf, $p + 1);
     return $r;
 }
开发者ID:svcorp77,项目名称:phpdaemon,代码行数:10,代码来源:SocketSession.class.php

示例3: gets

 /**
  * Read a first line ended with \n from buffer, removes it from buffer and returns the line
  * @return string Line. Returns false when failed to get a line
  */
 public function gets()
 {
     $p = strpos($this->buf, $this->EOL);
     if ($p === FALSE) {
         return FALSE;
     }
     $sEOL = strlen($this->EOL);
     $r = binarySubstr($this->buf, 0, $p + $sEOL);
     $this->buf = binarySubstr($this->buf, $p + $sEOL);
     return $r;
 }
开发者ID:J3FF3,项目名称:phpdaemon,代码行数:15,代码来源:SocketSession.php

示例4: send

 public function send($packet)
 {
     if (Daemon::$settings['logevents']) {
         Daemon::log(__METHOD__ . ' invoked (' . $this->clientAddr . '): ' . Daemon::var_dump($packet));
     }
     if ($this->http) {
         $s = json_encode($packet);
         $l = strlen($s);
         for ($o = 0; $o < $l;) {
             $c = min(Daemon::$parsedSettings['chunksize'], $l - $o);
             $chunk = dechex($c) . "\r\n" . ($c === $l ? $s : binarySubstr($s, $o, $c)) . "\r\n";
             $this->write($chunk);
             $o += $c;
         }
     } else {
         $this->writeln(json_encode($packet));
     }
 }
开发者ID:svcorp77,项目名称:phpdaemon,代码行数:18,代码来源:RTEP.php

示例5: onFrame


//.........这里部分代码省略.........
             $text = isset($e[1]) ? trim($e[1]) : '';
             if ($m === 'me') {
                 if ($text === '') {
                     $this->sysMsg('/me <message>: insufficient parameters', $packet['tab']);
                 } else {
                     $this->updateSession(array('statusmsg' => $text));
                 }
             } elseif ($m === 'tags') {
                 $tags = trim($text);
                 if ($tags !== '') {
                     $this->setTags(array_map('trim', explode(',', $tags)));
                 }
                 $this->sysMsg('/tags: ' . implode(', ', $this->tags), $packet['tab']);
             } elseif ($m === 'join') {
                 $tags = $text;
                 if ($tags !== '') {
                     $this->addTags(array_map('trim', explode(',', $tags)));
                 } else {
                     $this->sysMsg('/join <tag1>{,<tagN>}: insufficient parameters', $packet['tab']);
                 }
             } elseif ($m === 'part') {
                 $tags = $text;
                 if ($tags !== '') {
                     $this->removeTags(array_map('trim', explode(',', $tags)));
                 } else {
                     $this->sysMsg('/part <tag1>{,<tagN>}: insufficient parameters', $packet['tab']);
                 }
             } elseif ($m === 'nick') {
                 //$this->setUsername($text);
             } elseif ($m === 'thetime') {
                 $this->sysMsg('Current time: ' . date('r'), $packet['tab']);
             } elseif ($m === 'su') {
                 $password = $text;
                 if ($this->su || $password !== '' && $password === $this->appInstance->config->adminpassword->value) {
                     $this->su = true;
                     $this->send(array('type' => 'youAreModerator'));
                     $this->sysMsg('You\'ve got the power.', $packet['tab']);
                 } else {
                     $this->sysMsg('Your powers are weak, old man.', $packet['tab']);
                 }
             } elseif ($m === 'kick') {
                 $e = explode(' ', $text, 3);
                 $users = isset($e[0]) ? trim($e[0]) : '';
                 $tags = isset($e[1]) ? trim($e[1]) : '';
                 $reason = isset($e[2]) ? trim($e[2]) : '';
                 if ($users === '') {
                     $this->sysMsg('/kick <name> [<tags>] [<reason>]: insufficient parameters', $packet['tab']);
                 } else {
                     if (!$this->su) {
                         $this->sysMsg('Your powers are weak, old man.', $packet['tab']);
                     } else {
                         $this->appInstance->kickUsers($users, $tags, $reason);
                     }
                 }
             } elseif ($m === 'fchname') {
                 $e = explode(' ', $text);
                 $name = isset($e[0]) ? trim($e[0]) : '';
                 $newname = isset($e[1]) ? trim($e[1]) : '';
                 if ($name === '' || $newname === '') {
                     $this->sysMsg('/fchname <name> <newname>: insufficient parameters', $packet['tab']);
                 } elseif (!$this->appInstance->validateUsername($newname)) {
                     $this->sysMsg('/fchname: newname>', $packet['tab']);
                 } else {
                     if (!$this->su) {
                         $this->sysMsg('Your powers are weak, old man.', $packet['tab']);
                     } else {
                         $this->appInstance->forceChangeNick($name, $newname);
                     }
                 }
             } else {
                 $this->sysMsg($m . ' Unknown command', $packet['tab']);
             }
         } else {
             $doc = array('mtype' => 'pub', 'tags' => array_intersect($packet['tags'], $this->tags), 'from' => $username, 'text' => $text, 'color' => $color, 'tab' => isset($packet['tab']) ? $packet['tab'] : null);
             if (preg_match_all('~(?<=^|\\s)@([A-Za-z\\-_!0-9\\.\\wА-Яа-я]+)~u', $text, $m)) {
                 $doc['to'] = $m[1];
                 if (sizeof($doc['to']) == 1) {
                     if (binarySubstr($doc['text'], 0, $n = strlen($s = '@' . $doc['to'][0] . ': ')) == $s) {
                         $doc['text'] = binarySubstr($doc['text'], $n);
                     }
                 }
             }
             if (in_array('%private', $packet['tags'])) {
                 $clientId = $this->client->connId;
                 $appInstance = $this->appInstance;
                 $this->appInstance->db->{$this->appInstance->config->dbname->value . '.muchatignore'}->findOne(function ($item) use($clientId, $appInstance, $doc) {
                     if (!$item) {
                         if (!isset($appInstance->sessions[$clientId])) {
                             return;
                         }
                         $session = $appInstance->sessions[$clientId];
                         $session->sendMessage($doc);
                     }
                 }, array('where' => array('username' => $this->username, 'blocked' => $doc['to'][0])));
             } else {
                 $this->sendMessage($doc);
             }
         }
     }
 }
开发者ID:kakserpom,项目名称:WakePHP,代码行数:101,代码来源:Session.php

示例6: bitmap2bytes

 /**
  * Convert bitmap into bytes
  * @param  string  $bitmap    Bitmap
  * @param  integer $check_len Check length?
  * @return string|false
  */
 public static function bitmap2bytes($bitmap, $check_len = 0)
 {
     $r = '';
     $bitmap = str_pad($bitmap, ceil(strlen($bitmap) / 8) * 8, '0', STR_PAD_LEFT);
     for ($i = 0, $n = strlen($bitmap) / 8; $i < $n; ++$i) {
         $r .= chr((int) bindec(binarySubstr($bitmap, $i * 8, 8)));
     }
     if ($check_len && strlen($r) !== $check_len) {
         return false;
     }
     return $r;
 }
开发者ID:cobolbaby,项目名称:phpdaemon,代码行数:18,代码来源:Binary.php

示例7: onRead

 /**
  * Called when new data received
  * @return void
  */
 public function onRead()
 {
     Timer::setTimeout($this->keepaliveTimer);
     while (($line = $this->readline()) !== null) {
         if ($line === '') {
             continue;
         }
         if (strlen($line) > 512) {
             Daemon::$process->log('IRCBouncerConnection error: buffer overflow.');
             $this->finish();
             return;
         }
         $line = binarySubstr($line, 0, -strlen($this->EOL));
         $p = strpos($line, ':', 1);
         $max = $p ? substr_count($line, " ", 0, $p) + 1 : 18;
         $e = explode(" ", $line, $max);
         $i = 0;
         $cmd = $e[$i++];
         $args = [];
         for ($s = min(sizeof($e), 14); $i < $s; ++$i) {
             if ($e[$i][0] === ':') {
                 $args[] = binarySubstr($e[$i], 1);
                 break;
             }
             $args[] = $e[$i];
         }
         if (ctype_digit($cmd)) {
             $code = (int) $cmd;
             $cmd = isset(IRC::$codes[$code]) ? IRC::$codes[$code] : 'UNKNOWN-' . $code;
         }
         $this->onCommand($cmd, $args);
     }
     if (strlen($this->buf) > 512) {
         Daemon::$process->log('IRCClientConnection error: buffer overflow.');
         $this->finish();
     }
 }
开发者ID:shamahan,项目名称:phpdaemon,代码行数:41,代码来源:Connection.php

示例8: stdin

 public function stdin($buf)
 {
     $this->buf .= $buf;
     if (!$this->handshaked) {
         if (strpos($this->buf, '<policy-file-request/>') !== FALSE) {
             if (($FP = Daemon::$appResolver->getInstanceByAppName('FlashPolicy')) && $FP->policyData) {
                 $this->write($FP->policyData . "");
             }
             $this->finish();
             return;
         }
         $i = 0;
         while (($l = $this->gets()) !== FALSE) {
             if ($i++ > 100) {
                 break;
             }
             if ($l === "\r\n") {
                 if (!isset($this->server['HTTP_CONNECTION']) || $this->server['HTTP_CONNECTION'] !== 'Upgrade' || !isset($this->server['HTTP_UPGRADE']) || $this->server['HTTP_UPGRADE'] !== 'WebSocket') {
                     $this->finish();
                     return;
                 }
                 if (!($this->secprotocol = isset($this->server['HTTP_SEC_WEBSOCKET_KEY1']) && isset($this->server['HTTP_SEC_WEBSOCKET_KEY2']))) {
                     $this->handshake();
                 }
                 break;
             }
             if (!$this->firstline) {
                 $this->firstline = TRUE;
                 $e = explode(' ', $l);
                 $u = parse_url(isset($e[1]) ? $e[1] : '');
                 $this->server['REQUEST_METHOD'] = $e[0];
                 $this->server['REQUEST_URI'] = $u['path'] . (isset($u['query']) ? '?' . $u['query'] : '');
                 $this->server['DOCUMENT_URI'] = $u['path'];
                 $this->server['PHP_SELF'] = $u['path'];
                 $this->server['QUERY_STRING'] = isset($u['query']) ? $u['query'] : NULL;
                 $this->server['SCRIPT_NAME'] = $this->server['DOCUMENT_URI'] = isset($u['path']) ? $u['path'] : '/';
                 $this->server['SERVER_PROTOCOL'] = isset($e[2]) ? $e[2] : '';
                 list($this->server['REMOTE_ADDR'], $this->server['REMOTE_PORT']) = explode(':', $this->clientAddr);
             } else {
                 $e = explode(': ', $l);
                 if (isset($e[1])) {
                     $this->server['HTTP_' . strtoupper(strtr($e[0], Request::$htr))] = rtrim($e[1], "\r\n");
                 }
             }
         }
     }
     if ($this->handshaked) {
         while (($buflen = strlen($this->buf)) >= 2) {
             $frametype = ord(binarySubstr($this->buf, 0, 1));
             if (($frametype & 0x80) === 0x80) {
                 $len = 0;
                 $i = 0;
                 do {
                     $b = ord(binarySubstr($this->buf, ++$i, 1));
                     $n = $b & 0x7f;
                     $len *= 0x80;
                     $len += $n;
                 } while ($b > 0x80);
                 if (Daemon::$parsedSettings['mod' . $this->appInstance->modname . 'maxallowedpacket'] <= $len) {
                     $this->finish();
                     return;
                 }
                 if ($buflen < $len + 2) {
                     return;
                 }
                 // not enough data yet
                 $data = binarySubstr($this->buf, 2, $len);
                 $this->buf = binarySubstr($this->buf, 2 + $len);
                 $this->onFrame($data, $frametype);
             } else {
                 if (($p = strpos($this->buf, "ÿ")) !== FALSE) {
                     if (Daemon::$parsedSettings['mod' . $this->appInstance->modname . 'maxallowedpacket'] <= $p - 1) {
                         $this->finish();
                         return;
                     }
                     $data = binarySubstr($this->buf, 1, $p - 1);
                     $this->buf = binarySubstr($this->buf, $p + 1);
                     $this->onFrame($data, $frametype);
                 } else {
                     if (Daemon::$parsedSettings['mod' . $this->appInstance->modname . 'maxallowedpacket'] <= strlen($this->buf)) {
                         $this->finish();
                     }
                     return;
                 }
             }
         }
     } elseif ($this->secprotocol) {
         if (strlen($this->buf) >= 8) {
             $bodyData = binarySubstr($this->buf, 0, 8);
             $this->resultKey = md5($this->computeKey($this->server['HTTP_SEC_WEBSOCKET_KEY1']) . $this->computeKey($this->server['HTTP_SEC_WEBSOCKET_KEY2']) . $bodyData, TRUE);
             $this->buf = binarySubstr($this->buf, 8);
             $this->handshake();
         }
     }
 }
开发者ID:svcorp77,项目名称:phpdaemon,代码行数:95,代码来源:WebSocketServer.php

示例9: onRead

 public function onRead()
 {
     while ($this->connection && ($buflen = strlen($this->connection->buf)) >= 1) {
         $frametype = ord(binarySubstr($this->connection->buf, 0, 1));
         if (($frametype & 0x80) === 0x80) {
             $len = 0;
             $i = 0;
             do {
                 $b = ord(binarySubstr($this->connection->buf, ++$i, 1));
                 $n = $b & 0x7f;
                 $len *= 0x80;
                 $len += $n;
             } while ($b > 0x80);
             if ($this->connection->pool->maxAllowedPacket <= $len) {
                 // Too big packet
                 $this->connection->finish();
                 return FALSE;
             }
             if ($buflen < $len + 2) {
                 // not enough data yet
                 return FALSE;
             }
             $decodedData = binarySubstr($this->connection->buf, 2, $len);
             $this->connection->buf = binarySubstr($this->connection->buf, 2 + $len);
             $this->connection->onFrame($decodedData, 'BINARY');
         } else {
             if (($p = strpos($this->connection->buf, "ÿ")) !== FALSE) {
                 if ($this->connection->pool->maxAllowedPacket <= $p - 1) {
                     // Too big packet
                     $this->connection->finish();
                     return FALSE;
                 }
                 $decodedData = binarySubstr($this->connection->buf, 1, $p - 1);
                 $this->connection->buf = binarySubstr($this->connection->buf, $p + 1);
                 $this->connection->onFrame($decodedData, 'STRING');
             } else {
                 if ($this->connection->pool->maxAllowedPacket <= $buflen - 1) {
                     // Too big packet
                     $this->connection->finish();
                     return FALSE;
                 }
                 // not enough data yet
                 return;
             }
         }
     }
 }
开发者ID:ruslanchek,项目名称:phpdaemon,代码行数:47,代码来源:WebSocketProtocolV0.php

示例10: requestOut

 /**
  * Handles the output from downstream requests.
  * @param object Request.
  * @param string The output.
  * @return void
  */
 public function requestOut($req, $output)
 {
     $outlen = strlen($output);
     /* 
      * Iterate over every character in the string, 
      * escaping with a slash or encoding to UTF-8 where necessary 
      */
     // string bytes counter
     $d = 0;
     for ($c = 0; $c < $outlen; ++$c) {
         $ord_var_c = ord($output[$d]);
         switch (true) {
             case $ord_var_c >= 0x20 && $ord_var_c <= 0x7f:
                 // characters U-00000000 - U-0000007F (same as ASCII)
                 $d++;
                 break;
             case ($ord_var_c & 0xe0) == 0xc0:
                 // characters U-00000080 - U-000007FF, mask 110XXXXX
                 // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                 $d += 2;
                 break;
             case ($ord_var_c & 0xf0) == 0xe0:
                 // characters U-00000800 - U-0000FFFF, mask 1110XXXX
                 // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                 $d += 3;
                 break;
             case ($ord_var_c & 0xf8) == 0xf0:
                 // characters U-00010000 - U-001FFFFF, mask 11110XXX
                 // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                 $d += 4;
                 break;
             case ($ord_var_c & 0xfc) == 0xf8:
                 // characters U-00200000 - U-03FFFFFF, mask 111110XX
                 // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                 $d += 5;
                 break;
             case ($ord_var_c & 0xfe) == 0xfc:
                 // characters U-04000000 - U-7FFFFFFF, mask 1111110X
                 // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                 $d += 6;
                 break;
             default:
                 $d++;
         }
     }
     for ($o = 0; $o < $d;) {
         $c = min($this->pool->config->chunksize->value, $d - $o);
         $w = $this->write("" . "" . pack('nn', $req->attrs->id, $c) . "" . "" . ($c === $d ? $output : binarySubstr($output, $o, $c)));
         if ($w === false) {
             $req->abort();
             return false;
         }
         $o += $c;
     }
     return true;
 }
开发者ID:ruslanchek,项目名称:phpdaemon,代码行数:62,代码来源:FastCGIServerConnection.php

示例11: onRead

 /**
  * Called when new data received
  * @return void
  */
 public function onRead()
 {
     while (($line = $this->readline()) !== null) {
         if ($line === '') {
             continue;
         }
         if (strlen($line) > 512) {
             Daemon::$process->log('IRCClientConnection error: buffer overflow.');
             $this->finish();
             return;
         }
         $line = binarySubstr($line, 0, -strlen($this->EOL));
         $p = strpos($line, ' :', 1);
         $max = $p !== false ? substr_count($line, " ", 0, $p + 1) + 1 : 18;
         $e = explode(" ", $line, $max);
         $i = 0;
         $from = IRC::parseUsermask($e[$i][0] === ':' ? binarySubstr($e[$i++], 1) : null);
         $cmd = $e[$i++];
         $args = [];
         for ($s = min(sizeof($e), 14); $i < $s; ++$i) {
             if ($e[$i][0] === ':') {
                 $args[] = binarySubstr($e[$i], 1);
                 break;
             }
             $args[] = $e[$i];
         }
         if (ctype_digit($cmd)) {
             $code = (int) $cmd;
             $cmd = isset(IRC::$codes[$code]) ? IRC::$codes[$code] : $code;
         }
         $this->lastLine = $line;
         $this->onCommand($from, $cmd, $args);
     }
     if (strlen($this->buf) > 512) {
         Daemon::$process->log('IRCClientConnection error: buffer overflow.');
         $this->finish();
     }
 }
开发者ID:zenus,项目名称:phpinx,代码行数:42,代码来源:Connection.php

示例12: stdin

 /**
  * Called when new data received
  * @param string New data
  * @return void
  */
 public function stdin($buf)
 {
     if ($this->state === self::STATE_BODY) {
         goto body;
     }
     $this->buf .= $buf;
     $buf = '';
     while (($line = $this->gets()) !== FALSE) {
         if ($line === $this->EOL) {
             if (isset($this->headers['HTTP_CONTENT_LENGTH'])) {
                 $this->contentLength = (int) $this->headers['HTTP_CONTENT_LENGTH'];
             } else {
                 $this->contentLength = -1;
             }
             if (isset($this->headers['HTTP_TRANSFER_ENCODING'])) {
                 $e = explode(', ', strtolower($this->headers['HTTP_TRANSFER_ENCODING']));
                 $this->chunked = in_array('chunked', $e, true);
             } else {
                 $this->chunked = false;
             }
             if (isset($this->headers['HTTP_CONNECTION'])) {
                 $e = explode(', ', strtolower($this->headers['HTTP_CONNECTION']));
                 $this->keepalive = in_array('keep-alive', $e, true);
             }
             if (!$this->chunked) {
                 $this->body .= $this->buf;
                 $this->buf = '';
             }
             $this->state = self::STATE_BODY;
             break;
         }
         if ($this->state === self::STATE_ROOT) {
             $this->headers['STATUS'] = rtrim($line);
             $this->state = self::STATE_HEADERS;
         } elseif ($this->state === self::STATE_HEADERS) {
             $e = explode(': ', rtrim($line));
             if (isset($e[1])) {
                 $this->headers['HTTP_' . strtoupper(strtr($e[0], HTTPRequest::$htr))] = $e[1];
             }
         }
     }
     if ($this->state !== self::STATE_BODY) {
         return;
         // not enough data yet
     }
     body:
     if ($this->chunked) {
         $this->buf .= $buf;
         chunk:
         if ($this->curChunkSize === null) {
             // outside of chunk
             $l = $this->gets();
             if ($l === $this->EOL) {
                 // skip empty line
                 goto chunk;
             }
             if ($l === false) {
                 return;
                 // not enough data yet
             }
             $l = rtrim($l);
             if (!ctype_xdigit($l)) {
                 $this->protocolError = __LINE__;
                 $this->finish();
                 // protocol error
                 return;
             }
             $this->curChunkSize = hexdec($l);
         }
         if ($this->curChunkSize !== null) {
             if ($this->curChunkSize === 0) {
                 if ($this->gets() === $this->EOL) {
                     $this->requestFinished();
                     return;
                 } else {
                     // protocol error
                     $this->protocolError = __LINE__;
                     $this->finish();
                     return;
                 }
             }
             $len = strlen($this->buf);
             $n = $this->curChunkSize - strlen($this->curChunk);
             if ($n >= $len) {
                 $this->curChunk .= $this->buf;
                 $this->buf = '';
             } else {
                 $this->curChunk .= binarySubstr($this->buf, 0, $n);
                 $this->buf = binarySubstr($this->buf, $n);
             }
             if ($this->curChunkSize <= strlen($this->curChunk)) {
                 $this->body .= $this->curChunk;
                 $this->curChunkSize = null;
                 $this->curChunk = '';
                 goto chunk;
//.........这里部分代码省略.........
开发者ID:ruslanchek,项目名称:phpdaemon,代码行数:101,代码来源:HTTPClient.php

示例13: requestOut

 /**
  * Handles the output from downstream requests
  * @param  object  $req Request
  * @param  string  $out The output
  * @return boolean      Success
  */
 public function requestOut($req, $out)
 {
     $cs = $this->pool->config->chunksize->value;
     if (strlen($out) > $cs) {
         while (($ol = strlen($out)) > 0) {
             $l = min($cs, $ol);
             if ($this->sendChunk($req, binarySubstr($out, 0, $l)) === false) {
                 $req->abort();
                 return false;
             }
             $out = binarySubstr($out, $l);
         }
     } elseif ($this->sendChunk($req, $out) === false) {
         $req->abort();
         return false;
     }
     return true;
 }
开发者ID:cobolbaby,项目名称:phpdaemon,代码行数:24,代码来源:Connection.php

示例14: write

 /**
  * Write to shared memory
  * @param  string  $data   Data
  * @param  integer $offset Offset
  * @return boolean         Success
  */
 public function write($data, $offset)
 {
     $segno = floor($offset / $this->segsize);
     if (!isset($this->segments[$segno])) {
         if (!$this->open($segno, true)) {
             return false;
         }
     }
     $sOffset = $offset % $this->segsize;
     $d = $this->segsize - ($sOffset + strlen($data));
     if ($d < 0) {
         $this->write(binarySubstr($data, $d), ($segno + 1) * $this->segsize);
         $data = binarySubstr($data, 0, $d);
     }
     //Daemon::log('writing to #'.$offset.' (segno '.$segno.')');
     shmop_write($this->segments[$segno], $data, $sOffset);
     return true;
 }
开发者ID:cobolbaby,项目名称:phpdaemon,代码行数:24,代码来源:ShmEntity.php

示例15: onRead

 /**
  * Data decoding, according to related IETF draft
  * 
  * @see http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10#page-16
  */
 public function onRead()
 {
     $data = '';
     while ($this->connection && ($buflen = strlen($this->connection->buf)) >= 1) {
         $p = 0;
         // offset
         $first = ord(binarySubstr($this->connection->buf, $p++, 1));
         // first byte integer (fin, opcode)
         $firstBits = decbin($first);
         $rsv1 = (bool) $firstBits[1];
         $rsv2 = (bool) $firstBits[2];
         $rsv3 = (bool) $firstBits[3];
         $opcode = (int) bindec(substr($firstBits, 4, 4));
         if ($opcode === 0x8) {
             // CLOSE
             $this->connection->finish();
             return;
         }
         $opcodeName = $this->opcodes[$opcode];
         $second = ord(binarySubstr($this->connection->buf, $p++, 1));
         // second byte integer (masked, payload length)
         $fin = (bool) ($first >> 7);
         $isMasked = (bool) ($second >> 7);
         $dataLength = $second & 0x7f;
         if ($dataLength === 0x7e) {
             // 2 bytes-length
             if ($buflen < $p + 2) {
                 return;
                 // not enough data yet
             }
             $dataLength = $this->bytes2int(binarySubstr($this->connection->buf, $p, 2), false);
             $p += 2;
         } elseif ($dataLength === 0x7f) {
             // 4 bytes-length
             if ($buflen < $p + 4) {
                 return;
                 // not enough data yet
             }
             $dataLength = $this->bytes2int(binarySubstr($this->connection->buf, $p, 4));
             $p += 4;
         }
         if ($this->connection->pool->maxAllowedPacket <= $dataLength) {
             // Too big packet
             $this->connection->finish();
             return;
         }
         if ($isMasked) {
             if ($buflen < $p + 4) {
                 return;
                 // not enough data yet
             }
             $mask = binarySubstr($this->connection->buf, $p, 4);
             $p += 4;
         }
         if ($buflen < $p + $dataLength) {
             return;
             // not enough data yet
         }
         $data = binarySubstr($this->connection->buf, $p, $dataLength);
         $p += $dataLength;
         if ($isMasked) {
             $data = $this->mask($data, $mask);
         }
         $this->connection->buf = binarySubstr($this->connection->buf, $p);
         //Daemon::log(Debug::dump(array('ext' => $this->connection->extensions, 'rsv1' => $rsv1, 'data' => Debug::exportBytes($data))));
         if ($rsv1 && in_array('deflate-frame', $this->connection->extensions)) {
             // deflate frame
             $data = gzuncompress($data, $this->connection->pool->maxAllowedPacket);
         }
         if (!$fin) {
             $this->connection->framebuf .= $data;
         } else {
             $this->connection->onFrame($this->connection->framebuf . $data, $opcodeName);
             if ($this->connection) {
                 $this->connection->framebuf = '';
             }
         }
     }
 }
开发者ID:ruslanchek,项目名称:phpdaemon,代码行数:84,代码来源:WebSocketProtocolV13.php


注:本文中的binarySubstr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。