]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 3 Nov 2020 17:57:15 +0000 (18:57 +0100)
committerRoland Häder <roland@mxchange.org>
Tue, 3 Nov 2020 17:57:15 +0000 (18:57 +0100)
- renamed getSocketPeerName() to determineSocketPeerName()
- improved/added debug lines
- sorted members a little

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/container/socket/class_SocketContainer.php
application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseWrapper.php
application/hub/classes/info/connection/class_ConnectionInfo.php
application/hub/classes/listener/class_BaseListener.php
application/hub/classes/package/assembler/class_PackageAssembler.php
application/hub/classes/pools/peer/class_DefaultPeerPool.php
application/hub/exceptions/package/class_UnsupportedPackageCodeHandlerException.php
application/hub/interfaces/container/socket/class_StorableSocket.php

index 7268f614e5c863aeac29564464275fa4565a2b33..e3e9506cf43b78d1f51b6a611c2e56809bd1e5cc 100644 (file)
@@ -163,25 +163,6 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                return $socketInstance;
        }
 
-       /**
-        * Setter for package data instance
-        *
-        * @param       $packageDataInstance    An instance of a DeliverablePackage class
-        * @return      void
-        */
-       public function setPackageDataInstance (DeliverablePackage $packageDataInstance) {
-               $this->packageDataInstance = $packageDataInstance;
-       }
-
-       /**
-        * Getter for package data instance
-        *
-        * @return      $packageDataInstance    An instance of a DeliverablePackage class
-        */
-       public function getPackageDataInstance () {
-               return $this->packageDataInstance;
-       }
-
        /**
         * Checks whether the given Universal Node Locator matches with the one from package data
         *
@@ -238,7 +219,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                $this->accept($visitorInstance);
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: EXIT!', strtoupper($this->getSocketProtocol())));
        }
 
        /**
@@ -261,7 +242,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                $this->accept($visitorInstance);
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: EXIT!', strtoupper($this->getSocketProtocol())));
        }
 
        /**
@@ -287,9 +268,9 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @return      $result                 Result from asking for peer address
         * @throws      InvalidSocketException  If socket is invalid
         */
-       public function getSocketPeerName (&$peerAddress, &$peerPort) {
+       public function determineSocketPeerName (&$peerAddress, &$peerPort) {
                // Should be valid socket
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: peerAddress[%s]=%s,peerPort[%s]=%d - CALLED!', strtoupper($this->getSocketProtocol()), gettype($peerAddress), $peerAddress, gettype($peerPort), $peerPort));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: peerAddress[%s]=%s,peerPort[%s]=%d - CALLED!', strtoupper($this->getSocketProtocol()), gettype($peerAddress), $peerAddress, gettype($peerPort), $peerPort));
                if (!$this->isValidSocket()) {
                        // Throw exception
                        throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
@@ -312,7 +293,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                }
 
                // Return result
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: peerAddress=%s,peerPort=%d,result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), $peerAddress, $peerPort, gettype($result), intval($result)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: peerAddress=%s,peerPort=%d,result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), $peerAddress, $peerPort, gettype($result), intval($result)));
                return $result;
        }
 
@@ -356,10 +337,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      InvalidSocketException  If socket is invalid
         */
        public function getSocketRecipientAddress () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
                // Should be valid socket
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                if (!$this->isValidSocket()) {
                        // Throw exception
                        throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
@@ -374,10 +353,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                // Get address part
                $recipientAddress = $locatorInstance->getUnlAddress();
 
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: recipientAddress=%s - EXIT!', strtoupper($this->getSocketProtocol()), $recipientAddress));
-
                // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: recipientAddress=%s - EXIT!', strtoupper($this->getSocketProtocol()), $recipientAddress));
                return $recipientAddress;
        }
 
