[TASK] Added function for clients, so they're able to send initial data right after connecting to a server.

[TASK] Restructured parts of the core to support sending data right after connecting.
[TASK] Adapted core part for automatic reconnect to support sending initial data, too.
This commit is contained in:
Jan Philipp Timme
2011-06-25 22:13:53 +00:00
parent 4c9f5ba7f3
commit 2c5e520c9f
11 changed files with 159 additions and 66 deletions
+17 -1
View File
@@ -56,6 +56,14 @@ class Connection_ConnectionPool {
return $connectionHandler;
}
/**
* Returns the array with the current connectionHandlers.
* @return array
*/
public function getConnectionHandlers() {
return $this->connectionHandlers;
}
/**
* Adds a ConnectionHandler to the pool.
* @param Connection_ConnectionHandler $add_connectionHandler
@@ -108,9 +116,15 @@ class Connection_ConnectionPool {
foreach($this->connectionHandlers AS $connectionHandler) {
$connectionSocket = $connectionHandler->getSocket();
$read[] = $connectionSocket;
if($connectionHandler->canWrite() && $connectionHandler->isServer() === FALSE) $write[] = $connectionSocket;
if($connectionHandler->canWrite() === TRUE && $connectionHandler->isServer() === FALSE) {
$write[] = $connectionSocket;
//the line above does not work for freshly connected stuff.
//this is the fallback(?) - just write the stuff - no matter what happens.
if($connectionHandler->writeFromBuffer() === FALSE) $this->removeConnectionHandler($connectionHandler);
}
}
$except = $read;
//Arrays are prepared, let's have socket_select() take a look and process its results.
$tempArray = array();
$selectedSockets = $this->socketPool->select($read, $write, $except);
@@ -129,6 +143,8 @@ class Connection_ConnectionPool {
}
break;
case "write":
//this might still work on active connections that are "in use".
//however, it does not for freshly connected ones.
if($connectionHandler->writeFromBuffer() === FALSE) $this->removeConnectionHandler($connectionHandler);
break;
case "except":