// Get a new instance
$socketInstance = new SocketContainer();
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET: socketResource=%s,socketProtocol=%s,packageData[%s]=%s', $socketResource, $socketProtocol, StorableSocket::SOCKET_ARRAY_INDEX_TYPE, $packageData[StorableSocket::SOCKET_ARRAY_INDEX_TYPE]));
+
// Set protocol
$socketInstance->setSocketProtocol($socketProtocol);
*/
public function writeBufferToSocketByArray (array &$socketBuffer, &$sentBytes) {
// Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socketBuffer()=%d,sentBytes=%d - CALLED!', strtoupper($this->getSocketProtocol()), count($socketBuffer), $sentBytes));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socketBuffer()=%d,sentBytes=%d - CALLED!', strtoupper($this->getSocketProtocol()), count($socketBuffer), $sentBytes));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socketBuffer=%s', strtoupper($this->getSocketProtocol()), print_r($socketBuffer, TRUE)));
// Should be valid socket
if (!$this->isValidSocket()) {
}
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Sending out %d bytes,rawBufferSize=%d,diff=%d to socketResource=%s', strtoupper($this->getSocketProtocol()), strlen($socketBuffer[NetworkPackage::RAW_INDEX_ENCODED_DATA]), $socketBuffer[NetworkPackage::RAW_INDEX_BUFFER_SIZE], $socketBuffer[NetworkPackage::RAW_INDEX_DIFF], $this->getSocketResource()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Sending out %d bytes,rawBufferSize=%d,diff=%d to socketResource=%s', strtoupper($this->getSocketProtocol()), strlen($socketBuffer[NetworkPackage::RAW_INDEX_ENCODED_DATA]), $socketBuffer[NetworkPackage::RAW_INDEX_BUFFER_SIZE], $socketBuffer[NetworkPackage::RAW_INDEX_DIFF], $this->getSocketResource()));
// Is some data still pending or sent all out?
if ($socketBuffer[NetworkPackage::RAW_INDEX_DIFF] >= 0) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: MD5=%s', strtoupper($this->getSocketProtocol()), md5(substr($socketBuffer[NetworkPackage::RAW_INDEX_ENCODED_DATA], 0, ($socketBuffer[NetworkPackage::RAW_INDEX_BUFFER_SIZE] - $socketBuffer[NetworkPackage::RAW_INDEX_DIFF])))));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: MD5=%s', strtoupper($this->getSocketProtocol()), md5(substr($socketBuffer[NetworkPackage::RAW_INDEX_ENCODED_DATA], 0, ($socketBuffer[NetworkPackage::RAW_INDEX_BUFFER_SIZE] - $socketBuffer[NetworkPackage::RAW_INDEX_DIFF])))));
// Send all out (encodedData is smaller than or equal buffer size)
$sentBytes = socket_write($this->getSocketResource(), $socketBuffer[NetworkPackage::RAW_INDEX_ENCODED_DATA], ($socketBuffer[NetworkPackage::RAW_INDEX_BUFFER_SIZE] - $socketBuffer[NetworkPackage::RAW_INDEX_DIFF]));
} else {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: MD5=%s', strtoupper($this->getSocketProtocol()), md5(substr($socketBuffer[NetworkPackage::RAW_INDEX_ENCODED_DATA], 0, $socketBuffer[NetworkPackage::RAW_INDEX_BUFFER_SIZE]))));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: MD5=%s', strtoupper($this->getSocketProtocol()), md5(substr($socketBuffer[NetworkPackage::RAW_INDEX_ENCODED_DATA], 0, $socketBuffer[NetworkPackage::RAW_INDEX_BUFFER_SIZE]))));
// Send buffer size out
$sentBytes = socket_write($this->getSocketResource(), $socketBuffer[NetworkPackage::RAW_INDEX_ENCODED_DATA], $socketBuffer[NetworkPackage::RAW_INDEX_BUFFER_SIZE]);
$result = ($sentBytes !== FALSE);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: sentBytes[%s]=%d,result=%d', strtoupper($this->getSocketProtocol()), gettype($sentBytes), $sentBytes, intval($result)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: sentBytes[%s]=%d,result=%d', strtoupper($this->getSocketProtocol()), gettype($sentBytes), $sentBytes, intval($result)));
// If there was an error, don't continue here
if ($result === FALSE) {
// Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socket_write() failed, please evalutate. - EXIT!', strtoupper($this->getSocketProtocol())));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socket_write() failed, please evalutate. - EXIT!', strtoupper($this->getSocketProtocol())));
// Failed delivery!
return FALSE;
} elseif (($sentBytes === 0) && (strlen($socketBuffer[NetworkPackage::RAW_INDEX_ENCODED_DATA]) > 0)) {
// Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: All sent, returning TRUE ... - EXIT!', strtoupper($this->getSocketProtocol())));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: All sent, returning TRUE ... - EXIT!', strtoupper($this->getSocketProtocol())));
// Nothing sent means all data has been sent
return TRUE;
$socketBuffer[NetworkPackage::RAW_INDEX_SENT_BYTES] += $sentBytes;
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Sent out %d of %d bytes ...', strtoupper($this->getSocketProtocol()), $sentBytes, strlen($socketBuffer[NetworkPackage::RAW_INDEX_ENCODED_DATA])));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Sent out %d of %d bytes ...', strtoupper($this->getSocketProtocol()), $sentBytes, strlen($socketBuffer[NetworkPackage::RAW_INDEX_ENCODED_DATA])));
// Cut out the last unsent bytes
$socketBuffer[NetworkPackage::RAW_INDEX_ENCODED_DATA] = substr($socketBuffer[NetworkPackage::RAW_INDEX_ENCODED_DATA], $sentBytes);
}
// Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($result)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($result)));
// Return result
return $result;
*/
public function discoverSocket (array $packageData, $connectionType) {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISOVERY: connectionType=' . $connectionType . ' - CALLED!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISOVERY: packageData()=' . count($packageData) . ',connectionType=' . $connectionType . ' - CALLED!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISOVERY: packageData=' . print_r($packageData, TRUE));
// Make sure all parameters are valid
if (!isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) {
*/
public static final function createUnlInstanceFromString ($unl) {
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNL-FACTORY: unl=%s - CALLED!', $unl));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNL-FACTORY: unl=%s - CALLED!', $unl));
// If there is no handler?
if (GenericRegistry::getRegistry()->instanceExists('unl_' . $unl)) {
}
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNL-FACTORY: unlInstance[]=%s - EXIT!', gettype($unlInstance)));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNL-FACTORY: unlInstance[]=%s - EXIT!', gettype($unlInstance)));
// Return the instance
return $unlInstance;
* @todo Rewrite this to also handle IPv6 addresses and sockets
*/
public static final function createTcpOutgoingSocketFromPackageData (array $packageData) {
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: packageData=' . print_r($packageData, TRUE) . ' - CALLED!');
+
// Create a socket instance
$socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Created socket[' . gettype($socketResource) . ']=' . $socketResource . '.');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Created socket[' . gettype($socketResource) . ']=' . $socketResource . ' ...');
// Add socket type 'outgoing' to package data
- $packageData[StorableSocket::SOCKET_ARRAY_INDEX_TYPE] = StorableSocket::CONNECTION_TYPE_SERVER;
+ $packageData[StorableSocket::SOCKET_ARRAY_INDEX_TYPE] = StorableSocket::CONNECTION_TYPE_OUTGOING;
// Construct container class, this won't be reached if an exception is thrown
$socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', array($socketResource, StorableSocket::SOCKET_PROTOCOL_TCP, $packageData));
} // END - if
// Set the option to reuse the port
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Enabling re-use address ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Enabling re-use address ...');
if (!$socketInstance->enableSocketReuseAddress()) {
// Handle this socket error with a faked recipientData array
$socketInstance->handleSocketError(__METHOD__, __LINE__, array('0.0.0.0', '0'));
* it. This is now the default behaviour for all connection helpers who
* call initConnection(); .
*/
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Setting non-blocking mode.');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Setting non-blocking mode.');
if (!$socketInstance->enableSocketNonBlocking()) {
// Handle this socket error with a faked recipientData array
$socketInstance->handleSocketError(__METHOD__, __LINE__, array('0.0.0.0', '0'));
$rawDataChunk = $this->getFragmenterInstance()->getNextRawDataChunk($this->currentFinalHash);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: rawDataChunk=' . print_r($rawDataChunk, TRUE));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: rawDataChunk=' . print_r($rawDataChunk, TRUE));
// Get chunk hashes and chunk data
$chunkHashes = array_keys($rawDataChunk);
$rawData = '';
// Is the required data there?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: chunkHashes[]=' . count($chunkHashes) . ',chunkData[]=' . count($chunkData));
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('chunkData='.print_r($chunkData, TRUE));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: chunkHashes[]=' . count($chunkHashes) . ',chunkData[]=' . count($chunkData));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('chunkData='.print_r($chunkData, TRUE));
if ((isset($chunkHashes[0])) && (isset($chunkData[0]))) {
// Remember this chunk as queued
$this->queuedChunks[$chunkHashes[0]] = $chunkData[0];
// Return the raw data
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: rawData()=' . strlen($chunkData[0]) . ' bytes.');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: rawData()=' . strlen($chunkData[0]) . ' bytes.');
$rawData = $chunkData[0];
} // END - if
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: rawData()=%d - EXIT!', strlen($rawData)));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: rawData()=%d - EXIT!', strlen($rawData)));
// Return raw data
return $rawData;
*/
public function sendRawPackageData (array $packageData) {
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: packageData()=%d - CALLED!', count($packageData)));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: packageData()=%d - CALLED!', count($packageData)));
// The helper's state must be 'connected'
$this->getStateInstance()->validatePeerStateConnected();
$finalHash = $this->getFragmenterInstance()->fragmentPackageArray($packageData, $this);
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: finalHash[%s]=%s', gettype($finalHash), $finalHash));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: finalHash[%s]=%s', gettype($finalHash), $finalHash));
// Is the final hash set?
if ($finalHash !== TRUE) {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Setting finalHash=' . $finalHash . ',currentFinalHash[' . gettype($this->currentFinalHash) . ']=' . $this->currentFinalHash);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Setting finalHash=' . $finalHash . ',currentFinalHash[' . gettype($this->currentFinalHash) . ']=' . $this->currentFinalHash);
// Set final hash
$this->currentFinalHash = $finalHash;
// Fill sending buffer with data
while (TRUE) {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: dataStream()=%d - BEFORE!', strlen($dataStream)));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: dataStream()=%d - BEFORE!', strlen($dataStream)));
// Convert the package data array to a raw data stream
$dataStream = $this->getRawDataFromPackageArray($packageData);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: dataStream()=%d - AFTER!', strlen($dataStream)));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: dataStream()=%d - AFTER!', strlen($dataStream)));
// Is it empty?
if (strlen($dataStream) == 0) {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: dataStream is now empty, exiting loop ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: dataStream is now empty, exiting loop ...');
// Abort here
break;
} // END - if
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Adding ' . strlen($dataStream) . ' bytes to the sending buffer ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Adding ' . strlen($dataStream) . ' bytes to the sending buffer ...');
// Add raw data
$rawData .= $dataStream;
} // END - while
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: rawData()=%d - after loop ...', strlen($rawData)));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: rawData()=%d - after loop ...', strlen($rawData)));
// Nothing to sent is bad news, so assert on it
assert(strlen($rawData) > 0);
$bufferSize = $this->getConfigInstance()->getConfigEntry($this->getProtocolName() . '_buffer_length');
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: bufferSize=%d', $bufferSize));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: bufferSize=%d', $bufferSize));
// Encode the raw data with our output-stream
$encodedData = $this->getOutputStreamInstance()->streamData($rawData);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: socketResource[%s]=%s', gettype($this->getSocketInstance()->getSocketResource()), $this->getSocketInstance()->getSocketResource()));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: socketResource[%s]=%s', gettype($this->getSocketInstance()->getSocketResource()), $this->getSocketInstance()->getSocketResource()));
// Init array
$encodedDataArray = array(
$this->getPackageInstance()->getStackInstance()->pushNamed(NetworkPackage::STACKER_NAME_OUTGOING_STREAM, $encodedDataArray);
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: EXIT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: EXIT!');
}
/**
$socketError = $this->getSocketInstance()->getLastSocketErrorCode();
// Log error code and status
- /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: socketError=' . $socketError . ',isConnected=' . intval($isConnected));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: socketError=' . $socketError . ',isConnected=' . intval($isConnected));
// Skip any errors which may happen on non-blocking connections
if (($socketError == SOCKET_EINPROGRESS) || ($socketError == SOCKET_EALREADY)) {
// Now, is that attempt within parameters?
if ((time() - $time) >= $timeout) {
// Debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: timeout=' . $timeout .' reached, connection attempt failed.');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: timeout=' . $timeout .' reached, connection attempt failed.');
// Didn't work within timeout
$isConnected = FALSE;
$this->idle(1000);
} elseif ($socketError != 0) {
// Debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: socketError=' . $socketError . ' detected.');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: socketError=' . $socketError . ' detected.');
// Stop on everything else pronto
$isConnected = FALSE;
} // END - while
// Log error code
- /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: socketError=' . $socketError . ',isConnected=' . intval($isConnected) . ',hasTimedOut=' . intval($hasTimedOut) . ' after while() loop.');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: socketError=' . $socketError . ',isConnected=' . intval($isConnected) . ',hasTimedOut=' . intval($hasTimedOut) . ' after while() loop.');
/*
* All IPv4-based connections are non-blocking used by this program or
*/
if (($hasTimedOut === FALSE) && ($socketError == SOCKET_EINPROGRESS)) {
// Debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Clearing "operation in progress" as this is for 99.999% chance a non-blocking I/O operation.');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Clearing "operation in progress" as this is for 99.999% chance a non-blocking I/O operation.');
// A "connection in progress" has not timed out. All fine.
$isConnected = TRUE;
$this->getSocketInstance()->clearLastSocketError();
} // END - if
+ // Log error code
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: socketError=' . $socketError . ',isConnected=' . intval($isConnected) . ',hasTimedOut=' . intval($hasTimedOut) . ' after while() loop.');
+
// Is the peer connected?
if ($isConnected === TRUE) {
// Connection is fully established here, so change the state.
PeerStateFactory::createPeerStateInstanceByName('problem', $this);
}
+ // Log error code
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: isConnected=' . intval($isConnected) . ' - EXIT!');
+
// Return status
return $isConnected;
}
parent::__construct($className);
}
+ /**
+ * Setter for protocol name
+ *
+ * @param $protocolName Name of used protocol
+ * @return void
+ */
+ protected final function setProtocolName ($protocolName) {
+ $this->protocolName = $protocolName;
+ }
+
+ /**
+ * Setter for UNL instance
+ *
+ * @param $unlInstance An instance of a LocateableNode class
+ * @return void
+ */
+ protected final function setUniversalNodeLocatorInstance (LocateableNode $unlInstance) {
+ throw new UnsupportedOperationException('This method should not be called.');
+ }
+
/**
* Getter for listen address
*
return $this->protocolName;
}
- /**
- * Setter for protocol name
- *
- * @param $protocolName Name of used protocol
- * @return void
- */
- protected final function setProtocolName ($protocolName) {
- $this->protocolName = $protocolName;
- }
-
- /**
- * Setter for UNL instance
- *
- * @para $unlInstance An instance of a LocateableNode class
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected final function setUniversalNodeLocatorInstance (LocateableNode $unlInstance) {
- throw new UnsupportedOperationException('This method should not be called.');
- }
-
/**
* Getter for UNL instance
*
*/
public function doListen () {
// Trace message
- /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Calling this->getListenerInstance() ...');
+ /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Calling this->getListenerInstance()->doListen() ...');
// Handle generic TCP package
$this->getListenerInstance()->doListen();
* @return $accepts Whether this listener does accept
*/
public function ifListenerAcceptsPackageData (array $packageData) {
+ // Debug message
+ /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Calling this->getListenerInstance()->ifListenerAcceptsPackageData() ...');
+
// Call inner method, no decoration is wanted in this method
return $this->getListenerInstance()->ifListenerAcceptsPackageData($packageData);
}
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: EXIT!');
}
- /**
- * Checks whether the listener would accept the given package data array
- *
- * @param $packageData Raw package data
- * @return $accepts Whether this listener does accept
- * @throws UnsupportedOperationException If this method is called
- */
- public function ifListenerAcceptsPackageData (array $packageData) {
- // Please don't call this
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
}
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-TCP-LISTENER: packageData()=%d - CALLED!', count($packageData)));
- // Call parent method
- if (!parent::ifListenerAcceptsPackageData($packageData)) {
+ // Invoke decorated listener's method
+ if (!$this->getListenerInstance()->ifListenerAcceptsPackageData($packageData)) {
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.');
} // END - if
// Debugging
- /* DEBUG-DIE: */ die(__METHOD__.':packageData='.print_r($packageData, TRUE));
+ /* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
// Get a tags instance
$tagsInstance = PackageTagsFactory::createPackageTagsInstance();
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TCP-LISTENER: packageData()=%d - CALLED!', count($packageData)));
- // Call parent method
- if (!parent::ifListenerAcceptsPackageData($packageData)) {
+ // // Invoke decorated listener's method
+ if (!$this->getListenerInstance()->ifListenerAcceptsPackageData($packageData)) {
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.');
} // END - if
// Debugging
- /* DEBUG-DIE: */ die(__METHOD__.':packageData='.print_r($packageData, TRUE));
+ //* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
// Get a tags instance
$tagsInstance = PackageTagsFactory::createPackageTagsInstance();
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-UDP-LISTENER: packageData()=%d - CALLED!', count($packageData)));
- // Call parent method
- if (!parent::ifListenerAcceptsPackageData($packageData)) {
+ // Invoke decorated listener's method
+ if (!$this->getListenerInstance()->ifListenerAcceptsPackageData($packageData)) {
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.');
} // END - if
// Debugging
- /* DEBUG-DIE: */ die(__METHOD__.':packageData='.print_r($packageData, TRUE));
+ /* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
// Get a tags instance
$tagsInstance = PackageTagsFactory::createPackageTagsInstance();
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-UDP-LISTENER: packageData()=%d - CALLED!', count($packageData)));
- // Call parent method
- if (!parent::ifListenerAcceptsPackageData($packageData)) {
+ // Invoke decorated listener's method
+ if ($this->getListenerInstance()->ifListenerAcceptsPackageData($packageData)) {
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.');
} // END - if
// Debugging
- /* DEBUG-DIE: */ die(__METHOD__.':packageData='.print_r($packageData, TRUE));
+ /* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
// Get a tags instance
$tagsInstance = PackageTagsFactory::createPackageTagsInstance();
return $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL];
}
+ /**
+ * Some "getter" for UNL protocol part.
+ *
+ * @return $unlAddress UNL protocol part
+ */
+ public function getUnlProtocol () {
+ // Get UNL data
+ $unlData = $this->getUnlData();
+
+ // Default value is NULL
+ $unkProtocol = NULL;
+
+ // Is the element there?
+ if (isset($unlData[LocateableNode::UNL_PART_PROTOCOL])) {
+ // Use it
+ $unkProtocol = $unlData[LocateableNode::UNL_PART_PROTOCOL];
+ } // END - if
+
+ // Return it
+ return $unkProtocol;
+ }
+
/**
* Some "getter" for UNL address part.
*
$unlData = $this->getUnlData();
// Default value is NULL
- $unlPort = NULL;
+ $unkAddress = NULL;
// Is the element there?
if (isset($unlData[LocateableNode::UNL_PART_ADDRESS])) {
// Use it
- $unlPort = $unlData[LocateableNode::UNL_PART_ADDRESS];
+ $unkAddress = $unlData[LocateableNode::UNL_PART_ADDRESS];
} // END - if
// Return it
- return $unlPort;
+ return $unkAddress;
}
/**
// Is the key found?
if (isset($unlData[$key])) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UNIVERSAL-NODE-LOCATOR: Copying unlData[' . $key . ']=' . $unlData[$key] . ' ...');
+
// The copy the entry
$this->unlData[$key] = $unlData[$key];
} // END - if
*/
public function sendEncodedData () {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: CALLED!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: CALLED!');
// Make sure there is pending encoded data
assert($this->isEncodedDataPending());
assert($encodedDataArray[self::RAW_INDEX_SOCKET_INSTANCE] instanceof StorableSocket);
assert($encodedDataArray[self::RAW_INDEX_SOCKET_INSTANCE]->isValidSocket());
+ // Get socket instance and remove it from array
+ $socketInstance = $encodedDataArray[self::RAW_INDEX_SOCKET_INSTANCE];
+ $encodedDataArray[self::RAW_INDEX_SOCKET_INSTANCE] = NULL;
+
// Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: Calling socketInstance->writeBufferToSocketByArray(%d,%d) ...', count($encodedDataArray), $sentBytes));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: Calling socketInstance->writeBufferToSocketByArray(%d,%d) ...', count($encodedDataArray), $sentBytes));
// And deliver it
- if (!$encodedDataArray[self::RAW_INDEX_SOCKET_INSTANCE]->writeBufferToSocketByArray($encodedDataArray, $sentBytes)) {
+ if (!$socketInstance->writeBufferToSocketByArray($encodedDataArray, $sentBytes)) {
// Something bad happened while writing to socket
- $encodedDataArray[self::RAW_INDEX_SOCKET_INSTANCE]->handleSocketError(__METHOD__, __LINE__, array('0.0.0.0', '0'));
+ $socketInstance->handleSocketError(__METHOD__, __LINE__, array('0.0.0.0', '0'));
} // END - if
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: sentBytes[%s]=%d', gettype($sentBytes), $sentBytes));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: sentBytes[%s]=%d', gettype($sentBytes), $sentBytes));
// If there was an error, don't continue here
if (($sentBytes === 0) && (strlen($encodedDataArray[self::RAW_INDEX_ENCODED_DATA]) > 0)) {
// Nothing sent means all data has been sent
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: All sent! (LINE=' . __LINE__ . ')');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: All sent! (LINE=' . __LINE__ . ')');
return;
} elseif (strlen($encodedDataArray[self::RAW_INDEX_ENCODED_DATA]) == 0) {
// Abort here, all sent!
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: All sent! (LINE=' . __LINE__ . ')');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: All sent! (LINE=' . __LINE__ . ')');
return;
}
+ // Set it back
+ $encodedDataArray[self::RAW_INDEX_SOCKET_INSTANCE] = $socketInstance;
+
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Pushing raw data back to stacker, as still some data is pending delivery.');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Pushing raw data back to stacker, as still some data is pending delivery.');
// Push array back in stack
$this->getStackInstance()->pushNamed(self::STACKER_NAME_OUTGOING_STREAM, $encodedDataArray);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: EXIT!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: EXIT!');
}
///////////////////////////////////////////////////////////////////////////
*/
function getInternalUnl ();
+ /**
+ * Some "getter" for UNL protocol
+ *
+ * @return $unlProtocol Protocol part of UNL
+ */
+ function getUnlProtocol ();
+
/**
* Some "getter" for UNL address.
*