]> git.mxchange.org Git - hub.git/commitdiff
Renamed FooNetworkPackageHandler to FooRawDataHandler, because it handles raw data...
authorRoland Häder <roland@mxchange.org>
Wed, 20 Apr 2011 05:13:56 +0000 (05:13 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 20 Apr 2011 05:13:56 +0000 (05:13 +0000)
13 files changed:
.gitattributes
application/hub/config.php
application/hub/main/handler/network/class_BaseNetworkPackageHandler.php
application/hub/main/handler/network/class_BaseRawDataHandler.php [new file with mode: 0644]
application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php
application/hub/main/handler/network/tcp/class_TcpRawDataHandler.php [new file with mode: 0644]
application/hub/main/handler/network/udp/class_UdpNetworkPackageHandler.php
application/hub/main/handler/network/udp/class_UdpRawDataHandler.php [new file with mode: 0644]
application/hub/main/listener/class_BaseListener.php
application/hub/main/listener/tcp/class_TcpListener.php
application/hub/main/listener/udp/class_UdpListener.php
application/hub/main/resolver/state/network/class_NetworkStateResolver.php
application/hub/main/streams/raw_data/input/class_RawDataInputStream.php

index fef3f0e888ba5403efeed9c1518b010dce536ca8..01068421cacd66951ef0ee8d0f642f322dc024d0 100644 (file)
@@ -261,11 +261,14 @@ application/hub/main/handler/class_BaseHandler.php svneol=native#text/plain
 application/hub/main/handler/network/.htaccess -text svneol=unset#text/plain
 application/hub/main/handler/network/class_ svneol=native#text/plain
 application/hub/main/handler/network/class_BaseNetworkPackageHandler.php svneol=native#text/plain
+application/hub/main/handler/network/class_BaseRawDataHandler.php svneol=native#text/plain
 application/hub/main/handler/network/tcp/.htaccess -text svneol=unset#text/plain
 application/hub/main/handler/network/tcp/class_ svneol=native#text/plain
 application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php svneol=native#text/plain
+application/hub/main/handler/network/tcp/class_TcpRawDataHandler.php svneol=native#text/plain
 application/hub/main/handler/network/udp/.htaccess -text svneol=unset#text/plain
 application/hub/main/handler/network/udp/class_UdpNetworkPackageHandler.php svneol=native#text/plain
+application/hub/main/handler/network/udp/class_UdpRawDataHandler.php svneol=native#text/plain
 application/hub/main/handler/tasks/.htaccess -text svneol=unset#text/plain
 application/hub/main/handler/tasks/class_TaskHandler.php svneol=native#text/plain
 application/hub/main/helper/.htaccess -text svneol=unset#text/plain
index 99051c87226bc5c41c305e5d0dfd07904ddbff94..8a13c14836e066d16c2b2f9b1a51f64e1086a619 100644 (file)
@@ -105,8 +105,11 @@ $cfg->setConfigEntry('handler_pool_iterator_class', 'HandlerPoolIterator');
 // CFG: NETWORK-LISTEN-ITERATOR-CLASS
 $cfg->setConfigEntry('network_listen_iterator_class', 'NetworkListenIterator');
 
-// CFG: NETWORK-PACKAGE-HANDLER-CLASS
-$cfg->setConfigEntry('tcp_network_package_handler_class', 'TcpNetworkPackageHandler');
+// CFG: TCP-RAW-DATA-HANDLER-CLASS
+$cfg->setConfigEntry('tcp_raw_data_handler_class', 'TcpRawDataHandler');
+
+// CFG: UDP-RAW-DATA-HANDLER-CLASS
+$cfg->setConfigEntry('udp_raw_data_handler_class', 'UdpRawDataHandler');
 
 // CFG: SHUTDOWN-LISTENER-POOL-VISITOR-CLASS
 $cfg->setConfigEntry('shutdown_listener_pool_visitor_class', 'ShutdownListenerPoolVisitor');
index c563faca7bec50d108ef45c493f2f056cf443653..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,146 +1,3 @@
 <?php
-/**
- * A general Handler
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-class BaseNetworkPackageHandler extends BaseHandler {
-       // Error codes:
-       // - Socket raw data stream errors
-       const SOCKET_ERROR_UNKNOWN                = 'unknown_error';      // Unknown error (should not happen)
-       const SOCKET_ERROR_TRANSPORT_ENDPOINT     = 'transport_endpoint'; // Transport endpoint has closed
-       const SOCKET_ERROR_EMPTY_DATA             = 'empty_data';         // Other peer has sent nothing
-       const SOCKET_ERROR_INVALID_BASE64_MODULO  = 'base64_modulo';      // Length is not modulo 4
-       const SOCKET_ERROR_INVALID_BASE64_MESSAGE = 'base64_message';     // Raw data is not Base64-encoded
-       const SOCKET_ERROR_UNHANDLED              = 'unhandled_package';  // Unhandled raw data (not bad)
-
-       // - Package errors
-       const PACKAGE_ERROR_INVALID_DATA       = 'invalid_data';    // Invalid data in package found
-       const PACKAGE_ERROR_INCOMPLETE_DATA    = 'incomplete_data'; // Incomplete data sent (e.g. field is missing)
-       const PACKAGE_ERROR_INVALID_CONTENT    = 'invalid_content'; // Content is invalid (e.g. not well-formed)
-       const PACKAGE_ERROR_RECIPIENT_MISMATCH = 'recipient_error'; // Recipient is not us
-       const PACKAGE_LEVEL_CHECK_OKAY         = 'checked_package'; // Package is fine
-
-       // Package data
-       const PACKAGE_DECODED_DATA = 'decoded_data';
-       const PACKAGE_ERROR_CODE   = 'error_code';
-
-       /**
-        * Error code from socket
-        */
-       private $errorCode = -1;
-
-       /**
-        * Protected constructor
-        *
-        * @param       $className      Name of the class
-        * @return      void
-        */
-       protected function __construct ($className) {
-               // Call parent constructor
-               parent::__construct($className);
-
-               // Set error code to 'unknown'
-               $this->setErrorCode(self::SOCKET_ERROR_UNKNOWN);
-
-               // Get an input stream instance
-               $streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_input_stream_class', array($this));
-
-               // Set it in this network-package handler
-               $this->setInputStreamInstance($streamInstance);
-
-               // Init stacker instance for processed raw data
-               $stackerInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_stacker_class');
-
-               // Remember this in this package handler
-               $this->setStackerInstance($stackerInstance);
-
-               // Init stacker
-               $this->initStacker();
-       }
-
-       /**
-        * Initializes the stacker for raw data
-        *
-        * @return      void
-        */
-       protected function initStacker () {
-               $this->getStackerInstance()->initStacker('raw_data');
-       }
-
-       /**
-        * Adds given decoded data to the raw data stacker
-        *
-        * @param       $decodedData    Decoded data from the socket resource
-        * @return      void
-        */
-       protected function addDecodedDataToStacker ($decodedData) {
-               /*
-                * Add the deocoded data and error code to the stacker so other classes
-                * (e.g. NetworkPackage) can "pop" it from the stacker.
-                */
-               $this->getStackerInstance()->pushNamed('raw_data', array(
-                       self::PACKAGE_DECODED_DATA => $decodedData,
-                       self::PACKAGE_ERROR_CODE   => $this->getErrorCode()
-               ));
-       }
-
-       /**
-        * Checks wether the 'recipient' field matches our own address:port
-        * combination.
-        *
-        * @param       $packageData    Raw package data
-        * @return      $matches                Wether it matches
-        * @todo        This method will be moved to a better place
-        */
-       protected function ifRecipientMatchesOwnAddress (array $packageData) {
-               // Construct own address first
-               $ownAddress = Registry::getRegistry()->getInstance('node')->getAddressPort($this);
-
-               // Does it match?
-               // @TODO Numeric or alpha-numeric index?
-               $matches = ($ownAddress === $packageData[NetworkPackage::INDEX_PACKAGE_RECIPIENT]);
-
-               // Return result
-               return $matches;
-       }
-
-       /**
-        * Setter for error code
-        *
-        * @param       $errorCode      The error code we shall set
-        * @return      void
-        */
-       protected final function setErrorCode ($errorCode) {
-               $this->errorCode = $errorCode;
-       }
-
-       /**
-        * Getter for error code
-        *
-        * @return      $errorCode      The error code
-        */
-       public final function getErrorCode () {
-               return $this->errorCode;
-       }
-}
-
-// [EOF]
+// @DEPRECATED
 ?>
