private function handle_events($external, $data, $data_size, $i, $command = null)
{
if (is_null($command)) {
if ($i > $data_size) {
throw new MessageDecodingException();
}
$j = 4;
list(, $command) = unpack('L', substr($data, $i, $j));
} else {
$j = 4;
}
while (true) {
switch ($command) {
case MESSAGE_TERM:
$this->terminate = true;
if ($external) {
return false;
} else {
throw new TerminateException($this->timeout_terminate);
}
case MESSAGE_REINIT:
$i += $j;
$j = 4;
list(, $this->process_count) = unpack('L', substr($data, $i, $j));
$i += $j;
break;
case MESSAGE_KEEPALIVE:
$this->send(\Erlang\term_to_binary(new \Erlang\OtpErlangAtom('keepalive')));
$i += $j;
break;
default:
throw new MessageDecodingException();
}
if ($i > $data_size) {
throw new MessageDecodingException();
} elseif ($i == $data_size) {
return true;
}
$j = 4;
list(, $command) = unpack('L', substr($data, $i, $j));
}
}