From: Roland Häder Date: Mon, 26 Oct 2020 04:38:00 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d361579795587b760b13d0ecb48fab3391666b72;p=hub.git Continued: - 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 --- diff --git a/application/hub/classes/container/socket/class_SocketContainer.php b/application/hub/classes/container/socket/class_SocketContainer.php index 1f968409c..3e8987eaf 100644 --- a/application/hub/classes/container/socket/class_SocketContainer.php +++ b/application/hub/classes/container/socket/class_SocketContainer.php @@ -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 diff --git a/application/hub/interfaces/container/socket/class_StorableSocket.php b/application/hub/interfaces/container/socket/class_StorableSocket.php index 91cf198f9..a1fdc5143 100644 --- a/application/hub/interfaces/container/socket/class_StorableSocket.php +++ b/application/hub/interfaces/container/socket/class_StorableSocket.php @@ -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 8d5ee38d8..f6a7ed040 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 8d5ee38d8f889ffb079983b223c9dae3fb1e2b3d +Subproject commit f6a7ed0407c3411090a697ba0831bb0d6f4bb616