some cleanup

This commit is contained in:
kremsy 2015-06-23 15:44:22 +02:00
parent 35de1b1b87
commit 2fbb51dcd4

View File

@ -47,11 +47,10 @@ class Communication {
* @param callable $function * @param callable $function
* @param $method * @param $method
* @param string $data * @param string $data
* @return null
*/ */
public function call(callable $function, $method, $data = "") { public function call(callable $function, $method, $data = "") {
//TODO throw an exception or smth
if (!$this->socket) { if (!$this->socket) {
call_user_func($function, true, "You need to create an Communication before using it");
return null; return null;
} }
@ -69,6 +68,11 @@ class Communication {
* Process data on every Tick * Process data on every Tick
*/ */
public function tick() { public function tick() {
//Check if the connection is enabled
if (!$this->socket) {
return;
}
$data = fgets($this->socket, 1024); // reads as much as possible OR nothing at all $data = fgets($this->socket, 1024); // reads as much as possible OR nothing at all
if (strlen($data) > 0) { // got new data if (strlen($data) > 0) { // got new data
$this->buffer .= $data; // append new data to buffer $this->buffer .= $data; // append new data to buffer