From: Roland Häder Date: Sat, 20 May 2017 19:58:07 +0000 (+0200) Subject: Continued a bit: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a0d6ee35a700ef553d5e996a687f9f76f36d8841;p=hub.git Continued a bit: - implemented getLastSocketError() - added partial stub for bindSocketTo() 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 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 (); + }