]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 10 May 2022 23:27:44 +0000 (01:27 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 10 May 2022 23:28:49 +0000 (01:28 +0200)
- no need for two socket_write() invocations when you can just do the math in
  the if() block

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/container/socket/class_SocketContainer.php

index 43cebca3490656c4ab742b24e8e12246038911e4..7e72cfe8ad5abd638ed338142d5c09420b1f1d08 100644 (file)
@@ -965,18 +965,20 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                        throw new InvalidArgumentException(sprintf('socketBuffer[%s] is not set.', NetworkPackageHandler::RAW_INDEX_SENT_BYTES));
                }
 
+               // Initial buffer size
+               $bufferSize = $socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE];
+
                // Is some data still pending or sent all out?
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Sending out %d bytes,rawBufferSize=%d,diff=%d to this->socketResource=%s', strtoupper($this->getSocketProtocol()), strlen($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA]), $socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE], $socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF], $this->getSocketResource()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: bufferSize=%d,socketBuffer[%s]=%d', strtoupper($this->getSocketProtocol()), NetworkPackageHandler::RAW_INDEX_DIFF, $socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF]));
                if ($socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF] >= 0) {
-                       // Send all out (encodedData is smaller than or equal buffer size)
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: MD5=%s', strtoupper($this->getSocketProtocol()), md5(substr($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA], 0, ($socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE] - $socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF])))));
-                       $sentBytes = socket_write($this->getSocketResource(), $socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA], ($socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE] - $socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF]));
-               } else {
-                       // Send buffer size out
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: MD5=%s', strtoupper($this->getSocketProtocol()), md5(substr($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA], 0, $socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE]))));
-                       $sentBytes = socket_write($this->getSocketResource(), $socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA], $socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE]);
+                       // Reduce buffer size by difference
+                       $bufferSize = $socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE] - $socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF];
                }
 
+               // Send buffered raw data
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Invoking socket_write(%s,()=%d,%d) ...', strtoupper($this->getSocketProtocol()), $this->getSocketResource(), strlen($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA]), $bufferSize));
+               $sentBytes = socket_write($this->getSocketResource(), $socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA], $bufferSize);
+
                // Check if the operation was okay
                // @TODO Maybe check more?
                $result = ($sentBytes !== FALSE);