[TASK] Continued to work on the Buffer thingy. Code still broken.
This commit is contained in:
parent
c382cfe756
commit
2b8263a49d
|
@ -42,14 +42,18 @@ abstract class Client_AbstractClient {
|
|||
}
|
||||
|
||||
/**
|
||||
* Forwards incoming data to the ProtocolParser.
|
||||
* Calls protected processData()
|
||||
* Forwards incoming data to the ProtocolHandler
|
||||
* Let's the ProtocolHandler do all the work and forward its results to the Clients.
|
||||
* Return resulting raw data.
|
||||
* @param string $rawData
|
||||
* @return string
|
||||
*/
|
||||
public function processRawData($rawData) {
|
||||
$contentObject = $this->protocolHandler->pushRawData($rawData);
|
||||
return $this->processContentObject($this->protocolHandler->);
|
||||
$this->protocolHandler->pushRawData($rawData);
|
||||
while($this->protocolHandler->canWork()) {
|
||||
$this->processContentObject($this->protocolHandler->work());
|
||||
}
|
||||
return $this->protocolHandler->getRawData();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
* Abstract ProtocolHandler with the basic api.
|
||||
* The ProtocolHandler contains two buffers for incoming and outgoing data.
|
||||
* It will store the data and provide functions to add incoming and get outgoing data.
|
||||
* @author jpt
|
||||
* @abstract
|
||||
* @package Protocol
|
||||
|
@ -10,11 +12,46 @@
|
|||
abstract class Protocol_AbstractProtocolHandler {
|
||||
|
||||
/**
|
||||
* Parses incoming data, returns a ProtocolObject
|
||||
* @param string $data
|
||||
* Buffer for data that was received by the Client.
|
||||
* @var Misc_Buffer
|
||||
*/
|
||||
protected $buffer_incoming;
|
||||
|
||||
/**
|
||||
* Buffer for data that will be sent by the Client.
|
||||
* @var Misc_Buffer
|
||||
*/
|
||||
protected $buffer_outgoing;
|
||||
|
||||
/**
|
||||
* Returns whether work() can be called or not.
|
||||
* Depends on the protocol and its implementation.
|
||||
* @return boolean
|
||||
*/
|
||||
abstract public function canWork();
|
||||
|
||||
/**
|
||||
* Main worker function of the ProtocolHandler.
|
||||
* Will fetch data from the buffer_incoming, process it,
|
||||
* and create a ProtocolContentObject out of it that will be returned to the client.
|
||||
* @return mixed instance of Protocol_AbstractProtocolContentObject
|
||||
*/
|
||||
abstract public function parse($data);
|
||||
abstract public function work();
|
||||
|
||||
/**
|
||||
* Adds the incoming data to the internal buffer.
|
||||
* @param string $rawData
|
||||
*/
|
||||
public function pushRawData($rawData) {
|
||||
$this->buffer_incoming->addData($rawData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all outgoing data of the internal buffer.
|
||||
* @return string
|
||||
*/
|
||||
public function getRawData() {
|
||||
return $this->buffer_outgoing->getAllBufferContents();
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue