]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/listener/class_BaseListener.php
Use array_push() instead of [] as array_push() checks if parameter 1 is really an...
[hub.git] / application / hub / main / listener / class_BaseListener.php
index 97736134f488e4e58bdf17d851a6f50c3a71a745..6651198a5b7e7ad6144b3beabad770c3c547b54a 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
  */
 class BaseListener extends BaseHubSystem implements Visitable {
        // Exception code constants
-       const EXCEPTION_INVALID_SOCKET            = 0xa00;
-       const EXCEPTION_SOCKET_ALREADY_REGISTERED = 0xa01;
+       const EXCEPTION_INVALID_SOCKET                   = 0xa00;
+       const EXCEPTION_SOCKET_ALREADY_REGISTERED        = 0xa01;
+       const EXCEPTION_SOCKET_CREATION_FAILED           = 0xa02;
+       const EXCEPTION_NO_SOCKET_ERROR                  = 0xa03;
+       const EXCEPTION_CONNECTION_ALREADY_REGISTERED    = 0xa04;
+       const EXCEPTION_UNEXPECTED_PACKAGE_STATUS        = 0xa05;
+       const EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER = 0xa06;
+       const EXCEPTION_FINAL_CHUNK_VERIFICATION         = 0xa07;
+       const EXCEPTION_INVALID_DATA_CHECKSUM            = 0xa08;
 
        /**
         * Used protocol (Default: invalid, which is indeed invalid...)
         */
-       private $protcol = 'invalid';
+       private $protocol = 'invalid';
 
        /**
         * Address (IP mostly) we shall listen on
@@ -42,14 +49,14 @@ class BaseListener extends BaseHubSystem implements Visitable {
        private $listenPort = 0; // This port MUST be changed by your application
 
        /**
-        * Wether we are in blocking or non-blocking mode (default: non-blocking
+        * Whether we are in blocking or non-blocking mode (default: non-blocking
         */
        private $blockingMode = false;
 
        /**
         * A peer pool instance
         */
-       private $poolInstance = null;
+       private $poolInstance = NULL;
 
        /**
         * Protected constructor
@@ -63,10 +70,10 @@ class BaseListener extends BaseHubSystem implements Visitable {
        }
 
        /**
-        * Checks wether the given socket resource is a server socket
+        * Checks whether the given socket resource is a server socket
         *
         * @param       $socketResource         A valid socket resource
-        * @return      $isServerSocket         Wether the socket resource is a server socket
+        * @return      $isServerSocket         Whether the socket resource is a server socket
         */
        protected function isServerSocketResource ($socketResource) {
                // Check it
@@ -75,7 +82,7 @@ class BaseListener extends BaseHubSystem implements Visitable {
                // We need to clear the error here if it is a resource
                if ($isServerSocket === true) {
                        // Clear the error
-                       //* DEBUG: */ $this->debugOutput('socketResource[]=' . gettype($socketResource));
+                       //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('socketResource[]=' . gettype($socketResource));
                        socket_clear_error($socketResource);
                } // END - if
 
@@ -175,7 +182,7 @@ class BaseListener extends BaseHubSystem implements Visitable {
        /**
         * Setter for blocking-mode
         *
-        * @param       $blockingMode   Wether blocking-mode is disabled (default) or enabled
+        * @param       $blockingMode   Whether blocking-mode is disabled (default) or enabled
         * @return      void
         */
        protected final function setBlockingMode ($blockingMode) {
@@ -183,9 +190,9 @@ class BaseListener extends BaseHubSystem implements Visitable {
        }
 
        /**
-        * Checks wether blocking-mode is enabled or disabled
+        * Checks whether blocking-mode is enabled or disabled
         *
-        * @return      $blockingMode   Wether blocking mode is disabled or enabled
+        * @return      $blockingMode   Whether blocking mode is disabled or enabled
         */
        public final function isBlockingModeEnabled () {
                return $this->blockingMode;
@@ -235,13 +242,16 @@ class BaseListener extends BaseHubSystem implements Visitable {
 
                // Register the socket
                $registryInstance->registerSocket($this, $socketResource);
+
+               // And set it here
+               $this->setSocketResource($socketResource);
        }
 
        /**
-        * Checks wether given socket resource is registered in socket registry
+        * Checks whether given socket resource is registered in socket registry
         *
         * @param       $socketResource         A valid server socket resource
-        * @return      $isRegistered           Wether given server socket is registered
+        * @return      $isRegistered           Whether given server socket is registered
         */
        protected function isServerSocketRegistered ($socketResource) {
                // Get a socket registry instance (singleton)
@@ -254,22 +264,6 @@ class BaseListener extends BaseHubSystem implements Visitable {
                return $isRegistered;
        }
 
-       /**
-        * Getter for "this" socket resource
-        *
-        * @return      $socketResource         A valid socket resource
-        */
-       public final function getSocketResource () {
-               // Get a socket registry instance (singleton)
-               $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
-
-               // Get the socket resource
-               $socketResource = $registryInstance->getRegisteredSocketResource($this);
-
-               // Return it
-               return $socketResource;
-       }
-
        /**
         * Accepts the visitor to process the visit "request"
         *
@@ -278,7 +272,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: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($this->getProtocol()) . '-LISTENER[' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - START');
 
                // Visit this listener
                $visitorInstance->visitListener($this);
@@ -289,7 +283,20 @@ class BaseListener extends BaseHubSystem implements Visitable {
                } // END - if
 
                // Debug message
-               //* DEBUG: */ $this->debugOutput('LISTENER: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - FINISHED');
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($this->getProtocol()) . '-LISTENER[' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - FINISHED');
+       }
+
+       /**
+        * Monitors incoming raw data from the handler and transfers it to the
+        * given receiver instance. This method should not be called, please call
+        * the decorator's version instead to separator node/client traffic.
+        *
+        * @param       $receiverInstance       An instance of a Receivable class
+        * @return      void
+        * @throws      UnsupportedOperatorException    If this method is called by a mistake
+        */
+       public function monitorIncomingRawData (Receivable $receiverInstance) {
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $receiverInstance), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 }