[TASK] Implemented countActiveConnections().
This commit is contained in:
parent
dee3333578
commit
b1a7ac5fdb
@ -61,7 +61,6 @@ class Client_ClientManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Implement a function that is able to count active connections instead of sockets!
|
||||
* @see Connection_ConnectionPool
|
||||
* @return int
|
||||
*/
|
||||
@ -69,6 +68,15 @@ class Client_ClientManager {
|
||||
return $this->connectionPool->countSockets();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of connected connection handlers.
|
||||
* @see Connection_ConnectionPool
|
||||
* @return int
|
||||
*/
|
||||
public function countActiveConnections() {
|
||||
return $this->connectionPool->countActiveConnections();
|
||||
}
|
||||
|
||||
/**
|
||||
* Main worker function.
|
||||
* Processes incoming data, calls clients and much more.
|
||||
|
@ -180,5 +180,18 @@ class Connection_ConnectionPool {
|
||||
public function countSockets() {
|
||||
return $this->socketPool->countSockets();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of active connections.
|
||||
* A connection is active when the handler is connected.
|
||||
* @return int
|
||||
*/
|
||||
public function countActiveConnections() {
|
||||
$count = 0;
|
||||
foreach($this->connectionHandlers AS $connectionHandler) {
|
||||
if($connectionHandler->isConnected() === TRUE) $count++;
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
}
|
||||
?>
|
@ -37,7 +37,7 @@ $srv = $clientManager->createTcpConnection("srv", "jpt");
|
||||
$srv->bind("localhost", 7777);
|
||||
$srv->listen();
|
||||
|
||||
while($clientManager->countSockets() > 0) {
|
||||
while($clientManager->countActiveConnections() > 0) {
|
||||
$clientManager->work();
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user