]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 26 Oct 2020 04:38:00 +0000 (05:38 +0100)
committerRoland Häder <roland@mxchange.org>
Mon, 26 Oct 2020 04:46:46 +0000 (05:46 +0100)
- Implemented SocketContainer::bindSocketToFile()
- ops, needs to be listenPort and not listenAddress again
- socketType is not yet know in constructor, this will be later set
- updated core framework

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

index 1f968409c011ae2d97c61cd3b0992853ce21142f..3e8987eafbfc8e367ee2cdc755d84279e1b0ab46 100644 (file)
@@ -126,7 +126,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                $socketInstance = new SocketContainer();
 
                // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET: socketResource=%s,socketProtocol=%s,packageInstance->socketType=%s', $socketResource, $socketProtocol, $packageInstance->getSocketType()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET: socketResource=%s,socketProtocol=%s', $socketResource, $socketProtocol));
 
                // Set protocol
                $socketInstance->setSocketProtocol($socketProtocol);
@@ -524,10 +524,26 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @param       $bindPort               Optional port to bind to
         * @return      $result         Result from binding socket
         * @throws      InvalidSocketException  If socket is invalid
+        * @throws      NullPointerException    If listener instance is not given
         */
        public function bindSocketToFile () {
-               // Trace message
+               // Should be valid socket
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: CALLED!', strtoupper($this->getSocketProtocol())));
+               if (!$this->isValidSocket()) {
+                       // Throw exception
+                       throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
+               } elseif (is_null($this->getSocketFile())) {
+                       // Throw exception
+                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+               }
+
+               // Try to bind it to
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Binding socket to file %s ...', strtoupper($this->getSocketProtocol()), $this->getSocketFile()));
+               $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)));
+               return $result;
        }
 
        /**
@@ -552,10 +568,10 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
 
                // Get bind address and port
                $address = $this->getListenerInstance()->getListenAddress();
-               $port = $this->getListenerInstance()->getListenAddress();
+               $port = $this->getListenerInstance()->getListenPort();
 
                // Try to bind it to
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Binding socket to %s:%d ...', strtoupper($this->getSocketProtocol()), $address, $port));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Binding socket to address %s:%d ...', strtoupper($this->getSocketProtocol()), $address, $port));
                $result = socket_bind($this->getSocketResource(), $address, $port);
 
                // Return result
index 91cf198f930c2f9a3d6d8b9a2800c7f144474be3..a1fdc514353a02514674fc791c57bdeba5a9d6c5 100644 (file)
@@ -79,6 +79,7 @@ interface StorableSocket extends FrameworkInterface {
         *
         * @return      $result         Result from binding socket
         * @throws      InvalidSocketException  If stored socket is invalid
+        * @throws      NullPointerException    If listener instance is not given
         */
        function bindSocketToFile ();
 
diff --git a/core b/core
index 8d5ee38d8f889ffb079983b223c9dae3fb1e2b3d..f6a7ed0407c3411090a697ba0831bb0d6f4bb616 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 8d5ee38d8f889ffb079983b223c9dae3fb1e2b3d
+Subproject commit f6a7ed0407c3411090a697ba0831bb0d6f4bb616