From dc89633f1a03f8b1c4ff97ded394ba715ed239ba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 24 May 2017 22:04:07 +0200 Subject: [PATCH] Prepared next step of socket-rewrites: - instead of direct socket resource, use socket instance (not working now, die() has been added, too) - updated core framework MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../hub/classes/client/http/class_HttpClient.php | 6 +++--- .../connection/class_BaseConnectionHelper.php | 4 ++-- .../hub/classes/listener/class_BaseListener.php | 13 +++++++------ .../hub/classes/listener/udp/class_UdpListener.php | 6 +++--- core | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/application/hub/classes/client/http/class_HttpClient.php b/application/hub/classes/client/http/class_HttpClient.php index efad8cbd3..d3327c420 100644 --- a/application/hub/classes/client/http/class_HttpClient.php +++ b/application/hub/classes/client/http/class_HttpClient.php @@ -120,16 +120,16 @@ class HttpClient extends BaseClient implements Client { //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HTTP-CLIENT: rawRequest=' . $rawRequest); // Write request - fwrite($this->getSocketResource(), $rawRequest); + fwrite($this->getSocketInstance(), $rawRequest); // Got response? - if (feof($this->getSocketResource())) { + if (feof($this->getSocketInstance())) { // No response received return $response; } // END - if // Read the first line - $resp = trim(fgets($this->getSocketResource(), 10240)); + $resp = trim(fgets($this->getSocketInstance(), 10240)); // "Explode" the string to an array $responseArray = explode(' ', $resp); diff --git a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php index 2c48fba82..1e3e75054 100644 --- a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php @@ -291,14 +291,14 @@ class BaseConnectionHelper extends BaseHubSystemHelper implements Visitable, Reg $encodedData = $this->getOutputStreamInstance()->streamData($rawData); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: socketResource[]=' . gettype($this->getSocketResource()) . PHP_EOL); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: socketResource[]=' . gettype($this->getSocketInstance()->getSocketResource()) . PHP_EOL); // Init array $encodedDataArray = array( NetworkPackage::RAW_FINAL_HASH_INDEX => $this->currentFinalHash, NetworkPackage::RAW_ENCODED_DATA_INDEX => $encodedData, NetworkPackage::RAW_SENT_BYTES_INDEX => 0, - NetworkPackage::RAW_SOCKET_INDEX => $this->getSocketResource(), + NetworkPackage::RAW_SOCKET_INDEX => $this->getSocketInstance(), NetworkPackage::RAW_BUFFER_SIZE_INDEX => $bufferSize, NetworkPackage::RAW_DIFF_INDEX => 0 ); diff --git a/application/hub/classes/listener/class_BaseListener.php b/application/hub/classes/listener/class_BaseListener.php index 4b871ece6..9c8902227 100644 --- a/application/hub/classes/listener/class_BaseListener.php +++ b/application/hub/classes/listener/class_BaseListener.php @@ -258,12 +258,13 @@ class BaseListener extends BaseHubSystem implements Visitable { protected function doListenSocketSelect ($peerSuffix) { // Check on all instances assert($this->getPoolInstance() instanceof Poolable); - assert(is_resource($this->getSocketResource())); + assert($this->getSocketInstance()->isValidSocket()); // Get all readers $readers = $this->getPoolInstance()->getAllSingleSockets(); $writers = array(); $excepts = array(); + die('readers='.print_r($readers, TRUE)); // Check if we have some peers left $left = socket_select( @@ -277,17 +278,17 @@ class BaseListener extends BaseHubSystem implements Visitable { // Some new peers found? if ($left < 1) { // Debug message - //* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: left=' . $left . ',serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, true)); + //* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: left=' . $left . ',serverSocket=' . $this->getSocketInstance() . ',readers=' . print_r($readers, true)); // Nothing new found return; } // END - if // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: serverSocket=' . $this->getSocketInstance() . ',readers=' . print_r($readers, true)); // Do we have changed peers? - if (in_array($this->getSocketResource(), $readers)) { + if (in_array($this->getSocketInstance(), $readers)) { /* * Then accept it, if this socket is set to non-blocking IO and the * connection is NOT sending any data, socket_read() may throw @@ -295,10 +296,10 @@ class BaseListener extends BaseHubSystem implements Visitable { * because if you have blocking IO socket_read() will wait and wait * and wait ... */ - $newSocket = socket_accept($this->getSocketResource()); + $newSocket = socket_accept($this->getSocketInstance()); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: newSocket=' . $newSocket . ',serverSocket=' .$this->getSocketResource()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: newSocket=' . $newSocket . ',serverSocket=' .$this->getSocketInstance()); // Array for timeout settings $options = array( diff --git a/application/hub/classes/listener/udp/class_UdpListener.php b/application/hub/classes/listener/udp/class_UdpListener.php index 7bb83e9ed..ec41c1c26 100644 --- a/application/hub/classes/listener/udp/class_UdpListener.php +++ b/application/hub/classes/listener/udp/class_UdpListener.php @@ -90,10 +90,10 @@ class UdpListener extends BaseListener implements Listenable { */ public function doListen() { // Read a package and determine the peer - $amount = @socket_recvfrom($this->getSocketResource(), $rawData, $this->getConfigInstance()->getConfigEntry('udp_buffer_length'), MSG_DONTWAIT, $peer, $port); + $amount = @socket_recvfrom($this->getSocketInstance(), $rawData, $this->getConfigInstance()->getConfigEntry('udp_buffer_length'), MSG_DONTWAIT, $peer, $port); // Get last error - $lastError = socket_last_error($this->getSocketResource()); + $lastError = socket_last_error($this->getSocketInstance()); // Do we have an error at the line? if ($lastError == 11) { @@ -103,7 +103,7 @@ class UdpListener extends BaseListener implements Listenable { * "listener" won't read any packages except if the UDP sender * starts the transmission before this "listener" came up... */ - socket_clear_error($this->getSocketResource()); + socket_clear_error($this->getSocketInstance()); // Skip further processing return; diff --git a/core b/core index eb04c4ff1..5301f9dd1 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit eb04c4ff13087f8e0ca96168e3d718761bedabdb +Subproject commit 5301f9dd1ac83bc13ebfedda721477ec0405e228 -- 2.39.5