[TASK] Did some small changes in the code. Also updated some comments.

This commit is contained in:
Jan Philipp Timme 2011-06-29 19:16:08 +00:00
parent 77be9470a0
commit 9e83b0602a
4 changed files with 22 additions and 22 deletions

View File

@ -78,7 +78,7 @@ class Client_ClientManager {
}
/**
* Main worker function.
* Main worker procedure.
* Processes incoming data, calls clients and much more.
* @return void
*/
@ -121,6 +121,8 @@ class Client_ClientManager {
//call the registered client
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.
if($outgoingData !== "") $connectionHandler->write($result);
}
@ -196,9 +198,7 @@ class Client_ClientManager {
*/
public function getIDs() {
$list = array();
foreach($this->connectionPool->getConnectionHandlers() AS $connectionHandler) {
$list[] = $connectionHandler->getID();
}
foreach($this->connectionPool->getConnectionHandlers() AS $connectionHandler) $list[] = $connectionHandler->getID();
return $list;
}
@ -208,9 +208,7 @@ class Client_ClientManager {
*/
public function getGroups() {
$list = array();
foreach($this->connectionPool->getConnectionHandlers() AS $connectionHandler) {
$list[] = $connectionHandler->getGroup();
}
foreach($this->connectionPool->getConnectionHandlers() AS $connectionHandler) $list[] = $connectionHandler->getGroup();
return $list;
}
@ -240,6 +238,7 @@ class Client_ClientManager {
$className = "Client_" . $protocol . "Client";
//look for the class
if(class_exists($className)) {
//TODO: This looks ugly and wrong. Ideas, anyone?
$client = new $className();
if(!$client instanceof Client_AbstractClient) throw new Exception_GeneralException("Class '" . $className . "' does not implement the AbstractClient-API!", 1294837055);
return $client;
@ -299,6 +298,7 @@ class Client_ClientManager {
}
$client->injectClientManager($this);
$protocolHandlerClass = "Protocol_".$protocol."ProtocolHandler";
//TODO: This looks ugly, too. Is there a better way?
$protocolHandler = new $protocolHandlerClass();
$client->injectProtocolHandler($protocolHandler);
$client->setID($connectionHandler->getID());

View File

@ -1,6 +1,6 @@
<?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
* a full line won't be that much pain.
* @author jpt

View File

@ -66,24 +66,24 @@ class Connection_ConnectionPool {
/**
* Adds a ConnectionHandler to the pool.
* @param Connection_ConnectionHandler $add_connectionHandler
* @param Connection_ConnectionHandler $addConnectionHandler
* @return void
*/
public function addConnectionHandler($add_connectionHandler) {
array_push($this->connectionHandlers, $add_connectionHandler);
public function addConnectionHandler($addConnectionHandler) {
array_push($this->connectionHandlers, $addConnectionHandler);
$this->nextID++;
}
/**
* Removes a ConnectionHandler from the pool.
* @param Connection_ConnectionHandler $remove_connectionHandler
* @param Connection_ConnectionHandler $removeConnectionHandler
* @return void
*/
public function removeConnectionHandler($remove_connectionHandler) {
public function removeConnectionHandler($removeConnectionHandler) {
foreach($this->connectionHandlers AS $key=>$connectionHandler) {
if($connectionHandler === $remove_connectionHandler) {
$this->socketPool->removeSocket($remove_connectionHandler->getSocket());
$remove_connectionHandler->close();
if($connectionHandler === $removeConnectionHandler) {
$this->socketPool->removeSocket($removeConnectionHandler->getSocket());
$removeConnectionHandler->close();
unset($this->connectionHandlers[$key]);
}
}

View File

@ -39,22 +39,22 @@ class Socket_SocketPool {
/**
* Adds a socket to the pool
* @param ressource $add_socket
* @param ressource $addSocket
* @return void
*/
public function addSocket($add_socket) {
array_push($this->sockets, $add_socket);
public function addSocket($addSocket) {
array_push($this->sockets, $addSocket);
}
/**
* Removes the given socket from the pool.
* The socket will be shutdown.
* @param ressource $remove_socket
* @param ressource $removeSocket
* @return void
*/
public function removeSocket($remove_socket) {
public function removeSocket($removeSocket) {
foreach($this->sockets AS $key=>$socket) {
if($socket !== $remove_socket) {
if($socket !== $removeSocket) {
continue;
} else {
unset($socket);