From 218e49da7ab035573696ab83f8fcc5265ad87233 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 28 Apr 2012 08:37:05 +0000 Subject: [PATCH] Introduced new meta peer state 'problem' --- .gitattributes | 1 + application/hub/config.php | 3 ++ .../connection/class_BaseConnectionHelper.php | 12 +++++ .../tcp/class_TcpConnectionHelper.php | 3 -- .../peer/errors/class_ProblemPeerState.php | 53 +++++++++++++++++++ 5 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 application/hub/main/states/peer/errors/class_ProblemPeerState.php diff --git a/.gitattributes b/.gitattributes index 3f6d8cc60..6382e8404 100644 --- a/.gitattributes +++ b/.gitattributes @@ -466,6 +466,7 @@ application/hub/main/states/peer/errors/class_ConnectionRefusedPeerState.php svn application/hub/main/states/peer/errors/class_ConnectionTimedOutPeerState.php svneol=native#text/plain application/hub/main/states/peer/errors/class_NoRouteToHostPeerState.php svneol=native#text/plain application/hub/main/states/peer/errors/class_OperationAlreadyProgressPeerState.php svneol=native#text/plain +application/hub/main/states/peer/errors/class_ProblemPeerState.php svneol=native#text/plain application/hub/main/states/peer/errors/class_TransportEndpointGonePeerState.php svneol=native#text/plain application/hub/main/states/peer/init/.htaccess -text svneol=unset#text/plain application/hub/main/states/peer/init/class_InitPeerState.php svneol=native#text/plain diff --git a/application/hub/config.php b/application/hub/config.php index a67e18f89..b1505b352 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -589,6 +589,9 @@ $cfg->setConfigEntry('peer_init_state_class', 'InitPeerState'); // CFG: PEER-CONNECTED-STATE-CLASS $cfg->setConfigEntry('peer_connected_state_class', 'ConnectedPeerState'); +// CFG: PEER-PROBLEM-STATE-CLASS +$cfg->setConfigEntry('peer_problem_state_class', 'ProblemPeerState'); + // CFG: PEER-CONNECTION-REFUSED-STATE-CLASS $cfg->setConfigEntry('peer_connection_refused_state_class', 'ConnectionRefusedPeerState'); diff --git a/application/hub/main/helper/connection/class_BaseConnectionHelper.php b/application/hub/main/helper/connection/class_BaseConnectionHelper.php index c85464642..39fa404eb 100644 --- a/application/hub/main/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/main/helper/connection/class_BaseConnectionHelper.php @@ -252,6 +252,18 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc } } // END - while + // Is the peer connected? + if ($isConnected === true) { + // Connection is fully established here, so change the state. + PeerStateFactory::createPeerStateInstanceByName('connected', $this); + } else { + /* + * There was a problem connecting to the peer (this state is a meta + * state until the error handler has found the real cause). + */ + PeerStateFactory::createPeerStateInstanceByName('problem', $this); + } + // Return status return $isConnected; } diff --git a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php index d10b80f88..9095b817b 100644 --- a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php +++ b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php @@ -130,9 +130,6 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp $helperInstance->handleSocketError($socketResource, $recipientData); } // END - if - // Connection is fully established here, so change the state - PeerStateFactory::createPeerStateInstanceByName('connected', $helperInstance); - // Okay, that should be it. Return it... return $socketResource; } diff --git a/application/hub/main/states/peer/errors/class_ProblemPeerState.php b/application/hub/main/states/peer/errors/class_ProblemPeerState.php new file mode 100644 index 000000000..6f388486e --- /dev/null +++ b/application/hub/main/states/peer/errors/class_ProblemPeerState.php @@ -0,0 +1,53 @@ + + * @version 0.0.0 + * @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 + * + * 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 . + */ +class ProblemPeerState extends BasePeerState implements PeerStateable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set state name + $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_UNKNOWN); + } + + /** + * Creates an instance of this class + * + * @return $stateInstance An instance of a PeerStateable class + */ + public final static function createProblemPeerState () { + // Get new instance + $stateInstance = new ProblemPeerState(); + + // Return the prepared instance + return $stateInstance; + } +} + +// [EOF] +?> -- 2.39.5