From a0d6ee35a700ef553d5e996a687f9f76f36d8841 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 20 May 2017 21:58:07 +0200 Subject: [PATCH] Continued a bit: - implemented getLastSocketError() - added partial stub for bindSocketTo() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../socket/class_SocketContainer.php | 33 +++++++++++++++++++ .../factories/socket/class_SocketFactory.php | 2 +- .../container/socket/class_StorableSocket.php | 14 ++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/application/hub/classes/container/socket/class_SocketContainer.php b/application/hub/classes/container/socket/class_SocketContainer.php index 051f56f09..b23195fcd 100644 --- a/application/hub/classes/container/socket/class_SocketContainer.php +++ b/application/hub/classes/container/socket/class_SocketContainer.php @@ -4,12 +4,14 @@ namespace Hub\Container\Socket; // Import application-specific stuff use Hub\Information\ShareableInfo; +use Hub\Listener\BaseListener; use Hub\Network\Package\NetworkPackage; // Import framework stuff use CoreFramework\Container\BaseContainer; use CoreFramework\Listener\Listenable; use CoreFramework\Registry\Registerable; +use CoreFramework\Socket\InvalidSocketException; use CoreFramework\Visitor\Visitable; use CoreFramework\Visitor\Visitor; @@ -240,4 +242,35 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable return $isValidSocket; } + /** + * Getter for last socket error + * + * @return $lastSocketError Last socket error + */ + public function getLastSocketError () { + // Should be valid socket + if (!$this->isValidSocket()) { + // Throw exception + throw new InvalidSocketException(array($this, $this->getSocketResource()), BaseListener::EXCEPTION_INVALID_SOCKET); + } // END - if + + // Get it from stored socket resource + $socketResource = $this->getSocketResource(); + + // Get error code + $errorCode = socket_last_error($socketResource); + + // Return it + return $errorCode; + } + + /** + * Tries to bind the socket. + * + * @return $result Result from binding socket + */ + public function bindSocketTo () { + $this->partialStub('Unfinished method.'); + } + } diff --git a/application/hub/classes/factories/socket/class_SocketFactory.php b/application/hub/classes/factories/socket/class_SocketFactory.php index dfacab06b..18035de30 100644 --- a/application/hub/classes/factories/socket/class_SocketFactory.php +++ b/application/hub/classes/factories/socket/class_SocketFactory.php @@ -178,7 +178,7 @@ class SocketFactory extends ObjectFactory { $listenerInstance->handleSocketError(__METHOD__, __LINE__, $socketInstance, $packageData); } // END - if - // Now, we want non-blocking mode + // Allow non-blocking I/O self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Setting non-blocking mode.'); if (!$socketInstance->enableSocketNonBlocking()) { // Handle this socket error with a faked recipientData array diff --git a/application/hub/interfaces/container/socket/class_StorableSocket.php b/application/hub/interfaces/container/socket/class_StorableSocket.php index 2833ce2a0..8f80383c4 100644 --- a/application/hub/interfaces/container/socket/class_StorableSocket.php +++ b/application/hub/interfaces/container/socket/class_StorableSocket.php @@ -75,4 +75,18 @@ interface StorableSocket extends FrameworkInterface { */ function isValidSocket (); + /** + * Getter for last socket error + * + * @return $lastSocketError Last socket error + */ + function getLastSocketError (); + + /** + * Tries to bind the socket. + * + * @return $result Result from binding socket + */ + function bindSocketTo (); + } -- 2.39.5