diff --git a/application/hub/main/handler/network/class_BaseRawDataHandler.php b/application/hub/main/handler/network/class_BaseRawDataHandler.php
new file mode 100644 (file)
index 0000000..71c1552
--- /dev/null
@@ -0,0 +1,146 @@
+<?php
+/**
+ * A general Handler for raw data from sockets
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+class BaseRawDataHandler extends BaseHandler {
+       // Error codes:
+       // - Socket raw data stream errors
+       const SOCKET_ERROR_UNKNOWN                = 'unknown_error';      // Unknown error (should not happen)
+       const SOCKET_ERROR_TRANSPORT_ENDPOINT     = 'transport_endpoint'; // Transport endpoint has closed
+       const SOCKET_ERROR_EMPTY_DATA             = 'empty_data';         // Other peer has sent nothing
+       const SOCKET_ERROR_INVALID_BASE64_MODULO  = 'base64_modulo';      // Length is not modulo 4
+       const SOCKET_ERROR_INVALID_BASE64_MESSAGE = 'base64_message';     // Raw data is not Base64-encoded
+       const SOCKET_ERROR_UNHANDLED              = 'unhandled_package';  // Unhandled raw data (not bad)
+
+       // - Package errors
+       const PACKAGE_ERROR_INVALID_DATA       = 'invalid_data';    // Invalid data in package found
+       const PACKAGE_ERROR_INCOMPLETE_DATA    = 'incomplete_data'; // Incomplete data sent (e.g. field is missing)
+       const PACKAGE_ERROR_INVALID_CONTENT    = 'invalid_content'; // Content is invalid (e.g. not well-formed)
+       const PACKAGE_ERROR_RECIPIENT_MISMATCH = 'recipient_error'; // Recipient is not us
+       const PACKAGE_LEVEL_CHECK_OKAY         = 'checked_package'; // Package is fine
+
+       // Package data
+       const PACKAGE_DECODED_DATA = 'decoded_data';
+       const PACKAGE_ERROR_CODE   = 'error_code';
+
+       /**
+        * Error code from socket
+        */
+       private $errorCode = -1;
+
+       /**
+        * Protected constructor
+        *
+        * @param       $className      Name of the class
+        * @return      void
+        */
+       protected function __construct ($className) {
+               // Call parent constructor
+               parent::__construct($className);
+
+               // Set error code to 'unknown'
+               $this->setErrorCode(self::SOCKET_ERROR_UNKNOWN);
+
+               // Get an input stream instance
+               $streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_input_stream_class', array($this));
+
+               // Set it in this network-package handler
+               $this->setInputStreamInstance($streamInstance);
+
+               // Init stacker instance for processed raw data
+               $stackerInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_stacker_class');
+
+               // Remember this in this package handler
+               $this->setStackerInstance($stackerInstance);
+
+               // Init stacker
+               $this->initStacker();
+       }
+
+       /**
+        * Initializes the stacker for raw data
+        *
+        * @return      void
+        */
+       protected function initStacker () {
+               $this->getStackerInstance()->initStacker('raw_data');
+       }
+
+       /**
+        * Adds given decoded data to the raw data stacker
+        *
+        * @param       $decodedData    Decoded data from the socket resource
+        * @return      void
+        */
+       protected function addDecodedDataToStacker ($decodedData) {
+               /*
+                * Add the deocoded data and error code to the stacker so other classes
+                * (e.g. NetworkPackage) can "pop" it from the stacker.
+                */
+               $this->getStackerInstance()->pushNamed('raw_data', array(
+                       self::PACKAGE_DECODED_DATA => $decodedData,
+                       self::PACKAGE_ERROR_CODE   => $this->getErrorCode()
+               ));
+       }
+
+       /**
+        * Checks wether the 'recipient' field matches our own address:port
+        * combination.
+        *
+        * @param       $packageData    Raw package data
+        * @return      $matches                Wether it matches
+        * @todo        This method will be moved to a better place
+        */
+       protected function ifRecipientMatchesOwnAddress (array $packageData) {
+               // Construct own address first
+               $ownAddress = Registry::getRegistry()->getInstance('node')->getAddressPort($this);
+
+               // Does it match?
+               // @TODO Numeric or alpha-numeric index?
+               $matches = ($ownAddress === $packageData[NetworkPackage::INDEX_PACKAGE_RECIPIENT]);
+
+               // Return result
+               return $matches;
+       }
+
+       /**
+        * Setter for error code
+        *
+        * @param       $errorCode      The error code we shall set
+        * @return      void
+        */
+       protected final function setErrorCode ($errorCode) {
+               $this->errorCode = $errorCode;
+       }
+
+       /**
+        * Getter for error code
+        *
+        * @return      $errorCode      The error code
+        */
+       public final function getErrorCode () {
+               return $this->errorCode;
+       }
+}
+
+// [EOF]
+?>
index f11045886f99b030fa6435da1045d739b7592069..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,106 +1,3 @@
 <?php
