From d21dbeacee49d873308fad37f77cd7e2bbfdf594 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 19 May 2012 14:18:42 +0000 Subject: [PATCH] Moved registration of socket with fake package data array to listener --- .../main/listener/tcp/class_TcpListener.php | 20 +++++++++++++++++++ .../main/pools/peer/class_DefaultPeerPool.php | 14 ------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/application/hub/main/listener/tcp/class_TcpListener.php b/application/hub/main/listener/tcp/class_TcpListener.php index 480e792da..731de7f9b 100644 --- a/application/hub/main/listener/tcp/class_TcpListener.php +++ b/application/hub/main/listener/tcp/class_TcpListener.php @@ -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? diff --git a/application/hub/main/pools/peer/class_DefaultPeerPool.php b/application/hub/main/pools/peer/class_DefaultPeerPool.php index e4c1c1897..67b02b89c 100644 --- a/application/hub/main/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/main/pools/peer/class_DefaultPeerPool.php @@ -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); } -- 2.39.5