]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/listener/tcp/class_TcpListener.php
Renamed FooNetworkPackageHandler to FooRawDataHandler, because it handles raw data...
[hub.git] / application / hub / main / listener / tcp / class_TcpListener.php
index f8a9e21805a8092e3ce7f1c1a7d5da8c77f6cfe5..bdc20b462f98411783f950199ebb81097119a66e 100644 (file)
@@ -30,6 +30,9 @@ class TcpListener extends BaseListener implements Listenable {
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
+
+               // Set the protocol to TCP
+               $this->setProtocol('tcp');
        }
 
        /**
@@ -45,9 +48,6 @@ class TcpListener extends BaseListener implements Listenable {
                // Set the application instance
                $listenerInstance->setNodeInstance($nodeInstance);
 
-               // Set the protocol to TCP
-               $listenerInstance->setProtocol('tcp');
-
                // Return the prepared instance
                return $listenerInstance;
        }
@@ -95,7 +95,7 @@ class TcpListener extends BaseListener implements Listenable {
                // "Bind" the socket to the given address, on given port so this means
                // that all connections on this port are now our resposibility to
                // send/recv data, disconnect, etc..
-               $this->debugOutput('LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
+               $this->debugOutput('TCP-LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
                if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) {
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
@@ -111,7 +111,7 @@ class TcpListener extends BaseListener implements Listenable {
                } // END - if
 
                // Start listen for connections
-               $this->debugOutput('LISTENER: Listening for connections.');
+               $this->debugOutput('TCP-LISTENER: Listening for connections.');
                if (!socket_listen($mainSocket)) {
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
@@ -127,7 +127,7 @@ class TcpListener extends BaseListener implements Listenable {
                } // END - if
 
                // Now, we want non-blocking mode
-               $this->debugOutput('LISTENER: Setting non-blocking mode.');
+               $this->debugOutput('TCP-LISTENER: Setting non-blocking mode.');
                if (!socket_set_nonblock($mainSocket)) {
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
@@ -162,13 +162,13 @@ class TcpListener extends BaseListener implements Listenable {
                $this->setIteratorInstance($iteratorInstance);
 
                // Initialize the network package handler
-               $handlerInstance = ObjectFactory::createObjectByConfiguredName('tcp_network_package_handler_class');
+               $handlerInstance = ObjectFactory::createObjectByConfiguredName('tcp_raw_data_handler_class');
 
                // Set it in this class
                $this->setHandlerInstance($handlerInstance);
 
                // Output message
-               $this->debugOutput('LISTENER: TCP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
+               $this->debugOutput('TCP-LISTENER: TCP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
        }
 
        /**
@@ -202,7 +202,7 @@ class TcpListener extends BaseListener implements Listenable {
                if (in_array($this->getSocketResource(), $readers)) {
                        // Then accept it
                        $newSocket = socket_accept($this->getSocketResource());
-                       //* NOISY-DEBUG: */ $this->debugOutput('LISTENER: newSocket=' . $newSocket);
+                       //* NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: newSocket=' . $newSocket);
 
                        // We want non-blocking here, too
                        if (!socket_set_nonblock($newSocket)) {
@@ -235,7 +235,7 @@ class TcpListener extends BaseListener implements Listenable {
                // Handle it here, if not main socket
                if ($currentSocket != $this->getSocketResource()) {
                        // ... or else it will raise warnings like 'Transport endpoint is not connected'
-                       //* NOISY-DEBUG: */ $this->debugOutput('LISTENER: currentSocket=' . $currentSocket);
+                       //* NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: currentSocket=' . $currentSocket);
                        $this->getHandlerInstance()->processRawDataFromResource($currentSocket);
                } // END - if