[TASK] Started to move buffers into ProtocolHandler.
[TODO] Move buffers, finish the linebreak stuff.
This commit is contained in:
parent
db9dda856c
commit
5cb0714834
|
@ -41,11 +41,10 @@ class Client_ClientManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
* @param string $linebreak
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function __construct($linebreak = "\r\n") {
|
function __construct() {
|
||||||
$this->connectionPool = new Connection_ConnectionPool($linebreak);
|
$this->connectionPool = new Connection_ConnectionPool();
|
||||||
$this->clientPool = array();
|
$this->clientPool = array();
|
||||||
$this->registeredProtocols = array();
|
$this->registeredProtocols = array();
|
||||||
$this->routingRules = array();
|
$this->routingRules = array();
|
||||||
|
|
|
@ -28,9 +28,9 @@ class Connection_ConnectionPool {
|
||||||
* Creates an Instance of SocketPool
|
* Creates an Instance of SocketPool
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function __construct($linebreak = "\r\n") {
|
function __construct() {
|
||||||
$this->connectionHandlers = array();
|
$this->connectionHandlers = array();
|
||||||
$this->socketPool = new Socket_SocketPool($linebreak);
|
$this->socketPool = new Socket_SocketPool();
|
||||||
$this->nextID = 1;
|
$this->nextID = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
* Buffer class for a string.
|
* Buffer class for a string.
|
||||||
* Will fix issues with sockets that don't care about linebreaks.
|
* Will fix issues with sockets that don't care about linebreaks.
|
||||||
* Can also be used for all kinds of purpose.
|
* 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
|
* @author jpt
|
||||||
* @package Misc
|
* @package Misc
|
||||||
*/
|
*/
|
||||||
|
@ -25,7 +26,7 @@ class Misc_Buffer {
|
||||||
* @param $linebreak
|
* @param $linebreak
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function __construct($linebreak = "\r\n") {
|
function __construct($linebreak = "") {
|
||||||
$this->buffer = "";
|
$this->buffer = "";
|
||||||
$this->linebreak = $linebreak;
|
$this->linebreak = $linebreak;
|
||||||
}
|
}
|
||||||
|
@ -35,6 +36,8 @@ class Misc_Buffer {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function pruneEmptyLines() {
|
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;
|
if(strpos($this->buffer, $this->linebreak) === FALSE) return;
|
||||||
$has_linebreak_at_end = (substr($this->buffer, (-1) * strlen($this->linebreak)) === $this->linebreak) ? TRUE : FALSE;
|
$has_linebreak_at_end = (substr($this->buffer, (-1) * strlen($this->linebreak)) === $this->linebreak) ? TRUE : FALSE;
|
||||||
$lines = explode($this->linebreak, $this->buffer);
|
$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.
|
* Returns the next line in the buffer and removes it from the buffer.
|
||||||
* @return string
|
* @return string
|
||||||
|
* @throws Exception_GeneralException
|
||||||
*/
|
*/
|
||||||
public function getNextLine() {
|
public function getNextLine() {
|
||||||
|
if($this->linebreak === "") throw new Exception_GeneralException("Cannot return a line - no linebreak is set!", 1290964174);
|
||||||
if(!$this->hasLines()) return "";
|
if(!$this->hasLines()) return "";
|
||||||
list($line) = explode($this->linebreak, $this->buffer);
|
list($line) = explode($this->linebreak, $this->buffer);
|
||||||
$this->buffer = str_replace($line.$this->linebreak, "", $this->buffer);
|
$this->buffer = str_replace($line.$this->linebreak, "", $this->buffer);
|
||||||
|
@ -70,11 +75,22 @@ class Misc_Buffer {
|
||||||
return $result;
|
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.
|
* Checks whether the buffer contains more lines to process.
|
||||||
* @return boolean
|
* @return boolean
|
||||||
|
* @throws Exception_GeneralException
|
||||||
*/
|
*/
|
||||||
public function hasLines() {
|
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;
|
return (trim(strstr($this->buffer, $this->linebreak, TRUE)) !== "") ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* @abstract
|
* @abstract
|
||||||
* @package Protocol
|
* @package Protocol
|
||||||
* TODO: finish this shit
|
* TODO: finish this shit
|
||||||
|
* TODO: Move the buffers here, they will be more useful.
|
||||||
*/
|
*/
|
||||||
abstract class Protocol_AbstractProtocolHandler {
|
abstract class Protocol_AbstractProtocolHandler {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue