]> git.mxchange.org Git - hub.git/commitdiff
Prepared next step of socket-rewrites:
authorRoland Häder <roland@mxchange.org>
Wed, 24 May 2017 20:04:07 +0000 (22:04 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 21 Aug 2020 16:50:08 +0000 (18:50 +0200)
- instead of direct socket resource, use socket instance (not working now,
  die() has been added, too)
- updated core framework

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/client/http/class_HttpClient.php
application/hub/classes/helper/connection/class_BaseConnectionHelper.php
application/hub/classes/listener/class_BaseListener.php
application/hub/classes/listener/udp/class_UdpListener.php
core

index efad8cbd344ab8a5afca79d694df4c39820854e3..d3327c420822bfe4aa3f37ddfd39e84f6af19ac8 100644 (file)
@@ -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);
index 2c48fba82bffc82affa1f42df1bb80a703a4f880..1e3e7505470d7d3ac9860e680a07bbddc1f3cc2b 100644 (file)
@@ -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
                );
index 4b871ece6c0f7ad098d8090977c63e086a94e122..9c8902227ae93f36d37fc4b6ec234cdeeec4f341 100644 (file)
@@ -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(
index 7bb83e9ed429f9001a0e0cd5bf69015e4d488cd4..ec41c1c262979fe3a8379b80b24f721ff80f99ac 100644 (file)
@@ -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 eb04c4ff13087f8e0ca96168e3d718761bedabdb..5301f9dd1ac83bc13ebfedda721477ec0405e228 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit eb04c4ff13087f8e0ca96168e3d718761bedabdb
+Subproject commit 5301f9dd1ac83bc13ebfedda721477ec0405e228