public function flush() { if (\hacklib_cast_as_boolean($this->randomize_)) { shuffle($this->servers_); } foreach ($this->servers_ as $server) { $this->host_ = $server[0]; $this->port_ = $server[1]; $j = $this->numTries_; while ($j > 0) { try { parent::flush(); return; } catch (TTransportException $e) { if (\hacklib_cast_as_boolean($this->debug_)) { call_user_func($this->debugHandler_, $e->getMessage()); } --$j; } } } $this->host_ = ""; $this->port_ = 0; $error = "THttpClientPool: Could not connect to any of the servers " . "in the pool"; throw new TTransportException($error, TTransportException::NOT_OPEN); }
public function __construct($input, $output = null) { $this->input_ = $input; $this->output_ = \hacklib_cast_as_boolean($output) ?: $input; $this->asyncHandler_ = new TClientAsyncHandler(); $this->eventHandler_ = new TClientEventHandler(); }
public function rewind() { $this->key = !\hacklib_cast_as_boolean($this->key); if (!\hacklib_cast_as_boolean($this->key)) { $this->itr->rewind(); } }
function test_all_expression_types() { $v = new \HH\Vector(array()); $f = new Foo(); test_cast("clone", (bool) \hacklib_cast_as_boolean(clone $v)); test_cast("obj_get", (bool) \hacklib_cast_as_boolean($f->prop)); test_cast("array_get", (bool) \hacklib_cast_as_boolean(array($v)[0])); test_cast("class_get", (bool) \hacklib_cast_as_boolean(Foo::$s_prop)); test_cast("cast", (bool) \hacklib_cast_as_boolean((object) $v)); test_cast("cast", (bool) (array) \hacklib_cast_as_array($v)); for ($v_in = new \HH\Vector(array(1)), $i = 1; $i > 0, \hacklib_cast_as_boolean($v_in); $i++, $v_in->pop()) { echo "in here at " . $i . "\n"; if ($i > 5) { break; } } test_cast("Eif", (bool) \hacklib_cast_as_boolean(true ? $v : $f)); test_cast("unsafe_expr", (bool) \hacklib_cast_as_boolean($v)); test_cast("call", (bool) \hacklib_cast_as_boolean(Foo::s_func())); test_cast("Collection", (bool) (!\hacklib_id(new \HH\Vector(array()))->isEmpty())); test_cast("New", (bool) new Foo()); test_cast("New", (bool) (!\hacklib_id(new \HH\Vector(array()))->isEmpty())); test_cast("Eq", (bool) ($y = false)); test_cast("Eq", (bool) \hacklib_cast_as_boolean($z = $f->i_func())); echo $z . "\n"; }
public function close() { if (\hacklib_cast_as_boolean(isset($this->handle))) { fclose($this->handle); $this->handle = null; } }
function verify_set($s) { echo \hacklib_cast_as_boolean($s->isEmpty()) ? "empty\n" : "not empty\n"; echo $s->count() . "\n"; echo \hacklib_cast_as_boolean($s->contains("25")) ? "contains 25\n" : "does not contain 25\n"; echo \hacklib_cast_as_boolean($s->contains("truman")) ? "contains truman\n" : "does not contain truman\n"; echo \hacklib_cast_as_boolean(isset($s[\hacklib_id("25")])) ? "contains 25\n" : "does not contain 25\n"; echo gettype($s[\hacklib_id("25")]) . "\n"; echo gettype($s[\hacklib_id('25')]) . "\n"; echo gettype($s[25]) . "\n"; try { $s[\hacklib_id("truman")]; echo "should not see this"; } catch (OutOfBoundsException $e) { echo $e->getMessage() . "\n"; } foreach ($s as $i => $val) { $out = var_export($val, true); $t = gettype($i); echo "({$t}) {$i} : {$out}\n"; } $i = $s->getIterator(); $i->next(); $i->next(); $i->next(); $i->next(); try { $i->current(); echo "should not see this"; } catch (InvalidOperationException $e) { echo $e->getMessage() . "\n"; } }
function boolean_statements($c) { if (\hacklib_cast_as_boolean($c)) { echo "If Then"; } else { echo "If Else"; } $i = 0; do { $i++; if ($i > 3) { break; } } while (\hacklib_cast_as_boolean($c)); echo "Do Loop Iterations : {$i}\n"; $i = 0; while (\hacklib_cast_as_boolean($c)) { $i++; if ($i > 3) { break; } } echo "While loop Iterations : {$i}\n"; $i = 0; for (; \hacklib_cast_as_boolean($c); $i++) { if ($i > 3) { break; } } echo "For Loop iterations : {$i}\n"; }
public function process() { $client = $this->serverTransport->accept(0); if (\hacklib_cast_as_boolean($client)) { $this->clients[$this->clientIdx++] = $client; } $this->processExistingClients(); }
public function readContextOver() { $pos = $this->skipWhitespace(false); $c = $this->bufTrans->peek(1, $pos); if (!\hacklib_cast_as_boolean($this->first) && $c !== "," && $c !== "]") { throw new TProtocolException("TSimpleJSONProtocol: Expected \",\" or \"]\", encountered 0x" . bin2hex($c)); } return $c === "]"; }
public function open() { try { parent::open(); } catch (Exception $e) { $op_in_progress = strpos($e->getMessage(), "socket_connect error") !== false && strpos($e->getMessage(), "[115]") !== false; if (!\hacklib_cast_as_boolean($op_in_progress)) { throw $e; } } }
public function foo() { $x = 1 + 2 * (3 - 2 / 5); $y = -++$x % +10; $x -= $y++; $y /= --$z; $b = "hi" . " hello"; $c .= "hey there"; $n = $x-- | $y & ($z ^ ~$x >> 2) << 3; $yes = ((bool) \hacklib_cast_as_boolean($x) && $x > $y || !($x >= $z)) ^ $z < $y || $z <= $x; $maybe = \hacklib_equals($x, $y) && $x === $y && \hacklib_not_equals($z, $x) && $z !== $y; }
public static function deserialize($str, $object, $disable_hphp_extension = false) { $transport = new TMemoryBuffer(); $protocol = new TBinaryProtocolAccelerated($transport); if (\hacklib_cast_as_boolean(function_exists('thrift_protocol_read_binary')) && !\hacklib_cast_as_boolean($disable_hphp_extension)) { $protocol->writeMessageBegin('', TMessageType::REPLY, 0); $transport->write($str); $object = thrift_protocol_read_binary($protocol, get_class($object), $protocol->isStrictRead()); } else { $transport->write($str); $object->read($protocol); } return $object; }
public function write($output) { $xfer = 0; $xfer += $output->writeStructBegin('TApplicationException'); if (\hacklib_cast_as_boolean($message = $this->getMessage())) { $xfer += $output->writeFieldBegin('message', TType::STRING, 1); $xfer += $output->writeString($message); $xfer += $output->writeFieldEnd(); } if (\hacklib_cast_as_boolean($code = $this->getCode())) { $xfer += $output->writeFieldBegin('type', TType::I32, 2); $xfer += $output->writeI32($code); $xfer += $output->writeFieldEnd(); } $xfer += $output->writeFieldStop(); $xfer += $output->writeStructEnd(); return $xfer; }
public static function deserialize($str, $object, $override_version = null, $disable_hphp_extension = false) { $transport = new TMemoryBuffer(); $protocol = new TCompactProtocolAccelerated($transport); $use_hphp_extension = \hacklib_cast_as_boolean(function_exists('thrift_protocol_read_compact')) && !\hacklib_cast_as_boolean($disable_hphp_extension); if ($override_version !== null) { $protocol->setWriteVersion($override_version); if (!\hacklib_cast_as_boolean(function_exists('thrift_protocol_set_compact_version'))) { $use_hphp_extension = false; } } if (\hacklib_cast_as_boolean($use_hphp_extension)) { $protocol->writeMessageBegin('', TMessageType::REPLY, 0); $transport->write($str); $object = thrift_protocol_read_compact($protocol, get_class($object)); } else { $transport->write($str); $object->read($protocol); } return $object; }
function verify_map($m) { echo \hacklib_cast_as_boolean($m->isEmpty()) ? "empty\n" : "not empty\n"; echo $m->count() . "\n"; echo $m->at("25") . "\n"; echo $m[\hacklib_id("25")] . "\n"; echo $m->get("25") . "\n"; try { $m->at(25); echo "should not see this"; } catch (OutOfBoundsException $e) { echo $e->getMessage() . "\n"; } try { $m[25]; echo "should not see this"; } catch (OutOfBoundsException $e) { echo $e->getMessage() . "\n"; } echo var_export($m->get(25), true) . "\n"; echo \hacklib_cast_as_boolean(isset($m[\hacklib_id("25")])) ? "is set\n" : "not set\n"; echo \hacklib_cast_as_boolean($m->containsKey("25")) ? "contains Key\n" : "does not contain Key\n"; echo \hacklib_cast_as_boolean($m->containsKey(25)) ? "contains Key\n" : "does not contain Key\n"; foreach ($m as $i => $mal) { $out = var_export($mal, true); $t = gettype($i); echo "({$t}) {$i} : {$out}\n"; } $i = $m->getIterator(); $i->next(); $i->next(); $i->next(); $i->next(); try { $i->current(); echo "should not see this"; } catch (InvalidOperationException $e) { echo $e->getMessage() . "\n"; } }
function verify_pair($p) { echo \hacklib_cast_as_boolean($p->isEmpty()) ? "empty\n" : "not empty\n"; echo $p->count() . "\n"; echo $p->at(1) . "\n"; echo $p[1] . "\n"; echo $p->get(1) . "\n"; try { $p->at(10); echo "should not see this"; } catch (OutOfBoundsException $e) { echo $e->getMessage() . "\n"; } try { $p[10]; echo "should not see this"; } catch (OutOfBoundsException $e) { echo $e->getMessage() . "\n"; } echo var_export($p->get(10), true) . "\n"; echo \hacklib_cast_as_boolean(isset($p[3])) ? "is set\n" : "not set\n"; echo \hacklib_cast_as_boolean($p->containsKey(2)) ? "contains Key\n" : "does not contain Key\n"; echo \hacklib_cast_as_boolean($p->containsKey(20)) ? "contains Key\n" : "does not contain Key\n"; foreach ($p as $i => $val) { $out = var_export($val, true); echo "{$i} : {$out}\n"; } $i = $p->getIterator(); $i->next(); $i->next(); $i->next(); $i->next(); try { $i->current(); echo "should not see this"; } catch (InvalidOperationException $e) { echo $e->getMessage() . "\n"; } }
protected function skipWhitespace($skip = true) { $count = 0; $reading = true; while (\hacklib_cast_as_boolean($reading)) { $byte = $this->bufTrans->peek(1, $count); switch ($byte) { case " ": case "\t": case "\n": case "\r": $count++; break; default: $reading = false; break; } } if (\hacklib_cast_as_boolean($skip)) { $this->trans->readAll($count); } return $count; }
private function flushImpl($oneway) { if (\hacklib_equals(strlen($this->wBuf_), 0)) { if (\hacklib_cast_as_boolean($oneway)) { $this->transport_->onewayFlush(); } else { $this->transport_->flush(); } return; } $out = $this->transform($this->wBuf_); $this->wBuf_ = ''; if ($this->protoId_ === 1 && $this->clientType_ !== self::HTTP_CLIENT_TYPE) { throw new TTransportException('Trying to send JSON encoding over binary', TTransportException::INVALID_CLIENT); } $buf = ''; if ($this->clientType_ === self::HEADER_CLIENT_TYPE) { $transformData = ''; $num_headers = 0; foreach ($this->writeTrans_ as $trans) { ++$num_headers; $transformData .= $this->getVarint($trans); } if ($this->identity !== null) { $this->writeHeaders[self::ID_VERSION_HEADER] = (string) self::ID_VERSION; $this->writeHeaders[self::IDENTITY_HEADER] = $this->identity; } $infoData = ''; if (\hacklib_cast_as_boolean($this->writeHeaders) || \hacklib_cast_as_boolean($this->persistentWriteHeaders)) { $infoData .= $this->getVarint(self::INFO_KEYVALUE); $infoData .= $this->getVarint(count($this->writeHeaders) + count($this->persistentWriteHeaders)); foreach ($this->persistentWriteHeaders as $str_key => $str_value) { $infoData .= $this->writeString($str_key); $infoData .= $this->writeString($str_value); } foreach ($this->writeHeaders as $str_key => $str_value) { $infoData .= $this->writeString($str_key); $infoData .= $this->writeString($str_value); } } $this->writeHeaders = \HH\Map::hacklib_new(array(), array()); $headerData = $this->getVarint($this->protoId_) . $this->getVarint($num_headers); $header_size = strlen($transformData) + strlen($infoData) + strlen($headerData); $paddingSize = 4 - $header_size % 4; $header_size += $paddingSize; $buf = (string) pack('nn', self::HEADER_MAGIC, $this->flags_); $buf .= (string) pack('Nn', $this->seqId_, $header_size / 4); $buf .= $headerData . $transformData; $buf .= $infoData; for ($i = 0; $i < $paddingSize; $i++) { $buf .= (string) pack('C', '\\0'); } $buf .= $out; $buf = (string) pack('N', strlen($buf)) . $buf; } else { if ($this->clientType_ === self::FRAMED_DEPRECATED) { $buf = (string) pack('N', strlen($out)); $buf .= $out; } else { if ($this->clientType_ === self::UNFRAMED_DEPRECATED) { $buf = $out; } else { if ($this->clientType_ === self::HTTP_CLIENT_TYPE) { throw new TTransportException('HTTP not implemented', TTransportException::INVALID_CLIENT); } else { throw new TTransportException('Unknown client type', TTransportException::INVALID_CLIENT); } } } } if (strlen($buf) > self::MAX_FRAME_SIZE) { throw new TTransportException('Attempting to send oversize frame', TTransportException::INVALID_FRAME_SIZE); } $this->transport_->write($buf); if (\hacklib_cast_as_boolean($oneway)) { $this->transport_->onewayFlush(); } else { $this->transport_->flush(); } }
public function readString(&$value) { $len = 0; $result = $this->readI32($len); if (\hacklib_cast_as_boolean($len)) { $value = $this->trans_->readAll($len); } else { $value = ""; } return $result + $len; }
protected function _write($class, $spec, $output) { $xfer = 0; $xfer += $output->writeStructBegin($class); foreach ($spec as $fid => $fspec) { $var = $fspec[\hacklib_id('var')]; if ($this->{$var} !== null) { $ftype = $fspec[\hacklib_id('type')]; $xfer += $output->writeFieldBegin($var, $ftype, $fid); if (\hacklib_cast_as_boolean(isset(TBase::$tmethod[$ftype]))) { $func = 'write' . TBase::$tmethod[$ftype]; $xfer += $output->{$func}($this->{$var}); } else { switch ($ftype) { case TType::STRUCT: $xfer += $this->{$var}->write($output); break; case TType::MAP: $xfer += $this->_writeMap($this->{$var}, $fspec, $output); break; case TType::LST: $xfer += $this->_writeList($this->{$var}, $fspec, $output, false); break; case TType::SET: $xfer += $this->_writeList($this->{$var}, $fspec, $output, true); break; } } $xfer += $output->writeFieldEnd(); } } $xfer += $output->writeFieldStop(); $xfer += $output->writeStructEnd(); return $xfer; }
function print_res($name, $c) { echo $name . " : " . (\hacklib_cast_as_boolean($c) ? " TRUE " : " FALSE ") . "\n"; }
protected function _clientBegin($prot) { if (\hacklib_cast_as_boolean($this->serverEventHandler)) { $this->serverEventHandler->clientBegin($prot); } }
public function flush() { if (!\hacklib_cast_as_boolean($this->write_) || \hacklib_equals(strlen($this->wBuf_), 0)) { $this->transport_->flush(); return; } $out = (string) pack("N", strlen($this->wBuf_)); $out .= $this->wBuf_; $this->wBuf_ = ""; $this->transport_->write($out); $this->transport_->flush(); }
public function isOpen() { return (!\hacklib_cast_as_boolean($this->read_) || \hacklib_cast_as_boolean(is_resource($this->inStream_))) && (!\hacklib_cast_as_boolean($this->write_) || \hacklib_cast_as_boolean(is_resource($this->outStream_))); }
private function expectChar($char, $peek = false, $start = 0) { if (!\hacklib_cast_as_boolean($peek)) { $start = 0; } $c = null; if (\hacklib_cast_as_boolean($peek)) { $c = $this->bufTrans->peek(1, $start); } else { $c = $this->trans_->readAll(1); } if ($c !== $char) { throw new TProtocolException("TSimpleJSONProtocol: Expected " . $char . ", but encountered 0x" . bin2hex($c)); } }
public function isReadable() { return (bool) \hacklib_cast_as_boolean($this->data_); }
public function write($buf) { if ($this->handle_ === null) { throw new TException('TSocket: handle_ is null'); } $this->onWrite(strlen($buf)); if (!\hacklib_cast_as_boolean($this->sendTimeoutSet_)) { stream_set_timeout($this->handle_, 0, $this->sendTimeout_ * 1000); $this->sendTimeoutSet_ = true; } while (strlen($buf) > 0) { $buflen = strlen($buf); $t_start = microtime(true); $got = fwrite($this->handle_, $buf); $write_time = microtime(true) - $t_start; if ($got === 0 || !\hacklib_cast_as_boolean(is_int($got))) { $read_err_detail = sprintf('%d bytes from %s:%d to localhost:%d. Spent %2.2f ms.', $buflen, $this->host_, $this->port_, $this->lport_, $write_time * 1000); $md = stream_get_meta_data($this->handle_); if (\hacklib_cast_as_boolean($md[\hacklib_id('timed_out')])) { throw new TTransportException('TSocket: timeout while writing ' . $read_err_detail, TTransportException::TIMED_OUT); } else { $md_str = str_replace("\n", " ", print_r($md, true)); throw new TTransportException('TSocket: could not write ' . $read_err_detail, TTransportException::COULD_NOT_WRITE); } } $buf = substr($buf, $got); } $this->writeAttemptStart_ = null; }
public function skip($type) { $_ref = null; switch ($type) { case TType::BOOL: return $this->readBool($_ref); case TType::BYTE: return $this->readByte($_ref); case TType::I16: return $this->readI16($_ref); case TType::I32: return $this->readI32($_ref); case TType::I64: return $this->readI64($_ref); case TType::DOUBLE: return $this->readDouble($_ref); case TType::FLOAT: return $this->readFloat($_ref); case TType::STRING: return $this->readString($_ref); case TType::STRUCT: $result = $this->readStructBegin($_ref); while (true) { $ftype = null; $result += $this->readFieldBegin($_ref, $ftype, $_ref); if (\hacklib_equals($ftype, TType::STOP)) { break; } $result += $this->skip($ftype); $result += $this->readFieldEnd(); } $result += $this->readStructEnd(); return $result; case TType::MAP: $keyType = null; $valType = null; $size = 0; $result = $this->readMapBegin($keyType, $valType, $size); for ($i = 0; $size === null || $i < $size; $i++) { if ($size === null && !\hacklib_cast_as_boolean($this->readMapHasNext())) { break; } $result += $this->skip($keyType); $result += $this->skip($valType); } $result += $this->readMapEnd(); return $result; case TType::SET: $elemType = null; $size = 0; $result = $this->readSetBegin($elemType, $size); for ($i = 0; $size === null || $i < $size; $i++) { if ($size === null && !\hacklib_cast_as_boolean($this->readSetHasNext())) { break; } $result += $this->skip($elemType); } $result += $this->readSetEnd(); return $result; case TType::LST: $elemType = null; $size = 0; $result = $this->readListBegin($elemType, $size); for ($i = 0; $size === null || $i < $size; $i++) { if ($size === null && !\hacklib_cast_as_boolean($this->readSetHasNext())) { break; } $result += $this->skip($elemType); } $result += $this->readListEnd(); return $result; default: throw new TProtocolException("Unknown field type: " . $type, TProtocolException::INVALID_DATA); } }
public function garply($n, $s, $b) { echo \hacklib_cast_as_boolean($b) ? $s : $n; echo "\n"; }
public function read($len) { if ($this->sockRecvCapacity_ !== null) { $len = min($len, $this->sockRecvCapacity_); } $data = socket_read($this->handle_, $len); if ($data === false || $data === "") { $errno = socket_last_error($this->handle_); $errstr = socket_strerror($errno); $error = "read: no data to be read " . $this->host_ . ":" . $this->port_ . " (" . (string) $errstr . " [" . (string) $errno . "])"; if (\hacklib_cast_as_boolean($this->debug_)) { call_user_func($this->debugHandler_, $error); } return ""; } return $data; }