/**
* Called when new data received
* @return void
*/
public function onRead()
{
$packet = $this->read(1024);
$orig = $packet;
$type = Binary::getByte($packet);
$code = Binary::getByte($packet);
$checksum = Binary::getStrWord($packet);
$id = Binary::getWord($packet);
$seq = Binary::getWord($packet);
if ($checksum !== self::checksum(substr_replace($orig, "", 2, 2))) {
$status = 'badChecksum';
} elseif ($type === 0x3) {
$status = isset(static::$unreachableCodes[$code]) ? static::$unreachableCodes[$code] : 'unk' . $code . 'unreachable';
} else {
$status = 'unknownType0x' . dechex($type);
}
while (!$this->onResponse->isEmpty()) {
$el = $this->onResponse->shift();
if ($el instanceof CallbackWrapper) {
$el = $el->unwrap();
}
list($cb, $st) = $el;
call_user_func($cb, microtime(true) - $st, $status);
}
$this->finish();
}