diff --git a/Classes/Client/ClientManager.php b/Classes/Client/ClientManager.php index e069ccb..cec2f22 100644 --- a/Classes/Client/ClientManager.php +++ b/Classes/Client/ClientManager.php @@ -41,11 +41,10 @@ class Client_ClientManager { /** * Default constructor. - * @param string $linebreak * @return void */ - function __construct($linebreak = "\r\n") { - $this->connectionPool = new Connection_ConnectionPool($linebreak); + function __construct() { + $this->connectionPool = new Connection_ConnectionPool(); $this->clientPool = array(); $this->registeredProtocols = array(); $this->routingRules = array(); diff --git a/Classes/Connection/ConnectionPool.php b/Classes/Connection/ConnectionPool.php index 327f582..6b5ebba 100644 --- a/Classes/Connection/ConnectionPool.php +++ b/Classes/Connection/ConnectionPool.php @@ -28,9 +28,9 @@ class Connection_ConnectionPool { * Creates an Instance of SocketPool * @return void */ - function __construct($linebreak = "\r\n") { + function __construct() { $this->connectionHandlers = array(); - $this->socketPool = new Socket_SocketPool($linebreak); + $this->socketPool = new Socket_SocketPool(); $this->nextID = 1; } diff --git a/Classes/Misc/Buffer.php b/Classes/Misc/Buffer.php index 43c1f6c..2fb23e7 100644 --- a/Classes/Misc/Buffer.php +++ b/Classes/Misc/Buffer.php @@ -3,6 +3,7 @@ * Buffer class for a string. * Will fix issues with sockets that don't care about linebreaks. * Can also be used for all kinds of purpose. + * TODO: implement a method to return the next X bytes (return false if not enough bytes there,yet) * @author jpt * @package Misc */ @@ -25,7 +26,7 @@ class Misc_Buffer { * @param $linebreak * @return void */ - function __construct($linebreak = "\r\n") { + function __construct($linebreak = "") { $this->buffer = ""; $this->linebreak = $linebreak; } @@ -35,6 +36,8 @@ class Misc_Buffer { * @return void */ protected function pruneEmptyLines() { + //no need to do this when there are no linebreaks. + if($this->linebreak === "") return; if(strpos($this->buffer, $this->linebreak) === FALSE) return; $has_linebreak_at_end = (substr($this->buffer, (-1) * strlen($this->linebreak)) === $this->linebreak) ? TRUE : FALSE; $lines = explode($this->linebreak, $this->buffer); @@ -60,8 +63,10 @@ class Misc_Buffer { /** * Returns the next line in the buffer and removes it from the buffer. * @return string + * @throws Exception_GeneralException */ public function getNextLine() { + if($this->linebreak === "") throw new Exception_GeneralException("Cannot return a line - no linebreak is set!", 1290964174); if(!$this->hasLines()) return ""; list($line) = explode($this->linebreak, $this->buffer); $this->buffer = str_replace($line.$this->linebreak, "", $this->buffer); @@ -70,11 +75,22 @@ class Misc_Buffer { return $result; } + /** + * Returns the next $length chars from the buffer. + * @return string Returns "" if no + */ + public function getNextChars($length) { + //TODO: substr und so + return ""; + } + /** * Checks whether the buffer contains more lines to process. * @return boolean + * @throws Exception_GeneralException */ public function hasLines() { + if($this->linebreak === "") throw new Exception_GeneralException("Cannot tell whether the buffer has lines - no linebreak set!", 1290964243); return (trim(strstr($this->buffer, $this->linebreak, TRUE)) !== "") ? TRUE : FALSE; } diff --git a/Classes/Protocol/AbstractProtocolHandler.php b/Classes/Protocol/AbstractProtocolHandler.php index cf87df6..a0aa29b 100644 --- a/Classes/Protocol/AbstractProtocolHandler.php +++ b/Classes/Protocol/AbstractProtocolHandler.php @@ -5,6 +5,7 @@ * @abstract * @package Protocol * TODO: finish this shit + * TODO: Move the buffers here, they will be more useful. */ abstract class Protocol_AbstractProtocolHandler {