}
// And return it
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-SOCKET-DISCOVERY: socketInstance=%s,socketInstance->socketResource=%s - EXIT!', $socketInstance->__toString(), $socketInstance->getSocketResource()));
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: socketResource=' . $socketInstance->getSocketResource() . ',packageInstance=' . print_r($packageInstance, TRUE));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-SOCKET-DISCOVERY: socketInstance=%s,socketInstance->socketResource=%s - EXIT!', $socketInstance->__toString(), $socketInstance->getPrintableName()));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: socketResource=' . $socketInstance->getPrintableName() . ',packageInstance=' . print_r($packageInstance, TRUE));
return $socketInstance;
}
$socketInstance = self::$socketRegistryInstance->getInstance($registryKey);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: Using socketResource[%s]=%s from registry.', gettype($socketInstance->getSocketResource()), $socketInstance->getSocketResource()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: Using socketResource[%s]=%s from registry.', gettype($socketInstance->getSocketResource()), $socketInstance->getPrintableName()));
} else {
// Invoke inner factory
$socketInstance = ObjectFactory::createObjectByConfiguredName(sprintf('%s_connection_helper_class', $protocolInstance->getProtocolName()), array($packageInstance));
*/
public static final function createNextAcceptedSocketFromPool (Poolable $poolInstance, StorableSocket $socketInstance) {
// Invoke static initializer
- /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: poolInstance=%s,socketInstance->socketResource=%s - CALLED!', $poolInstance->__toString(), $socketInstance->getSocketResource()));
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: poolInstance=%s,socketInstance->socketResource=%s - CALLED!', $poolInstance->__toString(), $socketInstance->getPrintableName()));
self::staticInitializer();
// Get socket protocol
$this->setErrorCode(StorableSocket::SOCKET_ERROR_UNHANDLED);
// Read the raw data from socket in a loop
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-RAW-DATA-HANDLER: Handling TCP package from socketResource=%s,last error=%s,socketType=%s', $socketInstance->getSocketResource(), $socketInstance->getLastSocketErrorMessage(), $socketInstance->getSocketType()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-RAW-DATA-HANDLER: Handling TCP package from socketResource=%s,last error=%s,socketType=%s', $socketInstance->getPrintableName(), $socketInstance->getLastSocketErrorMessage(), $socketInstance->getSocketType()));
while ($rawData = $socketInstance->readDataFromSocket()) {
// Get socket error code back
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-RAW-DATA-HANDLER: rawData(%d)[]=%s', strlen($rawData), gettype($rawData)));
* ignored on non-blocking sockets. The socket is currently not
* sending any data.
*/
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-RAW-DATA-HANDLER: Ignoring error 11 (Resource temporary unavailable) from socketResource=%s - CONTINUE!', $socketInstance->getSocketResource()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-RAW-DATA-HANDLER: Ignoring error 11 (Resource temporary unavailable) from socketResource=%s - CONTINUE!', $socketInstance->getPrintableName()));
$socketInstance->clearLastSocketError();
// Is there anything to add to the stacker?
$this->setErrorCode(StorableSocket::SOCKET_ERROR_UNHANDLED);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UDP-HANDLER: Handling UDP package from socketResource=%s,last error=%s', $socketInstance->getSocketResource(), $socketInstance->getLastSocketErrorMessage()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UDP-HANDLER: Handling UDP package from socketResource=%s,last error=%s', $socketInstance->getPrintableName(), $socketInstance->getLastSocketErrorMessage()));
DebugMiddleware::getSelfInstance()->partialStub('Please rewrite this part.');
return;
}
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-LISTENER: socketInstance=%s - CALLED!', strtoupper($this->getProtocolName()), $socketInstance->__toString()));
if ($this->isServerSocketRegistered($socketInstance)) {
// Already registered
- throw new SocketAlreadyRegisteredException(array($this, $socketInstance->getSocketResource()), self::EXCEPTION_SOCKET_ALREADY_REGISTERED);
+ throw new SocketAlreadyRegisteredException([$this, $socketInstance->getSocketResource()], self::EXCEPTION_SOCKET_ALREADY_REGISTERED);
}
// Get a connection info instance
$infoInstance->fillWithListenerInformation($this);
// Register the socket
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-LISTENER: Registering socketInstance->socketResource=%s,socketType=%s ...', strtoupper($this->getProtocolName()), $socketInstance->getSocketResource(), $socketInstance->getSocketType()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-LISTENER: Registering socketInstance->socketResource=%s,socketType=%s ...', strtoupper($this->getProtocolName()), $socketInstance->getPrintableName(), $socketInstance->getSocketType()));
$this->getRegistryInstance()->registerSocketInstance($infoInstance, $socketInstance);
// And set it here
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-LISTENER: Setting socketInstance=%s (socketResource=%s) ...', strtoupper($this->getProtocolName()), $socketInstance->__toString(), $socketInstance->getSocketResource()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-LISTENER: Setting socketInstance=%s (socketResource=%s) ...', strtoupper($this->getProtocolName()), $socketInstance->__toString(), $socketInstance->getPrintableName()));
$this->setSocketInstance($socketInstance);
// Trace message
$infoInstance->fillWithListenerInformation($this);
// Check it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-LISTENER: Checking socketInstance ... (socketResource=%s)', strtoupper($this->getProtocolName()), $socketInstance->getSocketResource()));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-LISTENER: Checking socketInstance ... (socketResource=%s)', strtoupper($this->getProtocolName()), $socketInstance->getPrintableName()));
$isRegistered = $this->getRegistryInstance()->isSocketRegistered($infoInstance, $socketInstance);
// Return result
$socketInstance->setSenderPort($peerPort);
// Register the socket with the registry and with the faked array
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-LISTENER: Registering socketInstance->socketResource=%s,socketType=%s ...', strtoupper($this->getProtocolName()), $socketInstance->getSocketResource(), $socketInstance->getSocketType()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-LISTENER: Registering socketInstance->socketResource=%s,socketType=%s ...', strtoupper($this->getProtocolName()), $socketInstance->getPrintableName(), $socketInstance->getSocketType()));
$this->getRegistryInstance()->registerSocketInstance($infoInstance, $socketInstance);
// Invoke private method
$this->setHandlerInstance($handlerInstance);
// Output message
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Socket listener now ready on socket ' . $socketInstance->getSocketResource() . ' for service.');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Socket listener now ready on socket ' . $socketInstance->getPrintableName() . ' for service.');
}
/**
use Org\Mxchange\CoreFramework\Visitor\Visitable;
use Org\Mxchange\CoreFramework\Visitor\Visitor;
+// Import SPL stuff
+use \Iterator;
+
/**
* A general pool class
*
* @param $visitableInstance An instance of a class that should bed added to the pool
* @return void
*/
- protected final function addInstance ($group, $poolName, Visitable $visitableInstance) {
+ protected final function addInstance (string $group, string $poolName, Visitable $visitableInstance): void {
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: group=' . $group . ',poolName=' . $poolName . ',visitableInstance=' . $visitableInstance->__toString() . ' - CALLED!');
* @param $poolEntry The new pool entry that should be added
* @return void
*/
- protected final function addPoolEntry ($poolEntry) {
+ protected final function addPoolEntry ($poolEntry): void {
$this->getPoolEntriesInstance()->addEntry('pool', $poolEntry);
}
* @param $list The list identifier we should return
* @return $array The requested array
*/
- public final function getArrayFromList (string $list) {
+ public final function getArrayFromList (string $list): array {
// Get the array
$array = $this->getPoolEntriesInstance()->getArrayFromList($list);
* @param $visitorInstance An instance of a Visitor class
* @return void
*/
- public function accept (Visitor $visitorInstance) {
+ public function accept (Visitor $visitorInstance): void {
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - CALLED!');
*
* @return void
*/
- public function preShutdown () {
+ public function preShutdown (): void {
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: Shutting down listener pool - CALLED!');
* @param $poolType Pool type (e.g. socket_listen)
* @return $iteratorInstance An instance of a Iterator class
*/
- public function createListIteratorInstance ($poolType) {
+ public function createListIteratorInstance (string $poolType): Iterator {
// Create iterator instance
$iteratorInstance = ObjectFactory::createObjectByConfiguredName($poolType . '_iterator_class', array($this->getPoolEntriesInstance()));
* @param $entry Array entry to be used
* @return $hash Hash from it
*/
- public function generateListHashFromEntry (array $entry) {
+ public function generateListHashFromEntry (array $entry): string {
// Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: entry()=%d - CALLED!', count($entry)));
// 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];
+ $hash = $entry[Poolable::SOCKET_ARRAY_INSTANCE]->getPrintableName() . ':' . $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)));
*/
private function validateSocket (StorableSocket $socketInstance) {
// Is it a valid resource?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-SYSTEM: socketInstance->socketResource=%s - CALLED!', $socketInstance->getSocketResource()));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-SYSTEM: socketInstance->socketResource=%s - CALLED!', $socketInstance->getPrintableName()));
if (!$socketInstance->isValidSocket()) {
// Throw an exception
throw new InvalidSocketException([$this, $socketInstance->getSocketResource()], self::EXCEPTION_INVALID_SOCKET);
*/
public function addPeer (StorableSocket $socketInstance, string $connectionType) {
// Validate parameter
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: socketResource[%s]=%s,connectionType=%s - CALLED!', gettype($socketInstance->getSocketResource()), $socketInstance->getSocketResource(), $connectionType));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: socketResource[%s]=%s,connectionType=%s - CALLED!', gettype($socketInstance->getSocketResource()), $socketInstance->getPrintableName(), $connectionType));
if (empty($connectionType)) {
// Throw exception
throw new InvalidArgumentException('Parameter "connectionType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
}
} else {
// Server sockets won't work with socket_getpeername()
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEFAULT-PEER-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->getPrintableName() . '). This is not a bug.');
}
// Construct the array
- /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEFAULT-PEER-POOL: Adding peer ' . $peerAddress . ':' . $peerPort . ',socketResource=' . $socketInstance->getSocketResource() . ',connectionType=' . $connectionType);
+ /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEFAULT-PEER-POOL: Adding peer ' . $peerAddress . ':' . $peerPort . ',socketResource=' . $socketInstance->getPrintableName() . ',connectionType=' . $connectionType);
$socketArray = [
Poolable::SOCKET_ARRAY_INSTANCE => $socketInstance,
Poolable::SOCKET_ARRAY_CONN_TYPE => $connectionType
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-REGISTRY: infoInstance->protocolName=%s,infoInstance->socketResource[%s]=%s - CALLED!', $infoInstance->getProtocolName(), gettype($socketInstance->getSocketResource()), $socketInstance->getPrintableName()));
if ($this->isSocketRegistered($infoInstance, $socketInstance)) {
// Throw the exception
- throw new SocketAlreadyRegisteredException(array($infoInstance, $socketInstance->getSocketResource()), BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED);
+ throw new SocketAlreadyRegisteredException([$infoInstance, $socketInstance->getSocketResource()], BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED);
}
// Create registry key
// Still no socket resource?
if (!$socketInstance->isValidSocket()) {
// Then abort here with an exception (may happen after socket_shutdown())
- throw new InvalidSocketException(array($helperInstance, $socketInstance->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException([$helperInstance, $socketInstance->getSocketResource()], self::EXCEPTION_INVALID_SOCKET);
}
}
// Import application-specific stuff
use Org\Shipsimu\Hub\Generic\HubInterface;
+// Import SPL stuff
+use \Iterator;
+
/**
* A Poolable interface
*
* @param $list The list identifier we should return
* @return $array The requested array
*/
- function getArrayFromList (string $list);
+ function getArrayFromList (string $list): array;
/**
* Getter for pool entries instance
*
* @return void
*/
- function preShutdown ();
+ function preShutdown (): void;
/**
* Creates an iterator from inner list instance.
* @param $poolType Pool type (e.g. 'socket_listen', 'network_listen')
* @return $iteratorInstance An instance of a Iterator class
*/
- function createListIteratorInstance (string $poolType);
+ function createListIteratorInstance (string $poolType): Iterator;
+
+ /**
+ * Creates a hash based on given entry
+ *
+ * @param $entry Array entry to be used
+ * @return $hash Hash from it
+ */
+ function generateListHashFromEntry (array $entry): string;
}
* @param $fragmenterInstance A Fragmentable instance
* @return void
*/
- private final function setFragmenterInstance (Fragmentable $fragmenterInstance) {
+ private function setFragmenterInstance (Fragmentable $fragmenterInstance) {
$this->fragmenterInstance = $fragmenterInstance;
}
-Subproject commit 76a44f7f1b907c63484c751f1fcf19730c553b7d
+Subproject commit b0d8c80500e1b796f2398c44f20b36173bfc4d6c