// Return it
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: recipientPort=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($recipientPort)));
return $recipientPort;
-
}
/**
* PHP_NORMAL_READ, this line will endless block. This script does only
* provide simultanous or faked threads, not real.
*/
- /* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
$rawData = socket_read($this->getSocketResource(), $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
// Return it
- /* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: rawData[%s]()=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($rawData), strlen($rawData)));
+ /* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s,rawData[%s]=%s - EXIT!', strtoupper($this->getSocketProtocol()), $this->getSocketResource(), gettype($rawData), $rawData));
return $rawData;
}
* @return $result Whether the option has been set
*/
public function setSocketTimeoutOptions () {
- // Trace message
+ // Call setter method with configured values
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
- // Array for timeout settings
- $options = array(
+ $result = $this->setSocketOption(SOL_SOCKET, SO_RCVTIMEO, [
// Seconds
'sec' => $this->getConfigInstance()->getConfigEntry($this->getSocketProtocol() . '_socket_accept_wait_sec'),
// Milliseconds
- 'usec' => $this->getConfigInstance()->getConfigEntry($this->getSocketProtocol() . '_socket_accept_wait_usec')
- );
-
- // Call inner method
- $result = $this->setSocketOption(SOL_SOCKET, SO_RCVTIMEO, $options);
+ 'usec' => $this->getConfigInstance()->getConfigEntry($this->getSocketProtocol() . '_socket_accept_wait_usec'),
+ ]);
// Return result
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
*/
public function enableSocketOutOfBandData () {
// Call inner method
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
$result = $this->setSocketOption(SOL_SOCKET, SO_OOBINLINE, 1);
- // Trace message
-
// Return result
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
return $result;
}
*/
public function clearLastSocketError () {
// Should be valid socket
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Clearing socket error - CALLED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Clearing socket error - CALLED!');
if (!$this->isValidSocket()) {
// Throw exception
throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
socket_clear_error($this->getSocketResource());
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Error cleared - EXIT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Error cleared - EXIT!');
}
/**
* @return void
*/
public function registerInfoInstance (ShareableInfo $infoInstance) {
- // Trace message
- //* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Calling infoInstance->getListenerInstance() - CALLED!', strtoupper($this->getSocketProtocol())));
-
// Get listener/helper from info class
+ //* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Calling infoInstance->getListenerInstance() - CALLED!', strtoupper($this->getSocketProtocol())));
$listenerInstance = $infoInstance->getListenerInstance();
$helperInstance = $infoInstance->getHelperInstance();
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: listenerInstance[]=' . gettype($listenerInstance) . ',helperInstance[]=' . gettype($helperInstance));
-
// Is there a listener instance set?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: listenerInstance[]=' . gettype($listenerInstance) . ',helperInstance[]=' . gettype($helperInstance));
if ($listenerInstance instanceof Listenable) {
// Set it here for later usage
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Setting listenerInstance=' . $listenerInstance->__toString() . ' ...');
public function writeBufferToSocketByArray (array &$socketBuffer, &$sentBytes) {
// Should be valid socket
/* 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)));
+ //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socketBuffer=%s', strtoupper($this->getSocketProtocol()), print_r($socketBuffer, TRUE)));
if (!$this->isValidSocket()) {
// Throw exception
throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
public static function createSocketFromPackageInstance (DeliverablePackage $packageInstance, HandleableProtocol $protocolInstance) {
// Init instance
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: packageInstance=%s,protocolInstance=%s - CALLED!', $packageInstance->__toString(), $protocolInstance->__toString()));
+ //* DEBUG-DIE: */ die(sprintf('[%s:%d]: packageInstance=%s', __METHOD__, __LINE__, print_r($packageInstance, TRUE)));
$socketInstance = NULL;
// Construct registry key
$registryKey = sprintf('socket_%s_%s',
$protocolInstance->getProtocolName(),
- $packageInstance->getRecipientType()
+ $packageInstance->getRecipientUnl()
);
// Is the key there?
// Debug message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: Using socketResource[%s]=%s from registry.', gettype($socketInstance->getSocketResource()), $socketInstance->getSocketResource()));
} else {
- // Construct configuration entry for object factory and get it
- $className = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($protocolInstance->getProtocolName() . '_connection_helper_class');
-
- // And call the static method
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: Going to use className=%s for creating a socket resource ...', $className));
- $socketInstance = call_user_func($className . '::createConnectionFromPackageInstance', $packageInstance);
+ // Invoke inner factory
+ $socketInstance = self::createObjectByConfiguredName(sprintf('%s_connection_helper_class', $protocolInstance->getProtocolName()), array($packageInstance));
// Register it with the registry
GenericRegistry::getRegistry()->addInstance($registryKey, $socketInstance);