// Import framework stuff
use CoreFramework\Object\BaseFrameworkSystem;
-use CoreFramework\Socket\InvalidSocketException;
/**
* A general hub system class
*/
public function acceptNewIncomingSocket () {
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: CALLED!', strtoupper($this->getSocketProtocol())));
+ /* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: CALLED!', strtoupper($this->getSocketProtocol())));
// Should be valid socket
if (!$this->isValidSocket()) {
throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
} // END - if
+ // Debug message
+ /* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
+
// Init all arrays, at least readers
$readers = array($this->getSocketResource());
$writers = array();
$excepts = array();
+ // Trace message
+ /* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Calling socket_select(%d,%d,%d,0%d) ...', strtoupper($this->getSocketProtocol()), count($readers), count($writers), count($excepts), $this->socketSelectTimeout));
+
// Check if we have some peers left
$left = socket_select(
$readers,
$this->socketSelectTimeout
);
+ // Debug message
+ /* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: left=%d,readers()=%d,writers()=%d,except()=%d) ...', strtoupper($this->getSocketProtocol()), $left, count($readers), count($writers), count($excepts)));
+
// Some new peers found?
if ($left < 1) {
- // Debug message
+ // Trace message
//* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: left=' . $left . ',serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, true));
// Nothing new found
use CoreFramework\Registry\Registry;
use CoreFramework\Socket\InvalidSocketException;
+// Import SPL stuff
+use \LogicException;
+
/**
* A socket discovery class
*
// Debug message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-DISCOVERY: protocolName=' . $protocolName);
+ // Debugging
+ //* DEBUG-DIE: */ die(__METHOD__.':poolInstance='.print_r($poolInstance, TRUE));
+ //* DEBUG-DIE: */ die(__METHOD__.':poolInstance.arrayFromList('.$protocolName.')='.print_r($poolInstance->getArrayFromList($protocolName), TRUE));
+
/*
* Now we need to choose again. It is whether we are speaking with a hub
* or with a client. So just handle it over to all listeners in this
// Make sure the instance is valid
assert($listenerInstance instanceof Listenable);
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-DISCOVERY: Calling listenerInstance->ifListenerAcceptsPackageData(%d) ...', count($packageData)));
+
// Does the listener want that package?
if ($listenerInstance->ifListenerAcceptsPackageData($packageData)) {
// This listener likes our package data, so abort here
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-DISCOVERY: Listener is accepting package data.');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-DISCOVERY: Listener "%s" is accepting package data.', $listenerInstance->__toString()));
break;
} // END - if
* @throws NoListGroupException If the procol group is not found in peer list
* @throws NullPointerException If listenerInstance is NULL
* @throws InvalidUnlException If the provided UNL cannot be validated by the protocol handler
+ * @throws LogicException If the discovered listener instance has no pool set
*/
public function discoverSocket (array $packageData, $connectionType) {
// Debug message
if (is_null($listenerInstance)) {
// Abort with no resource
throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } // END - if
+ } elseif (is_null($listenerInstance->getPoolInstance())) {
+ // Opps another one
+ throw new LogicException(sprintf('listenerInstance=%s has no poolInstance set.', $listenerInstance->__toString()), self::EXCEPTION_IS_NULL_POINTER);
+ }
/*
* Now we have the listener instance, we can determine the right
$socketInstance = self::createObjectByConfiguredName('socket_container_class', array($socketResource, StorableSocket::SOCKET_PROTOCOL_FILE, $packageData));
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FILE_LISTENER: socketInstance[]=%s', gettype($socketInstance)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: socketInstance[]=%s', gettype($socketInstance)));
// Is the socket resource valid?
if (!$socketInstance->isValidSocket()) {
* @throws InvalidSocketException Thrown if the socket could not be initialized
*/
public static function createListenTcpSocket (Listenable $listenerInstance) {
+ // Trace message
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: listenerInstance=%s - CALLED!', $listenerInstance->__toString()));
+
// Create a streaming socket, of type TCP/IP
$socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
* @throws InvalidSocketException Thrown if the socket could not be initialized
*/
public static function createListenUdpSocket (Listenable $listenerInstance) {
+ // Trace message
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: listenerInstance=%s - CALLED!', $listenerInstance->__toString()));
+
// Create a streaming socket, of type TCP/IP
$socketResource = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
* @throws LogicException If the current instance is not valid
*/
public static final function createNextAcceptedSocketFromPool (Poolable $poolInstance, StorableSocket $socketInstance) {
+ // Trace message
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: poolInstance=%s,socketInstance.socketResource=%s - CALLED!', $poolInstance->__toString(), $socketInstance->getSocketResource()));
+
// Is the an iterator instance?
if (!Registry::getRegistry()->instanceExists('pool_iterator')) {
// Create iterator instance
// Try to accept a new (incoming) socket from current listener instance
$acceptedSocketInstance = $current[Poolable::SOCKET_ARRAY_INSTANCE]->acceptNewIncomingSocket();
+ // Trace message
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: acceptedSocketInstance[]=%s - EXIT!', gettype($acceptedSocketInstance)));
+
// Return found socket instance
return $acceptedSocketInstance;
}
}
/**
- * Processes raw data from given resource. This is mostly useful for TCP
- * package handling and is implemented in the ???Listener class
+ * Processes raw data from given socket instance. This is mostly useful for
+ * ||| package handling and is implemented in the ???Listener class.
*
* @param $resource A valid socket resource array
* @return void
*/
- public function processRawDataFromResource (array $socketArray) {
+ public function processRawDataFromSocketArray (array $socketArray) {
}
}
* @return void
*/
protected function initStack () {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RAW-DATA-HANDLER: CALLED!');
+
+ // Init stack(s)
$this->getStackInstance()->initStack(self::STACKER_NAME_RAW_DATA);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RAW-DATA-HANDLER: EXIT!');
}
/**
* @return void
*/
protected function addRawDataToStacker ($rawData) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-DATA-HANDLER: rawData()=%d - CALLED!', strlen($rawData)));
+
/*
* Add the deocoded data and error code to the stacker so other classes
* (e.g. NetworkPackage) can "pop" it from the stacker.
self::PACKAGE_RAW_DATA => $rawData,
self::PACKAGE_ERROR_CODE => $this->getErrorCode()
));
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RAW-DATA-HANDLER: EXIT!');
}
/**
* @return $isPending Whether raw data is pending
*/
public function isRawDataPending () {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RAW-DATA-HANDLER: CALLED!');
+
// Does the stacker have some entries (not empty)?
$isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_RAW_DATA));
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-DATA-HANDLER: isPending=%d - EXIT!', intval($isPending)));
+
// Return it
return $isPending;
}
* @todo This method will be moved to a better place
*/
protected function ifRecipientMatchesOwnUniversalNodeLocator (array $packageData) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-DATA-HANDLER: packageData()=%d - CALLED!', strlen($packageData)));
+
// Construct own address first
$ownAddress = NodeObjectFactory::createNodeInstance()->determineUniversalNodeLocator();
// Does it match?
$matches = ($ownAddress === $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-DATA-HANDLER: matches=%d - EXIT!', intval($matches)));
+
// Return result
return $matches;
}
}
/**
- * Processes raw data from given resource. This is mostly useful for TCP
- * package handling and is implemented in the ???Listener class
+ * Processes raw data from given socket instance. This is mostly useful for
+ * raw package handling and is implemented in the ???Listener class.
*
* @param $resource A valid socket resource array
* @return void
*/
- public function processRawDataFromResource (array $socketArray) {
+ public function processRawDataFromSocketArray (array $socketArray) {
$this->partialStub('socketArray=' . print_r($socketArray, TRUE));
}
-}
-// [EOF]
-?>
+}
namespace Hub\Handler\Network\RawData\Tcp;
// Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
use Hub\Handler\Network\RawData\BaseRawDataHandler;
use Hub\Network\Networkable;
use Hub\Pool\Poolable;
+// Import framework stuff
+use CoreFramework\Socket\InvalidSocketException;
+
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A TCP raw data handler
*
}
/**
- * Processes raw data from given resource. This is mostly useful for TCP
- * package handling and is implemented in the TcpListener class
+ * Processes raw data from given socket instance. This is mostly useful for
+ * TCP package handling and is implemented in the TcpListener class.
*
* @param $resource A valid socket resource array
* @return void
+ * @throws InvalidArgumentException If the socket instance is not set
*/
- public function processRawDataFromResource (array $socketArray) {
+ public function processRawDataFromSocketArray (array $socketArray) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-RAWDATA-HANDLER: socketArray()=%d - CALLED!', count($socketArray)));
+
// Check the resource
- if ((!isset($socketArray[Poolable::SOCKET_ARRAY_INSTANCE])) || (!is_resource($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]))) {
+ if ((!isset($socketArray[Poolable::SOCKET_ARRAY_INSTANCE])) || (!($socketArray[Poolable::SOCKET_ARRAY_INSTANCE] instanceof StorableSocket))) {
// Throw an exception
- throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ throw new InvalidArgumentException(sprintf('socketArray[%s] is not set or invalid.', Poolable::SOCKET_ARRAY_INSTANCE));
} // END - if
// Reset error code to unhandled
$this->setErrorCode(self::SOCKET_ERROR_UNHANDLED);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: Handling TCP package from resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE] . ',last error=' . socket_strerror($this->lastSocketError));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-RAWDATA-HANDLER: Handling TCP package from resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE] . ',last error=' . socket_strerror($this->lastSocketError));
+ $this->partialStub('Please rewrite this part.');
+ return;
/*
* Read the raw data from socket. If you change PHP_BINARY_READ to
* PHP_NORMAL_READ, this line will endless block. This script does only
- * provide simultanous threads, not real.
+ * provide simultanous or faked threads, not real.
*/
$rawData = socket_read($socketArray[Poolable::SOCKET_ARRAY_INSTANCE], $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
// Get socket error code back
- $this->lastSocketError = socket_last_error($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
+ $this->lastSocketError = $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketLastErrorCode();
// Debug output of read data length
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: rawData[' . gettype($rawData) . ']=' . strlen($rawData) . ',MD5=' . md5($rawData) . ',resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',error=' . socket_strerror($this->lastSocketError));
- /* NOISY-DEBUG: */ if ($rawData !== FALSE) self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: rawData=' . $rawData);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-RAWDATA-HANDLER: rawData[' . gettype($rawData) . ']=' . strlen($rawData) . ',MD5=' . md5($rawData) . ',resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',this->lastSocketError=' . socket_strerror($this->lastSocketError));
+ /* NOISY-DEBUG: */ if ($rawData !== FALSE) self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-RAWDATA-HANDLER: rawData=' . $rawData);
// Is it valid?
if ($this->lastSocketError == 11) {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: Ignoring error 11 (Resource temporary unavailable) from socket resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-RAWDATA-HANDLER: Ignoring error 11 (Resource temporary unavailable) from socket resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
/*
* Error code 11 (Resource temporary unavailable) can be safely
* ignored on non-blocking sockets. The socket is currently not
* sending any data.
*/
- socket_clear_error($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
+ $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->clearLastSocketError();
// Skip any further processing
return;
// Network error or connection lost
$this->setErrorCode($this->lastSocketError);
} elseif (empty($rawData)) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-RAWDATA-HANDLER: No raw data pending. - EXIT!');
+
// The peer did send nothing to us which is now being ignored
return;
} else {
* well-formed BASE64-encoded message with start and markers. This
* will be checked later on.
*/
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: Adding ' . strlen($rawData) . ' bytes to stacker ...');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-RAWDATA-HANDLER: Adding ' . strlen($rawData) . ' bytes to stacker ...');
$this->addRawDataToStacker($rawData);
}
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-RAWDATA-HANDLER: EXIT!');
+
}
}
}
/**
- * Processes raw data from given resource. This is mostly useful for UDP
- * package handling and is implemented in the UdpListener class
+ * Processes raw data from given socket instance. This is mostly useful for
+ * UDP package handling and is implemented in the UDPListener class
*
- * @param $socketArray A valid socket resource array
+ * @param $resource A valid socket resource array
* @return void
- * @throws InvalidResourceException If the given resource is invalid
- * @todo 0%
+ * @throws InvalidArgumentException If the socket instance is not set
*/
- public function processRawDataFromResource (array $socketArray) {
+ public function processRawDataFromSocketArray (array $socketArray) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UDP-HANDLER: socketArray()=%d - CALLED!', count($socketArray)));
+
// Check the resource
- if ((!isset($socketArray[Poolable::SOCKET_ARRAY_INSTANCE])) || (!is_resource($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]))) {
+ if ((!isset($socketArray[Poolable::SOCKET_ARRAY_INSTANCE])) || (!($socketArray[Poolable::SOCKET_ARRAY_INSTANCE] instanceof StorableSocket))) {
// Throw an exception
- throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ throw new InvalidArgumentException(sprintf('socketArray[%s] is not set or invalid.', Poolable::SOCKET_ARRAY_INSTANCE));
} // END - if
- // Implement processing here
- $this->partialStub('Please implement this method. resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[Poolable::SOCKET_ARRRAY_CONN_TYPE]);
+ // Reset error code to unhandled
+ $this->setErrorCode(self::SOCKET_ERROR_UNHANDLED);
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UDP-HANDLER: Handling UDP package from resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE] . ',last error=' . socket_strerror($this->lastSocketError));
+ $this->partialStub('Please rewrite this part.');
+ return;
}
-}
-// [EOF]
-?>
+}
// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
use Hub\Factory\Information\Connection\ConnectionInfoFactory;
+use Hub\Factory\Network\Locator\UniversalNodeLocatorFactory;
use Hub\Factory\Node\NodeObjectFactory;
use Hub\Factory\Socket\SocketFactory;
use Hub\Generic\BaseHubSystem;
+use Hub\Information\ShareableInfo;
use Hub\Network\Package\NetworkPackage;
use Hub\Pool\Peer\PoolablePeer;
use Hub\Pool\Poolable;
use CoreFramework\Factory\Registry\Socket\SocketRegistryFactory;
use CoreFramework\Generic\UnsupportedOperationException;
use CoreFramework\Socket\InvalidServerSocketException;
+use CoreFramework\Socket\SocketAlreadyRegisteredException;
use CoreFramework\Visitor\Visitable;
use CoreFramework\Visitor\Visitor;
+// Import SPL stuff
+use \LogicException;
+
/**
* A general listener class
*
* @throws SocketAlreadyRegisteredException If the given resource is already registered
*/
protected function registerServerSocketInstance (StorableSocket $socketInstance) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('LISTENER: socketInstance=%s - CALLED!', $socketInstance->__toString()));
+
// First check if it is valid
if ($this->isServerSocketRegistered($socketInstance)) {
// Already registered
- throw new SocketAlreadyRegisteredException($this, self::EXCEPTION_SOCKET_ALREADY_REGISTERED);
+ throw new SocketAlreadyRegisteredException(array($this, $socketInstance->getSocketResource()), self::EXCEPTION_SOCKET_ALREADY_REGISTERED);
} // END - if
// Get a socket registry instance (singleton)
// Register the socket
$registryInstance->registerSocketInstance($infoInstance, $socketInstance);
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('LISTENER: Setting socketInstance ... (socketResource=%s)', $socketInstance->getSocketResource()));
+
// And set it here
$this->setSocketInstance($socketInstance);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('LISTENER: EXIT!');
}
/**
*
* @param $socketInstance An instance of a StorableSocket class
* @return $isRegistered Whether given server socket is registered
+ * @throws LogicException If no info instance can be created
*/
protected function isServerSocketRegistered (StorableSocket $socketInstance) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('LISTENER: socketInstance=%s - CALLED!', $socketInstance->__toString()));
+
// Get a socket registry instance (singleton)
$registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
// Get a connection info instance
$infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($this->getProtocolName(), 'listener');
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('LISTENER: infoInstance[]=%s', gettype($infoInstance)));
+
+ // Is the instance set?
+ if (!($infoInstance instanceof ShareableInfo)) {
+ // Should not happen
+ throw new LogicException(sprintf('infoInstance[]=%s does not implement ShareableInfo', gettype($infoInstance)));
+ } // END - if
+
// Will the info instance with listener data
$infoInstance->fillWithListenerInformation($this);
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('LISTENER: Checking socketInstance ... (socketResource=%s)', $socketInstance->getSocketResource()));
+
// Check it
$isRegistered = $registryInstance->isSocketRegistered($infoInstance, $socketInstance);
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('LISTENER: isRegistered=%d - EXIT!', intval($isRegistered)));
+
// Return result
return $isRegistered;
}
* @return void
*/
protected function doListenSocketSelect ($peerSuffix) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('LISTENER: peerSuffix=%s - CALLED!', $peerSuffix));
+
// Check on all instances
assert($this->getPoolInstance() instanceof Poolable);
assert($this->getSocketInstance()->isValidSocket());
// Get next socket instance from pool over the factory
$socketInstance = SocketFactory::createNextAcceptedSocketFromPool($this->getPoolInstance(), $this->getSocketInstance());
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('LISTENER: socketInstance[]=%s accepted.', gettype($socketInstance)));
+
// Is socket instance set?
if (!($socketInstance instanceof StorableSocket)) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('LISTENER: No new connection on listener ... - EXIT!');
+
// Nothing has changed on the listener
return;
} // END - if
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('LISTENER: socketInstance.socketResource=%s accepted.', $socketInstance->getSocketResource()));
+
// Init peer address/port
$peerAddress = '0.0.0.0';
$peerPort = '0';
// Get the current value
$currentSocketData = $this->getIteratorInstance()->current();
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('LISTENER: currentSocketData=' . $currentSocketData[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $currentSocketData[Poolable::SOCKET_ARRAY_CONN_TYPE] . ',serverSocket=' . $this->getSocketInstance()->getSocketResource());
+
// Handle it here, if not main server socket
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: currentSocketData=' . $currentSocketData[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $currentSocketData[Poolable::SOCKET_ARRAY_CONN_TYPE] . ',serverSocket=' . $this->getSocketInstance()->getSocketResource());
if (($currentSocketData[Poolable::SOCKET_ARRAY_CONN_TYPE] != StorableSocket::CONNECTION_TYPE_SERVER) && (!$currentSocketData[Poolable::SOCKET_ARRAY_INSTANCE]->equals($this->getSocketInstance()))) {
// ... or else it will raise warnings like 'Transport endpoint is not connected'
- $this->getHandlerInstance()->processRawDataFromResource($currentSocketData);
+ $this->getHandlerInstance()->processRawDataFromSocketArray($currentSocketData);
} // END - if
// Advance to next entry. This should be the last line.
$this->getIteratorInstance()->next();
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('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
+ */
+ public function ifListenerAcceptsPackageData (array $packageData) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('LISTENER: packageData()=%d - CALLED!', count($packageData)));
+
+ // Check if same socket protocol
+ $socketProtocol = $this->getSocketInstance()->getSocketProtocol();
+
+ // Get UNL instance
+ $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+
+ // Get protocol from it
+ $unlProtocol = $unlInstance->getUnlProtocol();
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('LISTENER: unlInstance.unlProtocol=%s,socketProtocol=%s', $unlProtocol, $socketProtocol));
+
+ // Is same protocol?
+ $accepts = ($unlProtocol == $socketProtocol);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('LISTENER: accepts=%d - EXIT!', $accepts));
+
+ // Return the result
+ return $accepts;
}
}
* @return $poolInstance A peer pool instance
*/
public final function getPoolInstance () {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('LISTENER-DECORATOR: Getting poolInstance from inner listenerInstance=%s - CALLED!', $this->getListenerInstance()->__toString()));
+
+ // Get it
return $this->getListenerInstance()->getPoolInstance();
}
return;
} // END - if
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('LISTENER-DECORATOR: handlerInstance=%s', $handlerInstance->__toString()));
+
// Does the handler have some decoded data pending?
if (!$handlerInstance->isRawDataPending()) {
// No data is pending so skip further code silently
// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
use Hub\Factory\Socket\SocketFactory;
+use Hub\Factory\Tag\Package\PackageTagsFactory;
use Hub\Listener\BaseListener;
use Hub\Listener\Listenable;
* @return void
*/
public function doListen() {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Calling this->doListenSocketSelect() ... - CALLED!');
+
// Call super method
$this->doListenSocketSelect('');
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: EXIT!');
}
/**
* @return $accepts Whether this listener does accept
*/
public function ifListenerAcceptsPackageData (array $packageData) {
- $this->partialStub('Need to implement this method.');
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FILE-LISTENER: packageData()=%d - CALLED!', count($packageData)));
+
+ // Call parent method
+ if (!parent::ifListenerAcceptsPackageData($packageData)) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.');
+
+ // Is already different protocol
+ return FALSE;
+ } // END - if
+
+ // Debugging
+ /* DEBUG-DIE: */ die(__METHOD__.':packageData='.print_r($packageData, TRUE));
+
+ // Get a tags instance
+ $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
+
+ // So is the package accepted with this listener?
+ $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FILE-LISTENER: accepts=%d - EXIT!', $accepts));
+
+ // Return the result
+ return $accepts;
}
/**
* @return $accepts Whether this listener does accept
*/
public function ifListenerAcceptsPackageData (array $packageData) {
- // Get a tags instance
- $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
-
- // So is the package accepted with this listener?
- $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
-
- // Return the result
- return $accepts;
+ // Call inner method, no decoration is wanted in this method
+ return $this->getListenerInstance()->ifListenerAcceptsPackageData($packageData);
}
}
* @return void
*/
public function doListen () {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: Calling this->doListenSocketSelect(:0) ... - CALLED!');
+
// Call super method
$this->doListenSocketSelect(':0');
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: EXIT!');
}
/**
* @return $accepts Whether this listener does accept
*/
public function ifListenerAcceptsPackageData (array $packageData) {
+ // 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)) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.');
+
+ // Is already different protocol
+ return FALSE;
+ } // END - if
+
+ // Debugging
+ /* DEBUG-DIE: */ die(__METHOD__.':packageData='.print_r($packageData, TRUE));
+
// Get a tags instance
$tagsInstance = PackageTagsFactory::createPackageTagsInstance();
// So is the package accepted with this listener?
$accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-TCP-LISTENER: accepts=%d - EXIT!', $accepts));
+
// Return the result
return $accepts;
}
-}
-// [EOF]
-?>
+}
* @return $accepts Whether this listener does accept
*/
public function ifListenerAcceptsPackageData (array $packageData) {
+ // 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)) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.');
+
+ // Is already different protocol
+ return FALSE;
+ } // END - if
+
+ // Debugging
+ /* DEBUG-DIE: */ die(__METHOD__.':packageData='.print_r($packageData, TRUE));
+
// Get a tags instance
$tagsInstance = PackageTagsFactory::createPackageTagsInstance();
// So is the package accepted with this listener?
$accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TCP-LISTENER: accepts=%d - EXIT!', $accepts));
+
// Return the result
return $accepts;
}
-}
-// [EOF]
-?>
+}
// Import framework stuff
use CoreFramework\Factory\ObjectFactory;
+use CoreFramework\Generic\UnsupportedOperationException;
/**
* An UDP connection listener
* @return void
*/
public function initListener () {
- // Get socket instance
+ // Get instance from socket factory
$socketInstance = SocketFactory::createListenUdpSocket($this);
- // Remember the socket in our class
+ // Set socket instance
$this->registerServerSocketInstance($socketInstance);
+ // Initialize the peer pool instance
+ $poolInstance = ObjectFactory::createObjectByConfiguredName('node_pool_class', array($this));
+
+ // Add main socket
+ $poolInstance->addPeer($socketInstance, StorableSocket::CONNECTION_TYPE_SERVER);
+
+ // And add it to this listener
+ $this->setPoolInstance($poolInstance);
+
+ // Initialize iterator for listening on packages
+ $iteratorInstance = $poolInstance->createListIteratorInstance('network_listen');
+
+ // Rewind it and remember it in this class
+ $iteratorInstance->rewind();
+ $this->setIteratorInstance($iteratorInstance);
+
// Initialize the network package handler
$handlerInstance = ObjectFactory::createObjectByConfiguredName('udp_raw_data_handler_class');
* "Listens" for incoming network packages
*
* @return void
- * @todo ~50% done
*/
- public function doListen() {
- $this->partialStub('Please rewrite this part.');
- return;
-
- // Read a package and determine the peer
- $amount = @socket_recvfrom($this->getSocketInstance(), $rawData, $this->getConfigInstance()->getConfigEntry('udp_buffer_length'), MSG_DONTWAIT, $peer, $port);
-
- // Get last error
- $lastError = $this->getSocketInstance()->getSocketLastErrorCode();
-
- // Do we have an error at the line?
- if ($lastError == 11) {
- /*
- * This (resource temporary unavailable) can be safely ignored on
- * "listening" UDP ports. If we don't clear the error here, our UDP
- * "listener" won't read any packages except if the UDP sender
- * starts the transmission before this "listener" came up...
- */
- $this->getSocketInstance()->clearLastSocketError();
-
- // Skip further processing
- return;
- } elseif ($lastError > 0) {
- // Other error detected
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UDP-LISTENER: Error detected: ' . socket_strerror($lastError));
-
- // Skip further processing
- return;
- } elseif ((empty($rawData)) || (trim($peer) == '')) {
- // Zero sized packages/peer names are usual in non-blocking mode
- return;
- } // END - if
-
- // Debug only
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UDP-LISTENER: Handling UDP package with size ' . strlen($rawData) . ' from peer ' . $peer . ':' . $port);
+ public function doListen () {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UDP-LISTENER: Calling this->doListenSocketSelect(:0) ... - CALLED!');
+
+ // Call super method
+ $this->doListenSocketSelect(':0');
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UDP-LISTENER: EXIT!');
}
/**
*
* @param $packageData Raw package data
* @return $accepts Whether this listener does accept
+ * @throws UnsupportedOperationException If this method is called
*/
- function ifListenerAcceptsPackageData (array $packageData) {
- $this->partialStub('This call should not happen. Please report it.');
+ public function ifListenerAcceptsPackageData (array $packageData) {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
-}
-// [EOF]
-?>
+}
* @return $accepts Whether this listener does accept
*/
function ifListenerAcceptsPackageData (array $packageData) {
+ // 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)) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.');
+
+ // Is already different protocol
+ return FALSE;
+ } // END - if
+
+ // Debugging
+ /* DEBUG-DIE: */ die(__METHOD__.':packageData='.print_r($packageData, TRUE));
+
// Get a tags instance
$tagsInstance = PackageTagsFactory::createPackageTagsInstance();
// So is the package accepted with this listener?
$accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-UDP-LISTENER: accepts=%d - EXIT!', $accepts));
+
// Return the result
return $accepts;
}
-}
-// [EOF]
-?>
+}
* @return $accepts Whether this listener does accept
*/
public function ifListenerAcceptsPackageData (array $packageData) {
+ // 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)) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.');
+
+ // Is already different protocol
+ return FALSE;
+ } // END - if
+
+ // Debugging
+ /* DEBUG-DIE: */ die(__METHOD__.':packageData='.print_r($packageData, TRUE));
+
// Get a tags instance
$tagsInstance = PackageTagsFactory::createPackageTagsInstance();
// So is the package accepted with this listener?
$accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-UDP-LISTENER: accepts=%d - EXIT!', $accepts));
+
// Return the result
return $accepts;
}
-}
-// [EOF]
-?>
+}
* @return $isPending Whether decoded raw data is pending
*/
private function isRawDataPending () {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: CALLED!');
+
// Just return whether the stack is not empty
$isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECODED_INCOMING));
* @return $hasArrived Whether new raw package data has arrived for processing
*/
public function isNewRawDataPending () {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: Calling this->getListenerPoolInstance()->accept(%s) ... - CALLED!', $this->getVisitorInstance()));
+
// Visit the pool. This monitors the pool for incoming raw data.
$this->getListenerPoolInstance()->accept($this->getVisitorInstance());
// Check for new data arrival
$hasArrived = $this->isRawDataPending();
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: hasArrived=%d - EXIT!', intval($hasArrived)));
+
// Return the status
return $hasArrived;
}
// Init the pool entries
$this->poolEntriesInstance = ObjectFactory::createObjectByConfiguredName('pool_entries_list_class');
+
+ // Register this instance as call-back
+ $this->getPoolEntriesInstance()->setCallbackInstance($this);
}
/**
return $iteratorInstance;
}
+ /**
+ * Creates a hash based on given entry
+ *
+ * @param $entry Array entry to be used
+ * @return $hash Hash from it
+ */
+ public function generateListHashFromEntry (array $entry) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: entry()=%d - CALLED!', count($entry)));
+
+ // Debugging:
+ //* DEBUG-DIE: */ die(__METHOD__.':entry='.print_r($entry, TRUE));
+
+ // Init variable
+ $hash = NULL;
+
+ // Is 'instance' and 'connection_type' set?
+ if ((isset($entry[Poolable::SOCKET_ARRAY_INSTANCE])) && (isset($entry[Poolable::SOCKET_ARRAY_CONN_TYPE]))) {
+ // Get socket resource and type
+ $hash = $entry[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource() . ':' . $entry[Poolable::SOCKET_ARRAY_CONN_TYPE];
+ } else {
+ // Not supported
+ $this->debugInstance(sprintf('[%s:%d]: entry=%s is not supported.', __METHOD__, __LINE__, print_r($entry, TRUE)));
+ }
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: hash[%s]=%s - EXIT!', gettype($hash), $hash));
+
+ // Return hash
+ return $hash;
+ }
+
}
} // END - if
} else {
// Server sockets won't work with socket_getpeername()
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: Socket resource is server socket (' . $socketInstance->getSocketResource() . '). This is not a bug.');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEFAULT-PEER-POOL: Socket resource is server socket (' . $socketInstance->getSocketResource() . '). This is not a bug.');
}
// Debug message
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: Adding peer ' . $peerAddress . ':' . $peerPort . ',socketResource=' . $socketInstance->getSocketResource() . ',connectionType=' . $connectionType);
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEFAULT-PEER-POOL: Adding peer ' . $peerAddress . ':' . $peerPort . ',socketResource=' . $socketInstance->getSocketResource() . ',connectionType=' . $connectionType);
// Construct the array
$socketArray = array(
*/
public function getSocketFromPackageData (array $packageData, $connectionType = NULL) {
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL:packageData()=%d,connectionType[%s]=%s - CALLED!', count($packageData), gettype($connectionType), $connectionType));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL:packageData()=%d,connectionType[%s]=%s - CALLED!', count($packageData), gettype($connectionType), $connectionType));
// Default is no socket
$socketInstance = NULL;
$unlInstance = $handlerInstance->getUniversalNodeLocatorInstance();
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: Checking ' . count($this->getAllSockets()) . ' socket(s),unlInstance.unl=' . $unlInstance->generateUnl() . ' ...');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEFAULT-PEER-POOL: Checking ' . count($this->getAllSockets()) . ' socket(s),unlInstance.unl=' . $unlInstance->generateUnl() . ' ...');
// Default is all sockets
$sockets = $this->getAllSockets();
// Get all sockets and check them, skip the server socket
foreach ($sockets as $socketArray) {
// Debugging:
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: socketArray(%d)=%s', count($socketArray), implode(',', $socketArray)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: socketArray(%d)=%s', count($socketArray), implode(',', $socketArray)));
//* DEBUG-DIE: */ die(__METHOD__.':connectionType='.$connectionType.',socketArray='.print_r($socketArray, TRUE));
// Is connection type set?
throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE);
} elseif ((!empty($connectionType)) && ($socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE] !== $connectionType)) {
// Skip unwanted sockets
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: Skipping unwanted socket %s of type %s/%s ...', $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE], $connectionType));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: Skipping unwanted socket %s of type %s/%s ...', $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE], $connectionType));
continue;
}
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: socketInstance.socketResource=%s,socketInstance.socketProtocol=%s,socketArray[%s]=%s', $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketProtocol(), Poolable::SOCKET_ARRAY_CONN_TYPE, $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE]));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: socketInstance.socketResource=%s,socketInstance.socketProtocol=%s,socketArray[%s]=%s', $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketProtocol(), Poolable::SOCKET_ARRAY_CONN_TYPE, $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE]));
// Init peer address/port
$peerAddress = '0.0.0.0';
} // END - if
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: peerAddress=%s,peerPort=%d,unlInstance.addressPart=%s', $peerAddress, $peerPort, $unlInstance->getAddressPart()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: peerAddress=%s,peerPort=%d,unlInstance.addressPart=%s', $peerAddress, $peerPort, $unlInstance->getAddressPart()));
// If the "peer" IP and recipient is same, use it
if ($peerAddress == $unlInstance->getAddressPart()) {
$socketInstance = $socketArray[Poolable::SOCKET_ARRAY_INSTANCE];
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: peerAddress=%s matches with recipient IP address. Taking socketResource=%s,type=%s', $peerAddress, $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE]));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: peerAddress=%s matches with recipient IP address. Taking socketResource=%s,type=%s', $peerAddress, $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE]));
break;
} // END - if
} // END - foreach
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEFAULT-PEER-POOL: socketInstance[]=' . gettype($socketInstance) . ' - EXIT!');
+
// Return the determined socket instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: socketInstance[]=' . gettype($socketInstance));
return $socketInstance;
}
use CoreFramework\Registry\BaseRegistry;
use CoreFramework\Registry\Register;
use CoreFramework\Registry\Sub\SubRegistry;
+use CoreFramework\Socket\SocketAlreadyRegisteredException;
/**
* A Socket registry
// Is the socket already registered?
if ($this->isSocketRegistered($infoInstance, $socketInstance)) {
// Throw the exception
- throw new SocketAlreadyRegisteredException(array($infoInstance, $socketInstance), BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED);
+ throw new SocketAlreadyRegisteredException(array($infoInstance, $socketInstance->getSocketResource()), BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED);
} // END - if
// Does the instance exist?
// Get package instance
$packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-READER-TASK: packageInstance=%s', $packageInstance->__toString()));
+
// Do we have something to handle?
if ($packageInstance->isProcessedMessagePending()) {
// Trace message
// Do monitor here
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RAWDATA-MONITOR-VISITOR: Visiting decoratorInstance=' . $decoratorInstance->__toString() . ' - CALLED!');
$decoratorInstance->monitorIncomingRawData();
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RAWDATA-MONITOR-VISITOR: Visiting decoratorInstance=' . $decoratorInstance->__toString() . ' - FINISH');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RAWDATA-MONITOR-VISITOR: Visiting decoratorInstance=' . $decoratorInstance->__toString() . ' - EXIT!');
}
}
// Do "listen" here
/* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ACTIVE-TASK-VISITOR: Visiting listenerInstance=' . $listenerInstance->__toString() . ' - CALLED!');
$listenerInstance->doListen();
- /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ACTIVE-TASK-VISITOR: Visiting listenerInstance=' . $listenerInstance->__toString() . ' - FINISH');
+ /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ACTIVE-TASK-VISITOR: Visiting listenerInstance=' . $listenerInstance->__toString() . ' - EXIT!');
}
/**
// Inport application-specific stuff
use Hub\Handler\Protocol\HandleableProtocol;
+// Import framework stuff
+use CoreFramework\Socket\AbstractSocketException;
+
/**
* This exception is thrown when the requested socket is not thrown
*
// Import application-specific stuff
use Hub\Helper\Connection\ConnectionHelper;
+// Import framework stuff
+use CoreFramework\Socket\AbstractSocketException;
+
/**
* This exception is thrown if the socket cannot be shut down is not error 107
* which is "Transport endpoint not connected".
*/
interface Networkable extends HandleableDataSet, HubInterface {
/**
- * Processes raw data from given resource. This is mostly useful for TCP
- * package handling and is implemented in the TcpListener class
+ * Processes raw data from given socket instance. This is mostly useful for
+ * package handling and is implemented in the TcpListener class.
*
* @param $socketData A valid socket resource array
* @return void
* @throws InvalidResourceException If the given resource is invalid
*/
- function processRawDataFromResource (array $socketData);
+ function processRawDataFromSocketArray (array $socketData);
/**
* Checks whether decoded data is pending for further processing.
-Subproject commit 0a6b81dde16619b6d4466cca1ff8ad52226e9384
+Subproject commit fc0b718d5c258e187b226e2a088769e5d14fcc1f