]> git.mxchange.org Git - hub.git/commitdiff
Moved registration of socket with fake package data array to listener
authorRoland Häder <roland@mxchange.org>
Sat, 19 May 2012 14:18:42 +0000 (14:18 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 19 May 2012 14:18:42 +0000 (14:18 +0000)
application/hub/main/listener/tcp/class_TcpListener.php
application/hub/main/pools/peer/class_DefaultPeerPool.php

index 480e792da61aa98c10b07ac76a8ab1eb8c561a05..731de7f9b11b05ede2a9ef2236aa6c9a996e6919 100644 (file)
@@ -267,6 +267,26 @@ class TcpListener extends BaseListener implements Listenable {
 
                        // Add it to the peers
                        $this->getPoolInstance()->addPeer($newSocket);
+
+                       // Get peer name
+                       if (!socket_getpeername($newSocket, $peerName)) {
+                               // Handle this socket error with a faked recipientData array
+                               $this->handleSocketError(__METHOD__, __LINE__, $newSocket, array('0.0.0.0', '0'));
+                       } // END - if
+
+                       // Create a faked package data array
+                       $packageData = array(
+                               NetworkPackage::PACKAGE_DATA_SENDER    => $peerName . ':0',
+                               NetworkPackage::PACKAGE_DATA_RECIPIENT => $this->getSessionId(),
+                               NetworkPackage::PACKAGE_DATA_PROTOCOL  => $this->getProtocol(),
+                               NetworkPackage::PACKAGE_DATA_STATUS    => NetworkPackage::PACKAGE_STATUS_FAKED
+                       );
+
+                       // Get a socket registry
+                       $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
+
+                       // Register the socket with the registry and with the faked array
+                       $registryInstance->registerSocket($this, $newSocket, $packageData);
                } // END - if
 
                // Do we have to rewind?
index e4c1c18972d19ab063c20d038032211a524936d9..67b02b89c5ae1a518a656e1b8aa5a9edfbe1ee1e 100644 (file)
@@ -119,20 +119,6 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                // Debug message
                $this->debugOutput('POOL: Adding peer ' . $peerName . ',socketResource=' . $socketResource);
 
-               // Create the fake array
-               $packageData = array(
-                       NetworkPackage::PACKAGE_DATA_SENDER    => $peerName . ':0',
-                       NetworkPackage::PACKAGE_DATA_RECIPIENT => $this->getSessionId(),
-                       NetworkPackage::PACKAGE_DATA_PROTOCOL  => $this->getListenerInstance()->getProtocol(),
-                       NetworkPackage::PACKAGE_DATA_STATUS    => NetworkPackage::PACKAGE_STATUS_FAKED
-               );
-
-               // Get a socket registry
-               $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
-
-               // Register the socket with the registry and with a half-fake array
-               $registryInstance->registerSocket($this->getListenerInstance(), $socketResource, $packageData);
-
                // Add it finally to the pool
                $this->addPoolEntry($socketResource);
        }