]> git.mxchange.org Git - hub.git/commitdiff
Continued a bit:
authorRoland Häder <roland@mxchange.org>
Sun, 21 May 2017 21:50:38 +0000 (23:50 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 21 Aug 2020 16:50:07 +0000 (18:50 +0200)
- some more logging
- more constants for socket array indexes

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/statistics/connection/class_ConnectionStatisticsHelper.php
application/hub/interfaces/container/socket/class_StorableSocket.php

index 5f95620d8d5738e21ad10b3fbe734978482755e0..ff3bcb0650f72175cedc965460ff7c843cb9e0a7 100644 (file)
@@ -73,6 +73,10 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
         * @return      $socketInstance         An instance of this Container class
         */
        public static final function createSocketContainer ($socketResource, $socketProtocol, array $packageData, ShareableInfo $infoInstance = NULL) {
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET: socketResource=%s,socketProtocol=%s,packageData()=%d,infoInstance[]=%s - CALLED!', $socketResource, $socketProtocol, count($packageData), gettype($infoInstance)));
+               /* DEBUG-PRINT: */ printf('[%s:%d]: packageData=%s', __METHOD__, __LINE__, print_r($packageData, TRUE));
+
                // Get a new instance
                $socketInstance = new SocketContainer();
 
@@ -83,9 +87,6 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
                unset($packageData[NetworkPackage::PACKAGE_DATA_CONTENT]);
                unset($packageData[NetworkPackage::PACKAGE_DATA_HASH]);
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-CONTAINER:socketResource=' . $socketResource . ',packageData='.print_r($packageData, true));
-
                // Is the info instance set?
                if ($infoInstance instanceof ShareableInfo) {
                        // Get listener/helper from info class
index b057981e1ade4aafec949882d4443d1581c5ee67..b553e69053022dc2be110f638ea3e69aed8a9008 100644 (file)
@@ -107,7 +107,7 @@ class SocketFactory extends ObjectFactory {
                $socketFile = self::createTempPathForFile($listenerInstance->getConfigInstance()->getConfigEntry('ipc_socket_file_name'));
 
                // Debug message
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: socketFile=' . $socketFile . ' ...');
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: socketFile=' . $socketFile . ' ...');
 
                // File name must not be empty
                assert(!empty($socketFile));
@@ -122,8 +122,7 @@ class SocketFactory extends ObjectFactory {
                $socketResource = socket_create(AF_UNIX, SOCK_STREAM, 0);
 
                // Get container from it
-               // @TODO Somehow handle $infoInstance to this factory
-               $socketInstance = self::createObjectByConfiguredName('socket_container_class', array($socketResource, StorableSocket::SOCKET_PROTOCOL_FILE, $packageData, NULL));
+               $socketInstance = self::createObjectByConfiguredName('socket_container_class', array($socketResource, StorableSocket::SOCKET_PROTOCOL_FILE, $packageData));
 
                // Debug message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FILE_LISTENER: socketInstance[]=%s', gettype($socketInstance)));
@@ -143,7 +142,7 @@ class SocketFactory extends ObjectFactory {
                // Is the file there?
                if ((FrameworkBootstrap::isReachableFilePath($packageData[StorableSocket::SOCKET_ARRAY_INDEX_FILE])) && (file_exists($packageData[StorableSocket::SOCKET_ARRAY_INDEX_FILE]))) {
                        // Old socket found
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: WARNING: Old socket at ' . $packageData[StorableSocket::SOCKET_ARRAY_INDEX_FILE] . ' found. Will not start.');
+                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: WARNING: Old socket at ' . $packageData[StorableSocket::SOCKET_ARRAY_INDEX_FILE] . ' found. Will not start.');
 
                        // Shutdown this socket
                        $socketInstance->shutdownSocket();
@@ -153,7 +152,7 @@ class SocketFactory extends ObjectFactory {
                } // END - if
 
                // Debug message
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Binding to ' . $packageData[StorableSocket::SOCKET_ARRAY_INDEX_FILE] . ' ...');
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Binding to ' . $packageData[StorableSocket::SOCKET_ARRAY_INDEX_FILE] . ' ...');
 
                // Try to bind to it
                if (!$socketInstance->bindSocketTo($packageData[StorableSocket::SOCKET_ARRAY_INDEX_FILE])) {
@@ -162,14 +161,14 @@ class SocketFactory extends ObjectFactory {
                } // END - if
 
                // Start listen for connections
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Listening for connections.');
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Listening for connections.');
                if (!$socketInstance->listenOnSocket()) {
                        // Handle this socket error with a faked recipientData array
                        $socketInstance->handleSocketError(__METHOD__, __LINE__, array_values($packageData));
                } // END - if
 
                // Allow non-blocking I/O
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Setting non-blocking mode.');
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Setting non-blocking mode.');
                if (!$socketInstance->enableSocketNonBlocking()) {
                        // Handle this socket error with a faked recipientData array
                        $socketInstance->handleSocketError(__METHOD__, __LINE__, array_values($packageData));
@@ -196,8 +195,7 @@ class SocketFactory extends ObjectFactory {
                //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Created socket ' . $socketResource . '(' . gettype($socketResource) . ') from class ' . $className . '.');
 
                // Construct container class, this won't be reached if an exception is thrown
-               // @TODO Somehow handle $infoInstance to this factory
-               $socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', array($socketResource, StorableSocket::SOCKET_PROTOCOL_TCP, $packageData, NULL));
+               $socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', array($socketResource, StorableSocket::SOCKET_PROTOCOL_TCP, $packageData));
 
                // Is the socket resource valid?
                if (!$socketInstance->isValidSocket()) {
@@ -216,6 +214,7 @@ class SocketFactory extends ObjectFactory {
                } // END - if
 
                // Set the option to reuse the port
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Enabling re-use address ...');
                if (!$socketInstance->enableSocketReuseAddress()) {
                        // Handle this socket error with a faked recipientData array
                        $socketInstance->handleSocketError(__METHOD__, __LINE__, array('0.0.0.0', '0'));
@@ -226,6 +225,7 @@ class SocketFactory extends ObjectFactory {
                 * it. This is now the default behaviour for all connection helpers who
                 * call initConnection(); .
                 */
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Setting non-blocking mode.');
                if (!$socketInstance->enableSocketNonBlocking()) {
                        // Handle this socket error with a faked recipientData array
                        $socketInstance->handleSocketError(__METHOD__, __LINE__, array('0.0.0.0', '0'));
@@ -246,8 +246,10 @@ class SocketFactory extends ObjectFactory {
                // Create a streaming socket, of type TCP/IP
                $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
 
-               // @TODO Init fake package data with address/port from listener
+               // Init fake package data with address/port from listener
                $packageData = array(
+                       StorableSocket::SOCKET_ARRAY_INDEX_ADDRESS => $listenerInstance->getListenAddress(),
+                       StorableSocket::SOCKET_ARRAY_INDEX_PORT    => $listenerInstance->getListenPort(),
                );
 
                // Create socket instance
@@ -267,6 +269,7 @@ class SocketFactory extends ObjectFactory {
 
                // Set the option to reuse the port
                // @TODO: , SOL_SOCKET, SO_REUSEADDR, 1
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Enabling re-use address ...');
                if (!$socketInstance->enableSocketReuseAddress()) {
                        // Handle this socket error with a faked recipientData array
                        $socketInstance->handleSocketError(__METHOD__, __LINE__, array('0.0.0.0', '0'));
@@ -277,21 +280,21 @@ class SocketFactory extends ObjectFactory {
                 * that all connections on this port are now our resposibility to
                 * send/recv data, disconnect, etc..
                 */
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: Binding to address ' . $listenerInstance->getListenAddress() . ':' . $listenerInstance->getListenPort());
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Binding to address ' . $listenerInstance->getListenAddress() . ':' . $listenerInstance->getListenPort());
                if (!$socketInstance->bindSocketTo($listenerInstance->getListenAddress(), $listenerInstance->getListenPort())) {
                        // Handle this socket error with a faked recipientData array
                        $socketInstance->handleSocketError(__METHOD__, __LINE__, array('0.0.0.0', '0'));
                } // END - if
 
                // Start listen for connections
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: Listening for connections.');
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Listening for connections.');
                if (!$socketInstance->listenToSocket()) {
                        // Handle this socket error with a faked recipientData array
                        $socketInstance->handleSocketError(__METHOD__, __LINE__, array('0.0.0.0', '0'));
                } // END - if
 
                // Now, we want non-blocking mode
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: Setting non-blocking mode.');
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Setting non-blocking mode.');
                if (!$socketInstance->enableSocketNonBlocking()) {
                        // Handle this socket error with a faked recipientData array
                        $socketInstance->handleSocketError(__METHOD__, __LINE__, array('0.0.0.0', '0'));
index 7f839a6a798ae7674612a42b86d5e84b9f64564f..285458ea1fcf9b7872f6d607f12778a5997d890e 100644 (file)
@@ -106,7 +106,5 @@ class ConnectionStatisticsHelper extends BaseHubSystem {
                // @TODO last_update is not being used at the moment
                self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['last_update'] = time();
        }
-}
 
-// [EOF]
-?>
+}
index 13c8997cc464a782af758fa5849ecd89df516fe5..07de27e65f160c7cc76e4cf522adb5b0771850ba 100644 (file)
@@ -47,10 +47,10 @@ interface StorableSocket extends FrameworkInterface {
        const SOCKET_ERROR_OPERATION_NOT_SUPPORTED    = 'operation_not_supported';    // 'Operation not supported'
        const SOCKET_CONNECTED                        = 'connected';                  // Nothing errorous happens, socket is connected
 
-       /**
-        * Socket file array index
-        */
-       const SOCKET_ARRAY_INDEX_FILE = 'socket_file';
+       // Socket data array indexes
+       const SOCKET_ARRAY_INDEX_FILE    = 'socket_file';
+       const SOCKET_ARRAY_INDEX_ADDRESS = 'socket_address';
+       const SOCKET_ARRAY_INDEX_PORT    = 'socket_port';
 
        // Socket protocols
        const SOCKET_PROTOCOL_INVALID = 'invalid';