-/**
- * A TCP network package handler
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-class TcpNetworkPackageHandler extends BaseNetworkPackageHandler implements Networkable {
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-
-               // Set handler name
-               $this->setHandlerName('tcp');
-       }
-
-       /**
-        * Creates an instance of this class
-        *
-        * @return      $handlerInstance        An instance of a Networkable class
-        */
-       public static final function createTcpNetworkPackageHandler () {
-               // Get new instance
-               $handlerInstance = new TcpNetworkPackageHandler();
-
-               // Return the prepared instance
-               return $handlerInstance;
-       }
-
-       /**
-        * Processes raw data from given resource. This is mostly useful for TCP
-        * package handling and is implemented in the TcpListener class
-        *
-        * @param       $resource       A valid resource identifier
-        * @return      void
-        */
-       public function processRawDataFromResource ($resource) {
-               // Check the resource
-               if (!is_resource($resource)) {
-                       // Throw an exception
-                       throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
-               } // END - if
-
-               // Reset error code to unhandled
-               $this->setErrorCode(self::SOCKET_ERROR_UNHANDLED);
-
-               // Init variables
-               $decodedData = false;
-
-               // Debug message
-               //* NOISY-DEBUG: */ $this->debugOutput('HANDLER: Handling TCP package from peer ' . $resource);
-
-               /*
-                * Read the raw data from socket. If you change PHP_BINARY_READ to
-                * PHP_NORMAL_READ, this line will endless block. We only have
-                * simultanous threads and no real threads.
-                */
-               $rawData = socket_read($resource, $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
-
-               // Debug output of read data length
-               //* NOISY-DEBUG: */ $this->debugOutput('LISTENER: rawData[]=' . strlen($rawData));
-
-               // Is it valid?
-               if (($rawData === false) || (socket_last_error($resource) > 0)) {
-                       // Network error or connection lost
-                       $this->setErrorCode(socket_last_error($resource));
-               } elseif (empty($rawData)) {
-                       // The peer did send nothing to us
-                       $this->setErrorCode(self::SOCKET_ERROR_EMPTY_DATA);
-               } else {
-                       /*
-                        * Low-level checks of the raw data went all fine, we can now
-                        * decode the raw data. This may still fail because of invalid
-                        * encoded data.
-                        */
-                       $decodedData = $this->getInputStreamInstance()->streamData($rawData);
-               }
-
-               // Add the (maybe above decoded) data to the stacker
-               $this->addDecodedDataToStacker($decodedData);
-       }
-}
-
-// [EOF]
+// @DEPRECATED
 ?>
