[TASK] Did some small changes in the code. Also updated some comments.
This commit is contained in:
parent
77be9470a0
commit
9e83b0602a
|
@ -78,7 +78,7 @@ class Client_ClientManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main worker function.
|
* Main worker procedure.
|
||||||
* Processes incoming data, calls clients and much more.
|
* Processes incoming data, calls clients and much more.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@ -121,6 +121,8 @@ class Client_ClientManager {
|
||||||
//call the registered client
|
//call the registered client
|
||||||
if(isset($this->clientPool[$connectionHandler->getID()])) $outgoingData .= $this->clientPool[$connectionHandler->getID()]->processRawData($incomingData);
|
if(isset($this->clientPool[$connectionHandler->getID()])) $outgoingData .= $this->clientPool[$connectionHandler->getID()]->processRawData($incomingData);
|
||||||
|
|
||||||
|
//i don't know what to do here... maybe call a connection bridge?
|
||||||
|
|
||||||
//output will be sent.
|
//output will be sent.
|
||||||
if($outgoingData !== "") $connectionHandler->write($result);
|
if($outgoingData !== "") $connectionHandler->write($result);
|
||||||
}
|
}
|
||||||
|
@ -196,9 +198,7 @@ class Client_ClientManager {
|
||||||
*/
|
*/
|
||||||
public function getIDs() {
|
public function getIDs() {
|
||||||
$list = array();
|
$list = array();
|
||||||
foreach($this->connectionPool->getConnectionHandlers() AS $connectionHandler) {
|
foreach($this->connectionPool->getConnectionHandlers() AS $connectionHandler) $list[] = $connectionHandler->getID();
|
||||||
$list[] = $connectionHandler->getID();
|
|
||||||
}
|
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,9 +208,7 @@ class Client_ClientManager {
|
||||||
*/
|
*/
|
||||||
public function getGroups() {
|
public function getGroups() {
|
||||||
$list = array();
|
$list = array();
|
||||||
foreach($this->connectionPool->getConnectionHandlers() AS $connectionHandler) {
|
foreach($this->connectionPool->getConnectionHandlers() AS $connectionHandler) $list[] = $connectionHandler->getGroup();
|
||||||
$list[] = $connectionHandler->getGroup();
|
|
||||||
}
|
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,6 +238,7 @@ class Client_ClientManager {
|
||||||
$className = "Client_" . $protocol . "Client";
|
$className = "Client_" . $protocol . "Client";
|
||||||
//look for the class
|
//look for the class
|
||||||
if(class_exists($className)) {
|
if(class_exists($className)) {
|
||||||
|
//TODO: This looks ugly and wrong. Ideas, anyone?
|
||||||
$client = new $className();
|
$client = new $className();
|
||||||
if(!$client instanceof Client_AbstractClient) throw new Exception_GeneralException("Class '" . $className . "' does not implement the AbstractClient-API!", 1294837055);
|
if(!$client instanceof Client_AbstractClient) throw new Exception_GeneralException("Class '" . $className . "' does not implement the AbstractClient-API!", 1294837055);
|
||||||
return $client;
|
return $client;
|
||||||
|
@ -299,6 +298,7 @@ class Client_ClientManager {
|
||||||
}
|
}
|
||||||
$client->injectClientManager($this);
|
$client->injectClientManager($this);
|
||||||
$protocolHandlerClass = "Protocol_".$protocol."ProtocolHandler";
|
$protocolHandlerClass = "Protocol_".$protocol."ProtocolHandler";
|
||||||
|
//TODO: This looks ugly, too. Is there a better way?
|
||||||
$protocolHandler = new $protocolHandlerClass();
|
$protocolHandler = new $protocolHandlerClass();
|
||||||
$client->injectProtocolHandler($protocolHandler);
|
$client->injectProtocolHandler($protocolHandler);
|
||||||
$client->setID($connectionHandler->getID());
|
$client->setID($connectionHandler->getID());
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* This class is a decorator for the class SocketHandler.
|
* This class is a decorator for the SocketHandler class.
|
||||||
* It provides a buffer for the SocketHandler, so reading and writing
|
* It provides a buffer for the SocketHandler, so reading and writing
|
||||||
* a full line won't be that much pain.
|
* a full line won't be that much pain.
|
||||||
* @author jpt
|
* @author jpt
|
||||||
|
|
|
@ -66,24 +66,24 @@ class Connection_ConnectionPool {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a ConnectionHandler to the pool.
|
* Adds a ConnectionHandler to the pool.
|
||||||
* @param Connection_ConnectionHandler $add_connectionHandler
|
* @param Connection_ConnectionHandler $addConnectionHandler
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function addConnectionHandler($add_connectionHandler) {
|
public function addConnectionHandler($addConnectionHandler) {
|
||||||
array_push($this->connectionHandlers, $add_connectionHandler);
|
array_push($this->connectionHandlers, $addConnectionHandler);
|
||||||
$this->nextID++;
|
$this->nextID++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a ConnectionHandler from the pool.
|
* Removes a ConnectionHandler from the pool.
|
||||||
* @param Connection_ConnectionHandler $remove_connectionHandler
|
* @param Connection_ConnectionHandler $removeConnectionHandler
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function removeConnectionHandler($remove_connectionHandler) {
|
public function removeConnectionHandler($removeConnectionHandler) {
|
||||||
foreach($this->connectionHandlers AS $key=>$connectionHandler) {
|
foreach($this->connectionHandlers AS $key=>$connectionHandler) {
|
||||||
if($connectionHandler === $remove_connectionHandler) {
|
if($connectionHandler === $removeConnectionHandler) {
|
||||||
$this->socketPool->removeSocket($remove_connectionHandler->getSocket());
|
$this->socketPool->removeSocket($removeConnectionHandler->getSocket());
|
||||||
$remove_connectionHandler->close();
|
$removeConnectionHandler->close();
|
||||||
unset($this->connectionHandlers[$key]);
|
unset($this->connectionHandlers[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,22 +39,22 @@ class Socket_SocketPool {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a socket to the pool
|
* Adds a socket to the pool
|
||||||
* @param ressource $add_socket
|
* @param ressource $addSocket
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function addSocket($add_socket) {
|
public function addSocket($addSocket) {
|
||||||
array_push($this->sockets, $add_socket);
|
array_push($this->sockets, $addSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the given socket from the pool.
|
* Removes the given socket from the pool.
|
||||||
* The socket will be shutdown.
|
* The socket will be shutdown.
|
||||||
* @param ressource $remove_socket
|
* @param ressource $removeSocket
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function removeSocket($remove_socket) {
|
public function removeSocket($removeSocket) {
|
||||||
foreach($this->sockets AS $key=>$socket) {
|
foreach($this->sockets AS $key=>$socket) {
|
||||||
if($socket !== $remove_socket) {
|
if($socket !== $removeSocket) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
unset($socket);
|
unset($socket);
|
||||||
|
|
Loading…
Reference in New Issue