Attempting to create better shutdown for InputServer

This commit is contained in:
ShadowEO
2016-05-31 16:09:28 -04:00
parent 55231f3ad4
commit c8884d3f5b

View File

@@ -11,6 +11,7 @@ $inputserver_ref = null;
$inputclients = null;
$inputserver_sock = null;
$inputserver_conn = null;
$stream = null;
class InputDeviceServices {
@@ -94,10 +95,10 @@ class InputDeviceServices {
global $inputserver_ref;
global $loop;
LogEcho("Connection to Event Server.", "UINPUT");
LogEcho("Connection to Event Server.", "INPUTS");
$connection->id = ++$i;
$connection->on('end',function() {
InputDeviceServices::CloseInputServer('null');
$connection->on('end',function() use ($inputserver_ref) {
$inputserver_ref->terminate();
});
$inputclients->attach($connection);
@@ -113,11 +114,11 @@ class InputDeviceServices {
}
});
$inputserver_ref->stderr->on('data', function($output) {
if($output != "") LogEcho($output,"INPUT");
if($output != "") LogEcho($output,"INPUTS");
});
});
$inputserver_sock->listen("5055", "0.0.0.0");
LogEcho("Event server started on port 5055", "UINPUT");
LogEcho("Event server started on port 5055", "INPUTS");
//$loop->addTimer(0.001, function($timer) use ($inputserver_ref) {
@@ -138,6 +139,7 @@ class InputDeviceServices {
global $loop;
global $input_client_process;
global $input_client;
global $stream;
//$client = new steam_socket_client('tcp://'.$IP.":".$PORT);
//$client_connection = new React\Stream\Steam($client, $loop);
$input_client_process = new React\ChildProcess\Process('/opt/uinput-mapper/input-create -C');
@@ -151,8 +153,10 @@ class InputDeviceServices {
$input_client = new React\SocketClient\Connector($loop, $dns);
$input_client->create($IP, $PORT)->then(function (React\Stream\Stream $stream) use ($IP, $PORT) {
LogEcho("Connected to event server on: ".$sql['DEVICES']['host'].":".$sql['DEVICES']['port'],"INPUTC");
$stream->on('data', function($data) {
LogEcho("Connected to event server on: ".$IP. ":". $PORT,"INPUTC");
global $stream;
$stream = $stream;
$stream->on('data', function($data) {
global $input_client_process;
#if(defined("DEBUG")) LogEcho($data, "INPUTC");
$input_client_process->stdin->write($data);
@@ -180,8 +184,10 @@ class InputDeviceServices {
function Disconnect($sql) {
global $input_client_process;
global $input_client;
global $stream;
$input_client_process->terminate();
$stream->end();
//$input_client->end();
$ResponseArray = array("response_type"=>"success",
"response_msg"=>"Successfully disconnected from Event Server socket.",