diff --git a/application/hub/main/handler/network/tcp/class_TcpRawDataHandler.php b/application/hub/main/handler/network/tcp/class_TcpRawDataHandler.php
new file mode 100644 (file)
index 0000000..e37e6bc
--- /dev/null
@@ -0,0 +1,106 @@
+<?php
+/**
+ * A TCP raw data handler
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+class TcpRawDataHandler extends BaseRawDataHandler implements Networkable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set handler name
+               $this->setHandlerName('tcp');
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $handlerInstance        An instance of a Networkable class
+        */
+       public static final function createTcpRawDataHandler () {
+               // Get new instance
+               $handlerInstance = new TcpRawDataHandler();
+
+               // Return the prepared instance
+               return $handlerInstance;
+       }
+
+       /**
+        * Processes raw data from given resource. This is mostly useful for TCP
+        * package handling and is implemented in the TcpListener class
+        *
+        * @param       $resource       A valid resource identifier
+        * @return      void
+        */
+       public function processRawDataFromResource ($resource) {
+               // Check the resource
+               if (!is_resource($resource)) {
+                       // Throw an exception
+                       throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+               } // END - if
+
+               // Reset error code to unhandled
+               $this->setErrorCode(self::SOCKET_ERROR_UNHANDLED);
+
+               // Init variables
+               $decodedData = false;
+
+               // Debug message
+               //* NOISY-DEBUG: */ $this->debugOutput('HANDLER: Handling TCP package from peer ' . $resource);
+
+               /*
+                * Read the raw data from socket. If you change PHP_BINARY_READ to
+                * PHP_NORMAL_READ, this line will endless block. We only have
+                * simultanous threads and no real threads.
+                */
+               $rawData = socket_read($resource, $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
+
+               // Debug output of read data length
+               //* NOISY-DEBUG: */ $this->debugOutput('TCP-HANDLER: rawData[]=' . strlen($rawData));
+
+               // Is it valid?
+               if (($rawData === false) || (socket_last_error($resource) > 0)) {
+                       // Network error or connection lost
+                       $this->setErrorCode(socket_last_error($resource));
+               } elseif (empty($rawData)) {
+                       // The peer did send nothing to us
+                       $this->setErrorCode(self::SOCKET_ERROR_EMPTY_DATA);
+               } else {
+                       /*
+                        * Low-level checks of the raw data went all fine, we can now
+                        * decode the raw data. This may still fail because of invalid
+                        * encoded data.
+                        */
+                       $decodedData = $this->getInputStreamInstance()->streamData($rawData);
+               }
+
+               // Add the (maybe above decoded) data to the stacker
+               $this->addDecodedDataToStacker($decodedData);
+       }
+}
+
+// [EOF]
+?>
index 5bd1ea09bc7712ec8c622268a0f386caedb98434..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,73 +1,3 @@
 <?php
