]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 3 Dec 2020 23:33:10 +0000 (00:33 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 3 Dec 2020 23:37:42 +0000 (00:37 +0100)
- fixed NPE when socket is being shutdown on creation
- improved some logger messages
- updated core framework

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/container/socket/class_SocketContainer.php
application/hub/classes/factories/socket/class_SocketFactory.php
application/hub/classes/listener/socket/class_SocketFileListener.php
core

index 8f74603a08ebe975b016e30d26ba24cd8c7d204c..e794f2db74004aeff54e0d5eb2635604310d914c 100644 (file)
@@ -18,6 +18,7 @@ use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
+use Org\Mxchange\CoreFramework\Helper\Helper;
 use Org\Mxchange\CoreFramework\Registry\Registerable;
 use Org\Mxchange\CoreFramework\Socket\InvalidSocketException;
 use Org\Mxchange\CoreFramework\Socket\NoSocketErrorDetectedException;
@@ -229,7 +230,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         */
        public function shutdownSocket () {
                // Debug message
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Shutting down socket ' . $this->getSocketResource() . ' with state ' . $this->getHelperInstance()->getPrintableState() . ' ...');
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Shutting down socket ' . $this->getSocketResource() . ' with state ' . ($this->getHelperInstance() instanceof Helper ? $this->getHelperInstance()->getPrintableState() : 'NULL') . ' ...');
 
                // Get a visitor instance
                $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
@@ -770,7 +771,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                $socketResource = socket_accept($this->getSocketResource());
 
                // Create socket instance from it
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socketResource=%s,serverSocket=%s', strtoupper($this->getSocketProtocol()), $socketResource, $this->getSocketResource()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s,serverSocket=%s', strtoupper($this->getSocketProtocol()), $socketResource, $this->getSocketResource()));
                $socketInstance = SocketFactory::createIncomingSocketInstance($socketResource, $this->getSocketProtocol());
 
                // Return accepted socket instance
@@ -876,7 +877,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         */
        public function clearLastSocketError () {
                // Should be valid socket
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Clearing socket error, socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Clearing socket error, this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                if (!$this->isValidSocket()) {
                        // Throw exception
                        throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
@@ -889,7 +890,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                socket_clear_error($this->getSocketResource());
 
                // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Error cleared - EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Error cleared - EXIT!', strtoupper($this->getSocketProtocol())));
        }
 
        /**
@@ -901,12 +902,12 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         */
        public function registerInfoInstance (ShareableInfo $infoInstance) {
                // Get listener/helper from info class
-               //* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Calling infoInstance->getListenerInstance() - CALLED!', strtoupper($this->getSocketProtocol())));
+               /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: infoInstance=%s,this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $infoInstance->__toString(), $this->getSocketResource()));
                $listenerInstance = $infoInstance->getListenerInstance();
                $helperInstance = $infoInstance->getHelperInstance();
 
                // Is there a listener instance set?
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: listenerInstance[]=' . gettype($listenerInstance) . ',helperInstance[]=' . gettype($helperInstance));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: listenerInstance[]=%s,helperInstance[]=%s', strtoupper($this->getSocketProtocol()), gettype($listenerInstance), gettype($helperInstance)));
                if ($listenerInstance instanceof Listenable) {
                        // Set it here for later usage
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Setting listenerInstance=' . $listenerInstance->__toString() . ' ...');
@@ -957,7 +958,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                }
 
                // 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()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Sending out %d bytes,rawBufferSize=%d,diff=%d to this->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) {
                        // 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])))));
index 0180d652c39bdb181871cf7e6091cdd2770748e6..2d2ae56e5f2679edd032f9ccfa07c4ebad032ffc 100644 (file)
@@ -21,6 +21,7 @@ use Org\Mxchange\CoreFramework\Socket\InvalidSocketException;
 use \InvalidArgumentException;
 use \LogicException;
 use \SplFileInfo;
+use \UnexpectedValueException;
 
 /**
  * A socket factory class
@@ -105,20 +106,22 @@ class SocketFactory extends ObjectFactory {
         * @param       $listenerInstance       An instance of a Listenable class
         * @return      $socketInstance         An instance of a StorableSocket class
         * @throws      InvalidSocketException  If the socket cannot be completed
+        * @throws      UnexpectedValueException        If $socketFile is empty
         */
        public static final function createListenFileSocket (Listenable $listenerInstance) {
                // Create SplFileInfo
-               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: listenerInstance=%s - EXIT!', $listenerInstance->__toString()));
+               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: listenerInstance=%s - CALLED!', $listenerInstance->__toString()));
                $fileInfo = new SplFileInfo(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('ipc_socket_file_name'));
 
                // Create file name
                $socketFile = self::createTempPathForFile($fileInfo);
 
-               // Debug message
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: socketFile=' . $socketFile . ' ...');
-
                // File name must not be empty
-               assert(!empty($socketFile));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: socketFile=' . $socketFile . ' ...');
+               if (empty($socketFile)) {
+                       // Something unexpected
+                       throw new UnexpectedValueException('socketFile is empty');
+               }
 
                // Init package instance
                $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
@@ -127,12 +130,12 @@ class SocketFactory extends ObjectFactory {
                $socketResource = socket_create(AF_UNIX, SOCK_STREAM, 0);
 
                // Get container from it
-               $socketInstance = self::createObjectByConfiguredName('socket_container_class', array(
+               $socketInstance = self::createObjectByConfiguredName('socket_container_class', [
                        $socketResource,
                        StorableSocket::SOCKET_PROTOCOL_FILE,
                        $packageInstance,
                        StorableSocket::CONNECTION_TYPE_SERVER,
-               ));
+               ]);
 
                // Set socket file
                $socketInstance->setSocketFile($socketFile);
index e73e8b54c5b5e357e630d7f27906e6df1236c863..4a97d89eda8b2088ce54166d21002dc69d48d19b 100644 (file)
@@ -70,6 +70,7 @@ class SocketFileListener extends BaseListener implements Listenable {
         */
        public function initListener () {
                // Create socket with factory
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: CALLED!');
                $socketInstance = SocketFactory::createListenFileSocket($this);
 
                // Set the socket instance
diff --git a/core b/core
index ddbb50472e5383629958295be9f063cf8124b41f..ac256a664aa490665d37705439807ab6d62a7e3a 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit ddbb50472e5383629958295be9f063cf8124b41f
+Subproject commit ac256a664aa490665d37705439807ab6d62a7e3a