application/hub/main/visitor/pool/shutdown/.htaccess -text
application/hub/main/visitor/pool/shutdown/class_Shutdown -text
application/hub/main/visitor/pool/shutdown/class_ShutdownListenerPoolVisitor.php -text
+application/hub/main/visitor/socket/.htaccess -text
application/hub/main/visitor/tasks/.htaccess -text
application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php -text
application/hub/starter.php -text
// CFG: SHUTDOWN-TASK-VISITOR-CLASS
$cfg->setConfigEntry('shutdown_task_visitor_class', 'ShutdownTaskVisitor');
+// CFG: SHUTDOWN-SOCKET-VISITOR-CLASS
+$cfg->setConfigEntry('shutdown_socket_visitor_class', 'ShutdownSocketVisitor');
+
// CFG: ACTIVE-TASK-VISITOR-CLASS
$cfg->setConfigEntry('active_task_visitor_class', 'ActiveTaskVisitor');
// CFG: UDP-BUFFER-LENGTH
$cfg->setConfigEntry('udp_buffer_length', 1024);
+// CFG: TCP-CONNECT-RETRY-MAX
+$cfg->setConfigEntry('tcp_connect_retry_max', 10);
+
+// CFG: UDP-CONNECT-RETRY-MAX
+$cfg->setConfigEntry('udp_connect_retry_max', 10);
+
// [EOF]
?>
protected final function getPackageInstance () {
return $this->packageInstance;
}
+
+ /**
+ * Shuts down a given socket resource. This method does only ease calling
+ * the right visitor.
+ *
+ * @param $socketResource A valid socket resource
+ * @return void
+ */
+ public function shutdownSocket ($socketResource) {
+ // Debug message
+ $this->debugOutput('Shutting down socket ' . $socketResource . ' ...');
+
+ // Set socket resource
+ $this->setSocketResource($socketResource);
+
+ // Get a visitor instance
+ $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
+
+ // Call the visitor
+ $this->accept($visitorInstance);
+ }
}
// [EOF]
*/
private $offset = 0;
+ /**
+ * Connect retries for this connection
+ */
+ private $retryCount = 0;
+
+ /**
+ * Wether this connection is shutted down
+ */
+ private $shuttedDown = false;
+
/**
* Protected constructor
*
$this->address = $address;
}
+ /**
+ * "Accept" a visitor by simply calling it back
+ *
+ * @param $visitorInstance A Visitable instance
+ * @return void
+ */
+ protected final function accept (Visitor $visitorInstance) {
+ // Just call the visitor
+ $visitorInstance->visitConnectionHelper($this);
+ }
+
/**
* Sends raw package data to the recipient
*
// Return it
return $class;
}
+
+ /**
+ * Checks wether the connect retry is exhausted
+ *
+ * @return $isExhaused Wether connect retry is exchausted
+ */
+ public final function isConnectRetryExhausted () {
+ // Construct config entry
+ $configEntry = $this->getProtocol() . '_connect_retry_max';
+
+ // Check it out
+ $isExhausted = ($this->retryCount >= $this->getConfigInstance()->getConfigEntry($configEntry));
+
+ // Return it
+ return $isExhausted;
+ }
+
+ /**
+ * Increases the connect retry count
+ *
+ * @return void
+ */
+ public final function increaseConnectRetry () {
+ $this->retryCount++;
+ }
+
+ /**
+ * Marks this connection as shutted down
+ *
+ * @return void
+ */
+ protected final function markConnectionShutdown () {
+ $this->shuttedDown = true;
+ }
+
+ /**
+ * Getter for shuttedDown
+ *
+ * @return $shuttedDown Wether this connection is shutted down
+ */
+ public final function isShuttedDown () {
+ return $this->shuttedDown;
+ }
}
// [EOF]
// Okay, that should be it. So return it...
return $socketResource;
}
+
+ /**
+ * Do the shutdown sequence for TCP connections
+ *
+ * @todo We may want to implement a filter for ease notification of other objects like our pool
+ * @return void
+ * @throws SocketShutdownException If the current socket could not be shut down
+ */
+ public function doShutdown () {
+ // Clear any previous errors
+ socket_clear_error($this->getSocketResource());
+
+ // Call the shutdown function on the currently set socket
+ if (!@socket_shutdown($this->getSocketResource())) {
+ // Could not shutdown socket, this is fine if e.g. the other side is not connected, so analyse it
+ if (socket_last_error($this->getSocketResource()) != 107) {
+ // Something bad happened while we shutdown a socket
+ throw new SocketShutdownException($this, BaseListener::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+ } // END - if
+
+ // Mark this connection as shutted down
+ $this->markConnectionShutdown();
+ }
}
// [EOF]
// Get the right connection instance
$connectionInstance = SocketRegistry::createSocketRegistry()->getHandlerInstanceFromPackageData($packageData);
+ // Is this connection still alive?
+ if ($connectionInstance->isShuttedDown()) {
+ // This connection is shutting down
+ // @TODO We may want to do somthing more here?
+ return;
+ } // END - if
+
// Sent it away (we catch exceptions one method above
$connectionInstance->sendRawPackageData($packageData);
}
/**
* Creates an instance of this class
*
- * @return $visitorInstance An instance a Visitorable class
+ * @return $visitorInstance An instance a Visitorable class
*/
public final static function create???Visitor () {
// Get new instance
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ShutdownSocket visitor
+ *
+ * @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 ShutdownSocketVisitor extends BaseVisitor implements Visitor {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set visitor mode
+ $this->setVisitorMode('ShutdownSocket');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $visitorInstance An instance a Visitorable class
+ */
+ public final static function createShutdownSocketVisitor () {
+ // Get new instance
+ $visitorInstance = new ShutdownSocketVisitor();
+
+ // Return the prepared instance
+ return $visitorInstance;
+ }
+
+ /**
+ * "Visit" method to do the actual request. Here we want to shutdown the
+ * attached socket.
+ *
+ * @param $helperInstance A BaseConnectionHelper instance
+ * @return void
+ */
+ public function visitConnectionHelper (BaseConnectionHelper $helperInstance) {
+ // Do we have reached the retry count?
+ if ($helperInstance->isConnectRetryExhausted()) {
+ // Shutdown the connection
+ $helperInstance->doShutdown();
+ } else {
+ // We can still move on and retry the connection attempt
+ $helperInstance->increaseConnectRetry();
+ }
+ }
+}
+
+// [EOF]
+?>