release 1.3.0
This commit is contained in:
@@ -163,6 +163,27 @@ class TeamSpeak3_Adapter_ServerQuery extends TeamSpeak3_Adapter_Abstract
|
||||
|
||||
return new TeamSpeak3_Adapter_ServerQuery_Event($evt, $this->getHost());
|
||||
}
|
||||
|
||||
public function waittsn($lefttime = 0, $delay = 50000)
|
||||
{
|
||||
$microbegin = microtime(true);
|
||||
$token = "\n";
|
||||
|
||||
if($this->getTransport()->getConfig("blocking"))
|
||||
{
|
||||
throw new TeamSpeak3_Adapter_Exception("only available in non-blocking mode");
|
||||
}
|
||||
|
||||
do {
|
||||
$evt = $this->getTransport()->readLinetsn($token, $microbegin, $lefttime, $delay);
|
||||
} while($evt instanceof TeamSpeak3_Helper_String && !$evt->section(TeamSpeak3::SEPARATOR_CELL)->startsWith(TeamSpeak3::EVENT) && (microtime(true) < ($microbegin + $lefttime)));
|
||||
|
||||
if($evt instanceof TeamSpeak3_Helper_String && !$evt->section(TeamSpeak3::SEPARATOR_CELL)->startsWith(TeamSpeak3::EVENT)) {
|
||||
return;
|
||||
} else {
|
||||
return new TeamSpeak3_Adapter_ServerQuery_Event($evt, $this->getHost());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses given parameters and returns a prepared ServerQuery command.
|
||||
|
||||
@@ -271,4 +271,31 @@ abstract class TeamSpeak3_Transport_Abstract
|
||||
}
|
||||
while(@stream_select($read, $null, $null, $this->config["timeout"]) == 0);
|
||||
}
|
||||
|
||||
protected function waitForReadyReadtsn($time, $microbegin, $lefttime, $delay)
|
||||
{
|
||||
if(!$this->isConnected() || $this->config["blocking"]) return;
|
||||
|
||||
do
|
||||
{
|
||||
$read = array($this->stream);
|
||||
$null = null;
|
||||
|
||||
if($time)
|
||||
{
|
||||
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "WaitTimeout", $time, $this->getAdapter());
|
||||
}
|
||||
|
||||
$time = $time+$this->config["timeout"];
|
||||
$now = microtime(true);
|
||||
|
||||
if($now > ($microbegin + $lefttime)) return;
|
||||
if(stream_select($read, $null, $null, $this->config["timeout"]) === false) {
|
||||
throw new TeamSpeak3_Transport_Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost");
|
||||
} else {
|
||||
usleep($delay);
|
||||
}
|
||||
}
|
||||
while($now < ($microbegin + $lefttime));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,6 +169,42 @@ class TeamSpeak3_Transport_TCP extends TeamSpeak3_Transport_Abstract
|
||||
|
||||
return $line->trim();
|
||||
}
|
||||
|
||||
public function readLinetsn($token, $microbegin, $lefttime, $delay)
|
||||
{
|
||||
$this->connect();
|
||||
|
||||
$line = TeamSpeak3_Helper_String::factory("");
|
||||
|
||||
while(!$line->endsWith($token))
|
||||
{
|
||||
|
||||
$time = 0;
|
||||
|
||||
$this->waitForReadyReadtsn($time, $microbegin, $lefttime, $delay);
|
||||
|
||||
$data = @fgets($this->stream, 4096);
|
||||
|
||||
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data);
|
||||
|
||||
if($data === FALSE)
|
||||
{
|
||||
if($line->count())
|
||||
{
|
||||
$line->append($token);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$line->append($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $line->trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data to the stream.
|
||||
|
||||
Reference in New Issue
Block a user