@@ -388,10 +365,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      InvalidSocketException  If socket is invalid
         */
        public function getSocketRecipientPort () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
                // Should be valid socket
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                if (!$this->isValidSocket()) {
                        // Throw exception
                        throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
@@ -406,10 +381,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                // Get port part
                $recipientPort = $locatorInstance->getUnlPort();
 
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: recipientPort=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($recipientPort)));
-
                // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: recipientPort=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($recipientPort)));
                return $recipientPort;
 
        }
@@ -420,20 +393,16 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @return      $isValidSocket  Whether the stored socket is valid
         */
        public function isValidSocket () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
                // Get socket resource
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                $socketResource = $this->getSocketResource();
 
                // Is it valid?
                // @TODO maybe add more checks? is_resource() is still to less
                $isValidSocket = (is_resource($socketResource));
 
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: isValidSocket=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($isValidSocket)));
-
                // Return status
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: isValidSocket=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($isValidSocket)));
                return $isValidSocket;
        }
 
@@ -444,10 +413,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      InvalidSocketException  If socket is invalid
         */
        public function getLastSocketErrorCode () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
                // Should be valid socket
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                if (!$this->isValidSocket()) {
                        // Throw exception
                        throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
@@ -459,10 +426,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                // Get error code
                $errorCode = socket_last_error($socketResource);
 
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: errorCode=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($errorCode)));
-
                // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: errorCode=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($errorCode)));
                return $errorCode;
        }
 
@@ -473,10 +438,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      InvalidSocketException  If socket is invalid
         */
        public function getLastSocketErrorMessage () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
                // Should be valid socket
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                if (!$this->isValidSocket()) {
                        // Throw exception
                        throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
@@ -489,6 +452,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                $errorMessage = socket_strerror($this->getLastSocketErrorCode());
 
                // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: errorMessage=%s - EXIT!', strtoupper($this->getSocketProtocol()), $errorMessage));
                return $errorMessage;
        }
 
@@ -498,19 +462,15 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @return      $codeName       Code name to used e.g. with some_$codeName_socket_error_class or so
         */
        public function translateLastSocketErrorCodeToName () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
                // Get last error code
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                $errorCode = $this->getLastSocketErrorCode();
 
                // Call "translate" method
                $codeName = $this->translateSocketErrorCodeToName($errorCode);
 
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: codeName=%s - EXIT!', strtoupper($this->getSocketProtocol()), $codeName));
-
                // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: codeName=%s - EXIT!', strtoupper($this->getSocketProtocol()), $codeName));
                return $codeName;
        }
 
@@ -539,7 +499,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                $result = socket_bind($this->getSocketResource(), $this->getSocketFile());
 
                // Return result
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($result)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
                return $result;
        }
 
@@ -572,7 +532,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                $result = socket_bind($this->getSocketResource(), $address, $port);
 
                // Return result
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($result)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
                return $result;
        }
 
@@ -583,10 +543,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      InvalidSocketException  If stored socket is invalid
         */
        public function listenToSocket () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
                // Should be valid socket
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                if (!$this->isValidSocket()) {
                        // Throw exception
                        throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
@@ -595,10 +553,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                // Try to listen on socket
                $result = socket_listen($this->getSocketResource());
 
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($result)));
-
                // Return result
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
                return $result;
        }
 
@@ -609,10 +565,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      InvalidSocketException  If stored socket is invalid
         */
        public function enableSocketNonBlocking () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
                // Should be valid socket
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                if (!$this->isValidSocket()) {
                        // Throw exception
                        throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
@@ -621,10 +575,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                // Try to set non-blocking I/O
                $result = socket_set_nonblock($this->getSocketResource());
 
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($result)));
-
                // Return result
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
                return $result;
        }
 
@@ -635,10 +587,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      InvalidSocketException  If stored socket is invalid
         */
        public function enableSocketReuseAddress () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
                // Should be valid socket
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                if (!$this->isValidSocket()) {
                        // Throw exception
                        throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
@@ -647,10 +597,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                // Tries to set option
                $result = $this->setSocketOption(SOL_SOCKET, SO_REUSEADDR, 1);
 
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($result)));
-
                // Return result
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
                return $result;
        }
 
