*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
*
* @return $resolverInstance The prepared state resolver instance
*/
- public final static function createNetworkStateResolver () {
+ public static final function createNetworkStateResolver () {
// Create the new instance
$resolverInstance = new NetworkStateResolver();
* Returns an state instance for a given package class
*
* @param $packageInstance An instance of a package class
- * @param $rawData The raw data
+ * @param $packageData Raw package data
+ * @param $socketResource A valid socket resource
* @return $stateInstance An instance of the resolved state
* @todo ~30% done
*/
- public function resolveStateByPackage (Networkable $packageInstance, $rawData) {
+ public function resolveStateByPackage (Networkable $packageInstance, array $packageData, $socketResource) {
+ // Init state instance
+ $stateInstance = null;
+
// Get error code
$errorCode = $packageInstance->getErrorCode();
if (($errorCode == 134) || ($errorCode == 107)) {
// Transport endpoint not connected, should be handled else!
// @TODO On some systems it is 134, on some 107?
- $errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
+ $errorCode = BaseRawDataHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
} elseif (is_int($errorCode)) {
- // Debug output (because we might want to handle it like the above(s)
- $this->debugOutput(__METHOD__ . ': UNKNOWN ERROR CODE = ' . $errorCode, ', MESSAGE = ' . socket_strerror($errorCode));
+ // Unhandled error code detected, so first debug it because we may want to handle it like the others
+ $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode, ', MESSAGE = ' . socket_strerror($errorCode));
// Change it only in this class
- $errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_UNKNOWN;
+ $errorCode = BaseRawDataHandler::SOCKET_ERROR_UNKNOWN;
} // END - if
- // @TODO We need to somehow detect the state/status of the remote peer and still maintain good speed.
- // @TODO So maybe some pre-instancing of classes might help here to speedup this I/O intensive process.
- $this->partialStub('errorCode=' . $errorCode . ',rawData[] = ' . gettype($rawData) . '(' . strlen($rawData) . ')');
+ // Create a state instance based on $errorCode. This factory does the hard work for us
+ $stateInstance = PeerStateFactory::createPeerStateInstanceByErrorCode($errorCode, $packageData, $socketResource);
+
+ // Return the prepared instance
+ return $stateInstance;
}
}