// Deliver all data
while ($sentBytes !== false) {
// And deliver it
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: Sending out ' . strlen($encodedData) . ' bytes,MD5=' . md5($encodedData) . ',bufferSize=' . $bufferSize . ',diff=' . $this->diff);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: Sending out ' . strlen($encodedData) . ' bytes,bufferSize=' . $bufferSize . ',diff=' . $this->diff);
+
if ($this->diff >= 0) {
// Send all out (encodedData is smaller than or equal buffer size)
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: MD5=' . md5(substr($encodedData, 0, ($bufferSize - $this->diff))));
$sentBytes = socket_write($socketResource, $encodedData, ($bufferSize - $this->diff));
} else {
// Send buffer size out
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: MD5=' . md5(substr($encodedData, 0, $bufferSize)));
$sentBytes = socket_write($socketResource, $encodedData, $bufferSize);
}
* @todo Do we need to do something more here?
*/
public function streamData ($data) {
+ // Do we have start and end marker again?
+ assert((substr($data, 0, 5) == '[[S]]') && (substr($data, -5, 5) == '[[E]]'));
+
// Can it be validated?
if ((strlen($data) % 4) != 0) {
// Length modulo 4 must be zero, else it is an invalid Base64 message
* @todo Do we need to do something more here?
*/
public function streamData ($data) {
- // Encode the data with BASE64 encoding
- $data = base64_encode($data);
+ /*
+ * Encode the data with BASE64 encoding and put it in a "frame":
+ *
+ * [[S]] - Start marker
+ * [[E]] - End marker
+ */
+ $data = '[[S]]' . base64_encode($data) . '[[E]]';
// Return it
return $data;