@@ -680,7 +628,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                $result = socket_connect($this->getSocketResource(), $locatorInstance->getUnlAddress(), $locatorInstance->getUnlPort());
 
                // Return result
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($result)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
                return $result;
        }
 
@@ -722,7 +670,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                socket_set_block($this->getSocketResource());
 
                // Drop all data (don't sent any on socket closure)
-               socket_set_option($this->getSocketResource(), SOL_SOCKET, SO_LINGER, array('l_onoff' => 1, 'l_linger' => 0));
+               $this->setSocketOption(SOL_SOCKET, SO_LINGER, array('l_onoff' => 1, 'l_linger' => 0));
 
                // Finally close socket to free some resources
                socket_close($this->getSocketResource());
@@ -731,7 +679,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                $this->markConnectionShuttedDown();
 
                // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: EXIT!', strtoupper($this->getSocketProtocol())));
        }
 
        /**
@@ -854,7 +802,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                $peerPort    = '0';
 
                // Call other method
-               $result = $this->getSocketPeerName($peerAddress, $peerPort);
+               $result = $this->determineSocketPeerName($peerAddress, $peerPort);
 
                // Valid?
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d,peerAddress[%s]=%s,peerPort[%s]=%d', strtoupper($this->getSocketProtocol()), intval($result), gettype($peerAddress), $peerAddress, gettype($peerPort), $peerPort));
@@ -865,7 +813,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                } // END - if
 
                // Return result
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($result)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
                return $result;
        }
 
@@ -889,10 +837,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                // Call inner method
                $result = $this->setSocketOption(SOL_SOCKET, SO_RCVTIMEO, $options);
 
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($result)));
-
                // Return result
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
                return $result;
        }
 
@@ -909,7 +855,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                // Trace message
 
                // Return result
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($result)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
                return $result;
        }
 
@@ -968,7 +914,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                }
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: EXIT!', strtoupper($this->getSocketProtocol())));
        }
 
        /**
@@ -986,11 +932,9 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      InvalidArgumentException        If an array element is missing
         */
        public function writeBufferToSocketByArray (array &$socketBuffer, &$sentBytes) {
-               // Trace message
+               // Should be valid socket
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socketBuffer()=%d,sentBytes=%d - CALLED!', strtoupper($this->getSocketProtocol()), count($socketBuffer), $sentBytes));
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socketBuffer=%s', strtoupper($this->getSocketProtocol()), print_r($socketBuffer, TRUE)));
-
-               // Should be valid socket
                if (!$this->isValidSocket()) {
                        // Throw exception
                        throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
@@ -1008,21 +952,15 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                        throw new InvalidArgumentException(sprintf('socketBuffer[%s] is not set.', NetworkPackageHandler::RAW_INDEX_SENT_BYTES));
                }
 
-               // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Sending out %d bytes,rawBufferSize=%d,diff=%d to socketResource=%s', strtoupper($this->getSocketProtocol()), strlen($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA]), $socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE], $socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF], $this->getSocketResource()));
-
                // Is some data still pending or sent all out?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Sending out %d bytes,rawBufferSize=%d,diff=%d to socketResource=%s', strtoupper($this->getSocketProtocol()), strlen($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA]), $socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE], $socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF], $this->getSocketResource()));
                if ($socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF] >= 0) {
-                       // Debug message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: MD5=%s', strtoupper($this->getSocketProtocol()), md5(substr($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA], 0, ($socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE] - $socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF])))));
-
                        // Send all out (encodedData is smaller than or equal buffer size)
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: MD5=%s', strtoupper($this->getSocketProtocol()), md5(substr($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA], 0, ($socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE] - $socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF])))));
                        $sentBytes = socket_write($this->getSocketResource(), $socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA], ($socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE] - $socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF]));
                } else {
-                       // Debug message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: MD5=%s', strtoupper($this->getSocketProtocol()), md5(substr($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA], 0, $socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE]))));
-
                        // Send buffer size out
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: MD5=%s', strtoupper($this->getSocketProtocol()), md5(substr($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA], 0, $socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE]))));
                        $sentBytes = socket_write($this->getSocketResource(), $socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA], $socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE]);
                }
 
