application/hub/interfaces/nodes/class_NodeHelper.php -text svneol=unset#text/plain
application/hub/interfaces/package/.htaccess -text
application/hub/interfaces/package/class_Deliverable.php -text svneol=unset#text/plain
+application/hub/interfaces/package/fragmenter/.htaccess -text
+application/hub/interfaces/package/fragmenter/class_Fragmentable.php -text
application/hub/interfaces/pool/.htaccess -text
application/hub/interfaces/pool/class_Poolable.php -text svneol=unset#text/plain
application/hub/interfaces/pool/listener/.htaccess -text
application/hub/main/nodes/regular/class_HubRegularNode.php -text svneol=unset#text/plain
application/hub/main/package/.htaccess -text
application/hub/main/package/class_NetworkPackage.php -text svneol=unset#text/plain
+application/hub/main/package/fragmenter/.htaccess -text
+application/hub/main/package/fragmenter/class_PackageFragmenter.php -text
application/hub/main/pools/.htaccess -text
application/hub/main/pools/class_ -text svneol=unset#text/plain
application/hub/main/pools/class_BasePool.php -text svneol=unset#text/plain
// CFG: EXTERNAL-IP
$cfg->setConfigEntry('external_ip', 'free-search.homelinux.org');
+// CFG: PACKAGE-FRAGMENTER-CLASS
+$cfg->setConfigEntry('package_fragmenter_class', 'PackageFragmenter');
+
// [EOF]
?>
}
}
+// Error handler
+function __errorHandler ($errno, $errstr, $errfile, $errline, array $errcontext) {
+ // Construct the message
+ $message = sprintf("File: %s, Line: %s, Code: %s, Message: %s",
+ basename($errfile),
+ $errline,
+ $errno,
+ $errstr
+ );
+
+ // Throw an exception here
+ throw new FatalErrorException($message, BaseFrameworkSystem::EXCEPTION_FATAL_ERROR);
+} // END - function
+
+// Assertion handler
+function __assertHandler ($file, $line, $code) {
+ // Empty code?
+ if ($code === '') $code = '<em>Unknown</em>';
+
+ // Create message
+ $message = sprintf("File: %s, Line: %s, Code: %s",
+ basename($file),
+ $line,
+ $code
+ );
+
+ // Throw an exception here
+ throw new AssertionException($message, BaseFrameworkSystem::EXCEPTION_ASSERTION_FAILED);
+} // END - function
+
+// Set error handler
+//set_error_handler('__errorHandler');
+
// Set the new handler
set_exception_handler('hub_exception_handler');
+// Init assert handling
+assert_options(ASSERT_ACTIVE, 1);
+assert_options(ASSERT_WARNING, 0);
+assert_options(ASSERT_BAIL, 0);
+assert_options(ASSERT_QUIET_EVAL, 0);
+assert_options(ASSERT_CALLBACK, '__assertHandler');
+
// [EOF]
?>
*
* @return void
*/
- function sentWaitingPackage ();
+ function sendWaitingPackage ();
}
// [EOF]
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for a package fragmenter
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface Fragmentable extends FrameworkInterface {
+}
+
+// [EOF]
+?>
/**
* "Accept" a visitor by simply calling it back
*
- * @param $visitorInstance A Visitable instance
+ * @param $visitorInstance A Visitor instance
* @return void
*/
protected final function accept (Visitor $visitorInstance) {
$visitorInstance->visitConnectionHelper($this);
}
+ /**
+ * "Getter" for raw package data from a package array. This method does
+ * honor any unsend bytes in the back-buffer and the sending buffer size.
+ *
+ * @param $packageData Raw package data array
+ * @return $rawData Raw package data bytes
+ */
+ private function getRawDataFromPackageArray (array $packageData) {
+ // Get the fragmenter instance
+ $fragmenterInstance = ObjectFactory::createObjectByConfiguredName('package_fragmenter_class');
+ $fragmenterInstance->debugInstance();
+
+ // Return it
+ return $rawData;
+ }
+
/**
* Sends raw package data to the recipient
*
* @param $packageData Raw package data
- * @return void
- *@ throws InvalidSocketException If we got a problem with this socket
+ * @return $sentBytes Actual sent bytes to the peer
+ * @throws InvalidSocketException If we got a problem with this socket
*/
public function sendRawPackageData (array $packageData) {
// We need to "package" all data. This is done by a implode()
- $rawData = implode(NetworkPackage::PACKAGE_DATA_SEPERATOR, $packageData);
+ $rawData = $this->getRawDataFromPackageArray($packageData);
// Get socket resource
$socketResource = $this->getSocketResource();
// And deliver it
- $numBytes = @socket_write($socketResource, $rawData, $this->getConfigInstance()->getConfigEntry($this->getProtocol() . '_buffer_length') - $this->offset);
+ $sentBytes = @socket_write($socketResource, $rawData, $this->getConfigInstance()->getConfigEntry($this->getProtocol() . '_buffer_length') - $this->offset);
// If there was an error, we don't continue here
- if ($numBytes === false) {
+ if ($sentBytes === false) {
// Get socket error code for verification
$socketError = socket_last_error($socketResource);
throw new InvalidSocketException(array($this, gettype($socketResource), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
} // END - if
- // How much has been sent?
- die('num=' . $numBytes . "\n");
+ // The difference between sent bytes and length of raw data should not be below zero
+ assert((strlen($rawData) - $sentBytes) >= 0);
+
+ // Return sent bytes
+ return $sentBytes;
}
/**
*/
const STACKER_NAME_OUTGOING = 'outgoing';
+ /**
+ * Stacker name for "back-buffered" packages
+ */
+ const STACKER_NAME_BACK_BUFFER = 'backbuffer';
+
/**
* Network target (alias): 'upper hubs'
*/
} // END - if
// Sent it away (we catch exceptions one method above
- $connectionInstance->sendRawPackageData($packageData);
+ $sentBytes = $connectionInstance->sendRawPackageData($packageData);
+
+ // Remember unsent raw bytes in back-buffer, if any
+ $this->storeUnsentBytesInBackBuffer($packageData, $sentBytes);
}
/**
*
* @return void
*/
- public function sentWaitingPackage () {
+ public function sendWaitingPackage () {
+ // Sent any waiting bytes in the back-buffer
+ $this->sendBackBufferBytes();
+
// Sanity check if we have packages waiting for delivery
if (!$this->isPackageWaitingDelivery()) {
// This is not fatal but should be avoided
// Get the package again
$packageData = $this->getStackerInstance()->getNamed(self::STACKER_NAME_OUTGOING);
- // Now try to send it
try {
+ // Now try to send it
$this->sendOutgoingPackage($packageData);
+ die("O!\n");
- // And remove it finally when it has been fully delivered
+ // And remove it finally
$this->getStackerInstance()->popNamed(self::STACKER_NAME_OUTGOING);
} catch (InvalidSocketException $e) {
// Output exception message
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A PackageFragmenter class to fragment package data into smaller chunks for
+ * delivery. This class does add a serial number to it and in the first data
+ * submission chunk it will add a sumerization of all fragements and their
+ * serial numbers.
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class PackageFragmenter extends BaseFrameworkSystem implements Fragmentable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $fragmenterInstance An instance of a Fragmentable class
+ */
+ public final static function createPackageFragmenter () {
+ // Get new instance
+ $fragmenterInstance = new PackageFragmenter();
+
+ // Return the prepared instance
+ return $fragmenterInstance;
+ }
+}
+
+// [EOF]
+?>
$packageInstance->deliverDeclaredPackage();
} elseif ($packageInstance->isPackageWaitingDelivery()) {
// Sent it finally out
- $packageInstance->sentWaitingPackage();
+ $packageInstance->sendWaitingPackage();
}
}
}