-/**
- * A UDP network package handler
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-class UdpNetworkPackageHandler extends BaseNetworkPackageHandler implements Networkable {
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-
-               // Set handler name
-               $this->setHandlerName('udp');
-       }
-
-       /**
-        * Creates an instance of this class
-        *
-        * @return      $handlerInstance                An instance of a Networkable class
-        */
-       public static final function createUdpNetworkPackageHandler () {
-               // Get new instance
-               $handlerInstance = new UdpNetworkPackageHandler();
-
-               // Return the prepared instance
-               return $handlerInstance;
-       }
-
-       /**
-        * Processes raw data from given resource. This is mostly useful for TCP
-        * package handling and is implemented in the TcpListener class
-        *
-        * @param       $resource       A valid resource identifier
-        * @return      void
-        * @throws      InvalidResourceException        If the given resource is invalid
-        * @todo        0%
-        */
-       public function processRawDataFromResource ($resource) {
-               // Check the resource
-               if (!is_resource($resource)) {
-                       // Throw an exception
-                       throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
-               } // END - if
-
-               // Implement processing here
-               $this->partialStub('Please implement this method. resource=' . $resource);
-       }
-}
-
-// [EOF]
+// @DEPRECATED
 ?>
diff --git a/application/hub/main/handler/network/udp/class_UdpRawDataHandler.php b/application/hub/main/handler/network/udp/class_UdpRawDataHandler.php
new file mode 100644 (file)
index 0000000..1c35eb6
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+/**
+ * A UDP raw data handler
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+class UdpRawDataHandler extends BaseRawDataHandler implements Networkable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set handler name
+               $this->setHandlerName('udp');
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $handlerInstance                An instance of a Networkable class
+        */
+       public static final function createUdpRawDataHandler () {
+               // Get new instance
+               $handlerInstance = new UdpRawDataHandler();
+
+               // Return the prepared instance
+               return $handlerInstance;
+       }
+
+       /**
+        * Processes raw data from given resource. This is mostly useful for TCP
+        * package handling and is implemented in the TcpListener class
+        *
+        * @param       $resource       A valid resource identifier
+        * @return      void
+        * @throws      InvalidResourceException        If the given resource is invalid
+        * @todo        0%
+        */
+       public function processRawDataFromResource ($resource) {
+               // Check the resource
+               if (!is_resource($resource)) {
+                       // Throw an exception
+                       throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+               } // END - if
+
+               // Implement processing here
+               $this->partialStub('Please implement this method. resource=' . $resource);
+       }
+}
+
+// [EOF]
+?>
index 9c5f3fade1138b18bd51eeebf1e36ce52dd4fa06..b81ffd2027d98f28c52c1a78a443f4fb2b481cad 100644 (file)
@@ -278,7 +278,7 @@ class BaseListener extends BaseHubSystem implements Visitable {
         */
        public function accept (Visitor $visitorInstance) {
                // Debug message
-               //* DEBUG: */ $this->debugOutput('LISTENER: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - START');
+               //* DEBUG: */ $this->debugOutput(strtoupper($this->getProtocol()) . '-LISTENER: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - START');
 
                // Visit this listener
                $visitorInstance->visitListener($this);
@@ -289,7 +289,7 @@ class BaseListener extends BaseHubSystem implements Visitable {
                } // END - if
 
                // Debug message
-               //* DEBUG: */ $this->debugOutput('LISTENER: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - FINISHED');
+               //* DEBUG: */ $this->debugOutput(strtoupper($this->getProtocol()) . '-LISTENER: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - FINISHED');
        }
 
        /**
index f8a9e21805a8092e3ce7f1c1a7d5da8c77f6cfe5..bdc20b462f98411783f950199ebb81097119a66e 100644 (file)
@@ -30,6 +30,9 @@ class TcpListener extends BaseListener implements Listenable {
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
+
+               // Set the protocol to TCP
+               $this->setProtocol('tcp');
        }
 
        /**
@@ -45,9 +48,6 @@ class TcpListener extends BaseListener implements Listenable {
                // Set the application instance
                $listenerInstance->setNodeInstance($nodeInstance);
 
-               // Set the protocol to TCP
-               $listenerInstance->setProtocol('tcp');
-
                // Return the prepared instance
                return $listenerInstance;
        }
@@ -95,7 +95,7 @@ class TcpListener extends BaseListener implements Listenable {
                // "Bind" the socket to the given address, on given port so this means
                // that all connections on this port are now our resposibility to
                // send/recv data, disconnect, etc..
-               $this->debugOutput('LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
+               $this->debugOutput('TCP-LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
                if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) {
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
@@ -111,7 +111,7 @@ class TcpListener extends BaseListener implements Listenable {
                } // END - if
 
                // Start listen for connections
-               $this->debugOutput('LISTENER: Listening for connections.');
+               $this->debugOutput('TCP-LISTENER: Listening for connections.');
                if (!socket_listen($mainSocket)) {
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
@@ -127,7 +127,7 @@ class TcpListener extends BaseListener implements Listenable {
                } // END - if
 
                // Now, we want non-blocking mode
-               $this->debugOutput('LISTENER: Setting non-blocking mode.');
+               $this->debugOutput('TCP-LISTENER: Setting non-blocking mode.');
                if (!socket_set_nonblock($mainSocket)) {
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
@@ -162,13 +162,13 @@ class TcpListener extends BaseListener implements Listenable {
                $this->setIteratorInstance($iteratorInstance);
 
                // Initialize the network package handler
-               $handlerInstance = ObjectFactory::createObjectByConfiguredName('tcp_network_package_handler_class');
+               $handlerInstance = ObjectFactory::createObjectByConfiguredName('tcp_raw_data_handler_class');
 
                // Set it in this class
                $this->setHandlerInstance($handlerInstance);
 
                // Output message
-               $this->debugOutput('LISTENER: TCP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
+               $this->debugOutput('TCP-LISTENER: TCP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
        }
 
        /**
@@ -202,7 +202,7 @@ class TcpListener extends BaseListener implements Listenable {
                if (in_array($this->getSocketResource(), $readers)) {
                        // Then accept it
                        $newSocket = socket_accept($this->getSocketResource());
-                       //* NOISY-DEBUG: */ $this->debugOutput('LISTENER: newSocket=' . $newSocket);
+                       //* NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: newSocket=' . $newSocket);
 
                        // We want non-blocking here, too
                        if (!socket_set_nonblock($newSocket)) {
@@ -235,7 +235,7 @@ class TcpListener extends BaseListener implements Listenable {
                // Handle it here, if not main socket
                if ($currentSocket != $this->getSocketResource()) {
                        // ... or else it will raise warnings like 'Transport endpoint is not connected'
-                       //* NOISY-DEBUG: */ $this->debugOutput('LISTENER: currentSocket=' . $currentSocket);
+                       //* NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: currentSocket=' . $currentSocket);
                        $this->getHandlerInstance()->processRawDataFromResource($currentSocket);
                } // END - if
 
index df27bf096ad8a866214e5b0c4e22027355768489..4e8c52b6a777924218e9a7d493d31bf90608efa3 100644 (file)
@@ -30,6 +30,9 @@ class UdpListener extends BaseListener implements Listenable {
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
+
+               // Set the protocol to UDP
+               $this->setProtocol('udp');
        }
 
        /**
@@ -45,9 +48,6 @@ class UdpListener extends BaseListener implements Listenable {
                // Set the application instance
                $listenerInstance->setNodeInstance($nodeInstance);
 
-               // Set the protocol to UDP
-               $listenerInstance->setProtocol('udp');
-
                // Return the prepared instance
                return $listenerInstance;
        }
@@ -70,7 +70,7 @@ class UdpListener extends BaseListener implements Listenable {
                } // END - if
 
                // Set the option to reuse the port
-               $this->debugOutput('LISTENER: Setting re-use address option.');
+               $this->debugOutput('UDP-LISTENER: Setting re-use address option.');
                if (!socket_set_option($mainSocket, SOL_SOCKET, SO_REUSEADDR, 1)) {
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
@@ -88,7 +88,7 @@ class UdpListener extends BaseListener implements Listenable {
                // "Bind" the socket to the given address, on given port so this means
                // that all connections on this port are now our resposibility to
                // send/recv data, disconnect, etc..
-               $this->debugOutput('LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
+               $this->debugOutput('UDP-LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
                if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) {
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
@@ -104,7 +104,7 @@ class UdpListener extends BaseListener implements Listenable {
                } // END - if
 
                // Now, we want non-blocking mode
-               $this->debugOutput('LISTENER: Setting non-blocking mode.');
+               $this->debugOutput('UDP-LISTENER: Setting non-blocking mode.');
                if (!socket_set_nonblock($mainSocket)) {
                        // Get socket error code for verification
                        $socketError = socket_last_error($socket);
@@ -122,8 +122,14 @@ class UdpListener extends BaseListener implements Listenable {
                // Remember the socket in our class
                $this->registerServerSocketResource($mainSocket);
 
+               // Initialize the network package handler
+               $handlerInstance = ObjectFactory::createObjectByConfiguredName('udp_raw_data_handler_class');
+
+               // Set it in this class
+               $this->setHandlerInstance($handlerInstance);
+
                // Output message
-               $this->debugOutput('LISTENER: UDP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
+               $this->debugOutput('UDP-LISTENER: UDP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
        }
 
        /**
@@ -153,7 +159,7 @@ class UdpListener extends BaseListener implements Listenable {
                        return;
                } elseif ($lastError > 0) {
                        // Other error detected
-                       $this->debugOutput('LISTENER: Error detected: ' . socket_strerror($lastError));
+                       $this->debugOutput('UDP-LISTENER: Error detected: ' . socket_strerror($lastError));
 
                        // Skip further processing
                        return;
@@ -163,7 +169,7 @@ class UdpListener extends BaseListener implements Listenable {
                } // END - if
 
                // Debug only
-               $this->debugOutput('LISTENER: Handling UDP package with size ' . strlen($pkt) . ' from peer ' . $peer . ':' . $port);
+               $this->debugOutput('UDP-LISTENER: Handling UDP package with size ' . strlen($pkt) . ' from peer ' . $peer . ':' . $port);
        }
 
        /**
index 8fcdbccaac1cd0643f8db3b1538176663d1a3683..9b592b6f8ed311f99963c090a4afd24bf98fc4e8 100644 (file)
@@ -78,13 +78,13 @@ class NetworkStateResolver extends BaseStateResolver implements StateResolver {
                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)) {
                        // 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
 
                // Create a state instance based on $errorCode. This factory does the hard work for us
index c6b199ec1cb7e16e2d7f1a930d72b9266882ae7d..17fd7541028210f9a814460b7ce29aea596ba3ab 100644 (file)
@@ -60,11 +60,11 @@ class RawDataInputStream extends BaseStream implements InputStreamable {
                // Can it be validated?
                if ((strlen($data) % 4) != 0) {
                        // Length modulo 4 must be zero, else it is an invalid Base64 message
-                       $this->getHandlerInstance()->setErrorCode(BaseNetworkPackageHandler::SOCKET_ERROR_INVALID_BASE64_MODULO);
+                       $this->getHandlerInstance()->setErrorCode(BaseRawDataHandler::SOCKET_ERROR_INVALID_BASE64_MODULO);
                        $data = false;
                } elseif (!$this->isBase64Encoded($data)) {
                        // Is not a valid Base64-encoded message
-                       $this->getHandlerInstance()->setErrorCode(BaseNetworkPackageHandler::SOCKET_ERROR_INVALID_BASE64_MESSAGE);
+                       $this->getHandlerInstance()->setErrorCode(BaseRawDataHandler::SOCKET_ERROR_INVALID_BASE64_MESSAGE);
                        $data = false;
                } else {
                        // Decode the data with BASE64-encoding