@@ -1030,21 +968,15 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                // @TODO Maybe check more?
                $result = ($sentBytes !== FALSE);
 
-               // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: sentBytes[%s]=%d,result=%d', strtoupper($this->getSocketProtocol()), gettype($sentBytes), $sentBytes, intval($result)));
-
                // If there was an error, don't continue here
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: sentBytes[%s]=%d,result=%d', strtoupper($this->getSocketProtocol()), gettype($sentBytes), $sentBytes, intval($result)));
                if ($result === FALSE) {
-                       // Trace message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socket_write() failed, please evalutate. - EXIT!', strtoupper($this->getSocketProtocol())));
-
                        // Failed delivery!
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socket_write() failed, please evalutate. - EXIT!', strtoupper($this->getSocketProtocol())));
                        return FALSE;
                } elseif (($sentBytes === 0) && (strlen($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA]) > 0)) {
-                       // Trace message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: All sent, returning TRUE ... - EXIT!', strtoupper($this->getSocketProtocol())));
-
                        // Nothing sent means all data has been sent
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: All sent, returning TRUE ... - EXIT!', strtoupper($this->getSocketProtocol())));
                        return TRUE;
                } else {
                        // The difference between sent bytes and length of raw data should not go below zero
@@ -1053,20 +985,16 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                        // Add total sent bytes
                        $socketBuffer[NetworkPackageHandler::RAW_INDEX_SENT_BYTES] += $sentBytes;
 
-                       // Debug message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Sent out %d of %d bytes ...', strtoupper($this->getSocketProtocol()), $sentBytes, strlen($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA])));
-
                        // Cut out the last unsent bytes
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Sent out %d of %d bytes ...', strtoupper($this->getSocketProtocol()), $sentBytes, strlen($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA])));
                        $socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA] = substr($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA], $sentBytes);
 
                        // Calculate difference again
                        $socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF] = $socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE] - strlen($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA]);
                }
 
-               // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($result)));
-
                // Return result
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
                return $result;
        }
 
@@ -1083,10 +1011,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      NoSocketErrorDetectedException  If socket_last_error() gives zero back
         */
        public function handleSocketError ($method, $line) {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-SYSTEM: Handling socket errorCode=%d - CALLED!', $this->getLastSocketErrorCode()));
-
                // This method handles only socket resources
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-SYSTEM: Handling socket errorCode=%d - CALLED!', $this->getLastSocketErrorCode()));
                if (!$this->isValidSocket()) {
                        // No resource, abort here
                        throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
@@ -1111,7 +1037,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                $this->clearLastSocketError();
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: EXIT!', strtoupper($this->getSocketProtocol())));
        }
 
        /**
@@ -1123,10 +1049,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      UnsupportedSocketErrorHandlerException If the error handler is not implemented
         */
        protected function getSocketErrorHandlerFromCode ($errorCode) {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: errorCode=%d - CALLED!', strtoupper($this->getSocketProtocol()), $errorCode));
-
                // Create a name from translated error code
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: errorCode=%d - CALLED!', strtoupper($this->getSocketProtocol()), $errorCode));
                $handlerName = 'handleSocketError' . self::convertToClassName($this->translateSocketErrorCodeToName($errorCode));
 
                // Is the call-back method there?
@@ -1135,10 +1059,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                        throw new UnsupportedSocketErrorHandlerException(array($this, $handlerName, $errorCode), BaseConnectionHelper::EXCEPTION_UNSUPPORTED_ERROR_HANDLER);
                } // END - if
 
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: handlerName=%d - EXIT!', strtoupper($this->getSocketProtocol()), $handlerName));
-
                // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: handlerName=%d - EXIT!', strtoupper($this->getSocketProtocol()), $handlerName));
                return $handlerName;
        }
 
@@ -1154,10 +1076,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      SocketBindingException  The socket could not be bind to
         */
        protected function handleSocketErrorPermissionDenied () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
                // Get socket error code for verification
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                $socketError = $this->getLastSocketErrorCode();
 
                // Get error message
@@ -1178,10 +1098,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      SocketConnectionException       The connection attempts fails with a time-out
         */
        protected function handleSocketErrorConnectionTimedOut () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
                // Get socket error code for verification
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                $socketError = $this->getLastSocketErrorCode();
 
                // Get error message
@@ -1202,10 +1120,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      SocketConnectionException       The connection attempts fails with a time-out
         */
        protected function handleSocketErrorResourceUnavailable () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
                // Get socket error code for verification
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                $socketError = $this->getLastSocketErrorCode();
 
                // Get error message
@@ -1226,10 +1142,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      SocketConnectionException       The connection attempts fails with a time-out
         */
        protected function handleSocketErrorConnectionRefused () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
                // Get socket error code for verification
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                $socketError = $this->getLastSocketErrorCode();
 
                // Get error message
@@ -1250,10 +1164,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      SocketConnectionException       The connection attempts fails with a time-out
         */
        protected function handleSocketErrorNoRouteToHost () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
                // Get socket error code for verification
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                $socketError = $this->getLastSocketErrorCode();
 
                // Get error message
@@ -1274,9 +1186,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      SocketConnectionException       The connection attempts fails with a time-out
         */
        protected function handleSocketErrorOperationAlreadyProgress () {
-               // Trace message
-
                // Get socket error code for verification
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                $socketError = $this->getLastSocketErrorCode();
 
                // Get error message
@@ -1297,10 +1208,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      SocketConnectionException       The connection attempts fails with a time-out
         */
        protected function handleSocketErrorConnectionResetByPeer () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
                // Get socket error code for verification
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                $socketError = $this->getLastSocketErrorCode();
 
                // Get error message
@@ -1426,16 +1335,6 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                return $errorName;
        }
 
-       /**
-        * Setter for socket protocol field
-        *
-        * @param       $socketProtocol         Socket protocol
-        * @return      void
-        */
-       private function setSocketProtocol ($socketProtocol) {
-               $this->socketProtocol = $socketProtocol;
-       }
-
        /**
         * Tries to set given socket option
         *
@@ -1446,10 +1345,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @throws      InvalidSocketException  If stored socket is invalid
         */
        private function setSocketOption ($level, $optionName, $optionValue) {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: level=%s,optionName=%s,optionValue[%s]=%s - CALLED!', strtoupper($this->getSocketProtocol()), $level, $optionName, gettype($optionValue), implode(',', $optionValue)));
-
                // Should be valid socket
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: level=%s,optionName=%s,optionValue[]=%s - CALLED!', strtoupper($this->getSocketProtocol()), $level, $optionName, gettype($optionValue)));
                if (!$this->isValidSocket()) {
                        // Throw exception
                        throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
@@ -1459,9 +1356,39 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                $result = socket_set_option($this->getSocketResource(), $level, $optionName, $optionValue);
 
                // Return result
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
                return $result;
        }
 
+       /**
+        * Setter for socket protocol field
+        *
+        * @param       $socketProtocol         Socket protocol
+        * @return      void
+        */
+       private function setSocketProtocol ($socketProtocol) {
+               $this->socketProtocol = $socketProtocol;
+       }
+
+       /**
+        * Setter for package data instance
+        *
+        * @param       $packageDataInstance    An instance of a DeliverablePackage class
+        * @return      void
+        */
+       public function setPackageDataInstance (DeliverablePackage $packageDataInstance) {
+               $this->packageDataInstance = $packageDataInstance;
+       }
+
+       /**
+        * Getter for package data instance
+        *
+        * @return      $packageDataInstance    An instance of a DeliverablePackage class
+        */
+       public function getPackageDataInstance () {
+               return $this->packageDataInstance;
+       }
+
        /**
         * Getter for socket file instance
         *
index 3ff61b5390fcbffacc6b3e048fb5cc1770722822..90d47ab2ef0f21e4b8368e829b8292cc9e5c86bd 100644 (file)
@@ -160,7 +160,7 @@ class PeerStateLookupDatabaseWrapper extends BaseHubDatabaseWrapper implements L
                $peerPort    = '0';
 
                // Get peer name
-               if (!$socketInstance->getSocketPeerName($peerAddress, $peerPort)) {
+               if (!$socketInstance->determineSocketPeerName($peerAddress, $peerPort)) {
                        // ... and cleartext message from it and put both into criteria
                        $dataSetInstance->addCriteria(self::DB_COLUMN_SOCKET_ERROR_CODE, $socketInstance->getLastSocketErrorCode());
                        $dataSetInstance->addCriteria(self::DB_COLUMN_SOCKET_ERROR_MSG , $socketInstance->getLastSocketErrorMessage());
index 2952f829cb3955638ab03a12885e775f5b4c8274..87ab06435a4d871a91eece3700b89ffdfa1e9a2a 100644 (file)
@@ -139,12 +139,12 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable {
         */
        public function fillWithSocketPeerInformation (StorableSocket $socketInstance) {
                // Init variables
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO: socketInstance->socketResource=%s - CALLED!', $socketInstance->getSocketResource()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO: socketInstance=%s - CALLED!', $socketInstance->__toString()));
                $socketAddress = '0.0.0.0';
                $socketPort    = '0';
 
                // Get peer name
-               if (!$socketInstance->getSocketPeerName($socketAddress, $socketPort)) {
+               if (!$socketInstance->determineSocketPeerName($socketAddress, $socketPort)) {
                        // Did not work
                        throw new InvalidSocketException(array($this, $socketInstance->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
                } // END - if
index 8cd3f4bb0e2846896050e595dc14e4f4254ac21c..cf91676fd3f2b5192312ca940984c099b4d847ac 100644 (file)
@@ -385,7 +385,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable {
                $peerPort    = '0';
 
                // Get peer name
-               if (!$socketInstance->getSocketPeerName($peerAddress, $peerPort)) {
+               if (!$socketInstance->determineSocketPeerName($peerAddress, $peerPort)) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
                } // END - if
index b2ea0caaee47f4be35685cc8d201cdb451924a25..208c776ea99cb934791eeee1e703b81741b4cab4 100644 (file)
@@ -6,6 +6,7 @@ namespace Org\Shipsimu\Hub\Network\Package\Receiver\Assembler;
 use Org\Shipsimu\Hub\Container\Socket\StorableSocket;
 use Org\Shipsimu\Hub\Factory\Handler\Chunk\ChunkHandlerFactory;
 use Org\Shipsimu\Hub\Generic\BaseHubSystem;
+use Org\Shipsimu\Hub\Handler\Network\PackageCode\UnsupportedPackageCodeHandlerException;
 use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData;
 use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
@@ -18,6 +19,9 @@ use Org\Mxchange\CoreFramework\Registry\Registerable;
 use Org\Mxchange\CoreFramework\Visitor\Visitable;
 use Org\Mxchange\CoreFramework\Visitor\Visitor;
 
+// Import SPL stuff
+use \BadMethodCallException;
+
 /**
  * A PackageAssembler class to assemble a package content stream fragemented
  * by PackageFragmenter back to a raw package data array.
@@ -51,7 +55,9 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable,
        const EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER = 0xf2200;
 
        /**
-        * Pending data
+        * Pending raw data, when this data is finished being collected
+        * ("assembled") then there should be one start-marker at the beginning and
+        * one end-marker at the end of the string.
         */
        private $pendingData = '';
 
@@ -117,10 +123,8 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable,
                // Check it
                $isInputBufferEmpty = $this->getPackageHandlerInstance()->getStackInstance()->isStackEmpty(NetworkPackageHandler::STACKER_NAME_DECODED_HANDLED);
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: isInputBufferEmpty=' . intval($isInputBufferEmpty));
-
                // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: isInputBufferEmpty=%d - EXIT!', intval($isInputBufferEmpty)));
                return $isInputBufferEmpty;
        }
 
@@ -148,22 +152,32 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable,
         * chunks and (maybe) re-request some chunks from the sender, this would
         * take to much time and therefore slow down this node again.
         *
-        * @param       $packageInstance                An array with two elements: 'raw_data' and 'error_code'
+        * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      void
         * @throws      UnsupportedPackageCodeHandlerException  If the package code handler is not implemented
         */
        public function chunkPackageInstance (DeliverablePackage $packageInstance) {
                // Construct call-back name from package error code
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $this->callbacks[$packageInstance->getErrorCode()] = 'handlePackageBy' . self::convertToClassName($packageInstance->getErrorCode());
 
+               // Init callable array
+               $callable = [
+                       $this,
+                       $this->callbacks[$packageInstance->getErrorCode()],
+               ];
+
                // Abort if the call-back method is not there
-               if (!method_exists($this, $this->callbacks[$packageInstance->getErrorCode()])) {
+               if (!method_exists($callable[0], $callable[1])) {
                        // Throw an exception
-                       throw new UnsupportedPackageCodeHandlerException(array($this, $this->callbacks[$packageInstance->getErrorCode()], $packageInstance), self::EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER);
-               } // END - if
+                       throw new UnsupportedPackageCodeHandlerException(array($callable, $packageInstance), self::EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER);
+               }
 
                // Call it back
-               call_user_func(array($this, $this->callbacks[$packageInstance->getErrorCode()]), $packageInstance);
+               call_user_func($callable, $packageInstance);
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: EXIT!');
        }
 
        /**************************************************************************
@@ -176,24 +190,23 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable,
         * class, does some low checks on it and feeds it into another queue for
         * verification and re-request for bad chunks.
         *
-        * @param       $packageInstance                An array with two elements: 'raw_data' and 'error_code'
+        * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      void
         */
        private function handlePackageByUnhandledPackage (DeliverablePackage $packageInstance) {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: packageInstance->rawData[]=' . $packageInstance->getRawData());
-
                // Check for some conditions
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                if ((!$this->ifInputBufferIsEmpty()) || (!$this->isPackageContentCompleted($packageInstance))) {
                        // Last chunk is not valid, so wait for more
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: packageInstance->rawData()=%d being added to this->peningData ...', strlen($packageInstance->getRawData())));
                        $this->pendingData .= $packageInstance->getRawData();
-
-                       // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: Partial data received. Waiting for more ... ( ' . strlen($packageInstance->getRawData()) . ' bytes)');
                } else {
                        // Debug message
-                       //* DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: packageContent=' . print_r($packageInstance, TRUE) . ',chunks='.print_r($chunks, TRUE));
+                       //* PRINTR-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: packageInstance=' . print_r($packageInstance, TRUE) . ',chunks='.print_r($chunks, TRUE));
                }
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: EXIT!');
        }
 
        /**
@@ -204,9 +217,11 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable,
         */
        public function isPendingDataEmpty () {
                // A simbple check
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: CALLED!');
                $ifPendingDataIsEmpty = empty($this->pendingData);
 
                // Return it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: ifPendingDataIsEmpty=%d - EXIT!', intval($ifPendingDataIsEmpty)));
                return $ifPendingDataIsEmpty;
        }
 
@@ -217,12 +232,11 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable,
         */
        public function ifMultipleMessagesPending () {
                // Determine it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: CALLED!');
                $isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_MULTIPLE_MESSAGE));
 
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: isPending=' . intval($isPending) . ' - EXIT!');
-
                // Return it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: isPending=%s - EXIT!', intval($isPending)));
                return $isPending;
        }
 
@@ -230,13 +244,15 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable,
         * Handles the assembler's pending data
         *
         * @return      void
+        * @throws      BadMethodCallException  If this method was called but $this->pendingData is empty
         */
        public function handlePendingData () {
-               // Debug output
+               // Wrong method invocation?
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: Going to decode ' . strlen($this->pendingData) . ' Bytes of pending data. pendingData=' . $this->pendingData);
-
-               // Assert on condition
-               assert(!$this->isPendingDataEmpty());
+               if ($this->isPendingDataEmpty()) {
+                       // Should not happen
+                       throw new BadMethodCallException('this->pendingData is empty but method was called..');
+               }
 
                // No markers set?
                if (!$this->ifStartEndMarkersSet($this->pendingData)) {
index de0785ed91866092d691b3784b82647cc4a0b279..9bdd7cfdedb935b41cca73417e001a4ded5fd5cb 100644 (file)
@@ -127,7 +127,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                // The socket resource should not match server socket
                if (!$this->getListenerInstance()->getSocketInstance()->equals($socketInstance)) {
                        // Try to determine the peer's IP number
-                       if (!$socketInstance->getSocketPeerName($peerAddress, $peerPort)) {
+                       if (!$socketInstance->determineSocketPeerName($peerAddress, $peerPort)) {
                                // Handle the socket error
                                $socketInstance->handleSocketError(__METHOD__, __LINE__);
                        } // END - if
@@ -267,7 +267,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
 
                        // Try to get the "peer"'s name
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: socketInstance->socketResource=%s,socketInstance->socketProtocol=%s,socketArray[%s]=%s', $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketProtocol(), Poolable::SOCKET_ARRAY_CONN_TYPE, $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE]));
-                       if (!$socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketPeerName($peerAddress, $peerPort)) {
+                       if (!$socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->determineSocketPeerName($peerAddress, $peerPort)) {
                                // Handle the socket error with given package data
                                $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->handleSocketError(__METHOD__, __LINE__);
                        } // END - if
index 8a7d0102a802ebce88946d7787908624eb016624..bf7774f3c294288f836adc3305c70b71a5d0d4f9 100644 (file)
@@ -41,10 +41,10 @@ class UnsupportedPackageCodeHandlerException extends FrameworkException {
        public function __construct (array $messageArray, $code) {
                // Construct the message
                $message = sprintf('[%s:%d] Unsupported package code handler %s for package code %s detected.',
-                       $messageArray[0]->__toString(),
+                       $messageArray[0][0]->__toString(),
                        $this->getLine(),
-                       $messageArray[1],
-                       $messageArray[2]->getErrorCode()
+                       $messageArray[0][1],
+                       $messageArray[1]->getErrorCode()
                );
 
                // Call parent exception constructor
index 73d39091c40922c941a3146f3e64e0b01f36bc1d..b6bec8e9ab6f60938aa6fa5c887692e2cfa8e3bd 100644 (file)
@@ -117,14 +117,14 @@ interface StorableSocket extends FrameworkInterface {
        function enableSocketReuseAddress ();
 
        /**
-        * Some "getter" for peer address/port from stored socket
+        * Determines socket's "peer name", mostly address and port number.
         *
         * @param       $peerAddress    Peer address being determined
         * @param       $peerPort               Peer port being determined
         * @return      $result                 Result from asking for peer address
         * @throws      InvalidSocketException  If stored socket is invalid
         */
-       function getSocketPeerName (&$peerAddress, &$peerPort);
+       function determineSocketPeerName (&$peerAddress, &$peerPort);
 
        /**
         * Calls socket_select() on stored socket resource