namespace Hub\Factory\Socket;
// Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
use Hub\Handler\Protocol\HandleableProtocol;
use Hub\Listener\BaseListener;
use Hub\Listener\Listenable;
// Import application-specific stuff
use Hub\Handler\RawData\BaseRawDataHandler;
use Hub\Network\Networkable;
-use Hub\Pool\BasePool;
+use Hub\Pool\Poolable;
/**
* A TCP raw data handler
*/
public function processRawDataFromResource (array $socketArray) {
// Check the resource
- if ((!isset($socketArray[BasePool::SOCKET_ARRAY_INSTANCE])) || (!is_resource($socketArray[BasePool::SOCKET_ARRAY_INSTANCE]))) {
+ if ((!isset($socketArray[Poolable::SOCKET_ARRAY_INSTANCE])) || (!is_resource($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]))) {
// Throw an exception
throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
} // END - if
$this->setErrorCode(self::SOCKET_ERROR_UNHANDLED);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: Handling TCP package from resource=' . $socketArray[BasePool::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',last error=' . socket_strerror($this->lastSocketError));
+ //* 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));
/*
* 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.
*/
- $rawData = socket_read($socketArray[BasePool::SOCKET_ARRAY_INSTANCE], $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
+ $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[BasePool::SOCKET_ARRAY_INSTANCE]);
+ $this->lastSocketError = socket_last_error($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
// 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[BasePool::SOCKET_ARRAY_INSTANCE] . ',error=' . socket_strerror($this->lastSocketError));
+ //* 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);
// 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[BasePool::SOCKET_ARRAY_INSTANCE]);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-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[BasePool::SOCKET_ARRAY_INSTANCE]);
+ socket_clear_error($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
// Skip any further processing
return;
// Import application-specific stuff
use Hub\Handler\RawData\BaseRawDataHandler;
use Hub\Network\Networkable;
-use Hub\Pool\BasePool;
+use Hub\Pool\Poolable;
/**
* A UDP raw data handler
*/
public function processRawDataFromResource (array $socketArray) {
// Check the resource
- if ((!isset($socketArray[BasePool::SOCKET_ARRAY_INSTANCE])) || (!is_resource($socketArray[BasePool::SOCKET_ARRAY_INSTANCE]))) {
+ if ((!isset($socketArray[Poolable::SOCKET_ARRAY_INSTANCE])) || (!is_resource($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]))) {
// Throw an exception
throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
} // END - if
// Implement processing here
- $this->partialStub('Please implement this method. resource=' . $socketArray[BasePool::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[BasePool::SOCKET_ARRRAY_CONN_TYPE]);
+ $this->partialStub('Please implement this method. resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[Poolable::SOCKET_ARRRAY_CONN_TYPE]);
}
}
namespace Hub\Handler\RawData;
// Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
use Hub\Network\Package\NetworkPackage;
// Import framework stuff
parent::__construct($className);
// Set error code to 'unknown'
- $this->setErrorCode(self::SOCKET_ERROR_UNKNOWN);
+ $this->setErrorCode(StorableSocket::SOCKET_ERROR_UNKNOWN);
// Init stacker instance for processed raw data
$stackInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_stacker_class');
namespace Hub\Helper\Connection\IpV4;
// Import application-specific stuff
-use Hub\Container\Socket\StorableSocket;
use Hub\Helper\Connection\BaseConnectionHelper;
use Hub\Locator\Node\LocateableNode;
use Hub\Helper\Connection\BaseConnectionHelper;
use Hub\Network\Package\NetworkPackage;
use Hub\Pool\Peer\PoolablePeer;
+use Hub\Pool\Poolable;
// Import framework stuff
use CoreFramework\Factory\ObjectFactory;
$currentSocketData = $this->getIteratorInstance()->current();
// Handle it here, if not main server socket
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: currentSocketData=' . $currentSocketData[BasePool::SOCKET_ARRAY_INSTANCE] . ',type=' . $currentSocketData[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',serverSocket=' . $this->getSocketInstance()->getSocketResource());
- if (($currentSocketData[BasePool::SOCKET_ARRAY_CONN_TYPE] != BaseConnectionHelper::CONNECTION_TYPE_SERVER) && (!$currentSocketData[BasePool::SOCKET_ARRAY_INSTANCE]->equals($this->getSocketInstance()))) {
+ //* 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] != BaseConnectionHelper::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);
} // END - if
namespace Hub\Network\Package;
// Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
use Hub\Factory\Assembler\Package\PackageAssemblerFactory;
use Hub\Factory\Dht\DhtObjectFactory;
use Hub\Factory\Information\Connection\ConnectionInfoFactory;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
abstract class BasePool extends BaseHubSystem implements Poolable, Visitable {
- /**
- * Socket array elements
- */
- const SOCKET_ARRAY_INSTANCE = 'instance';
- const SOCKET_ARRAY_CONN_TYPE = 'connection_type';
-
/**
* A list of pool entries
*/
use Hub\Locator\Node\LocateableNode;
use Hub\Network\Package\NetworkPackage;
use Hub\Pool\BasePool;
+use Hub\Pool\Poolable;
use Hub\Pool\Peer\PoolablePeer;
// Import framework stuff
// Construct the array
$socketArray = array(
- self::SOCKET_ARRAY_INSTANCE => $socketInstance,
- self::SOCKET_ARRAY_CONN_TYPE => $connectionType
+ Poolable::SOCKET_ARRAY_INSTANCE => $socketInstance,
+ Poolable::SOCKET_ARRAY_CONN_TYPE => $connectionType
);
// Add it finally to the pool
// "Walk" through all socket arrays
foreach ($socketArrays as $socketArray) {
// Add the socket
- array_push($sockets, $socketArray[self::SOCKET_ARRAY_INSTANCE]);
+ array_push($sockets, $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
} // END - foreach
// Return it
// "Walk" through all socket arrays
foreach ($socketArrays as $socketArray) {
// Does it match?
- if ($socketArray[self::SOCKET_ARRAY_CONN_TYPE] === $connectionType) {
+ if ($socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE] === $connectionType) {
// Add the socket
- array_push($sockets, $socketArray[self::SOCKET_ARRAY_INSTANCE]);
+ array_push($sockets, $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
} // END - if
} // END - foreach
// Get all sockets and check them, skip the server socket
foreach ($sockets as $socketArray) {
// Is this a server socket?
- if ($socketArray[self::SOCKET_ARRAY_INSTANCE]->equals($this->getListenerInstance()->getSocketInstance())) {
+ if ($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->equals($this->getListenerInstance()->getSocketInstance())) {
// Skip 'server' sockets (local socket)
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: Skipping server socket ' . $socketArray[self::SOCKET_ARRAY_INSTANCE]->getSocketResource() . ' ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: Skipping server socket ' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource() . ' ...');
continue;
} // END - if
$peerPort = '0';
// Try to get the "peer"'s name
- if (!$socketArray[self::SOCKET_ARRAY_INSTANCE]->getSocketPeerName($peerAddress, $peerPort)) {
+ if (!$socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketPeerName($peerAddress, $peerPort)) {
// Handle the socket error with given package data
- $socketArray[self::SOCKET_ARRAY_INSTANCE]->handleSocketError(__METHOD__, __LINE__, explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+ $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->handleSocketError(__METHOD__, __LINE__, explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
} // END - if
// Get
// If the "peer" IP and recipient is same, use it
if ($peerAddress == $unlData[LocateableNode::UNL_PART_ADDRESS]) {
// IPs match, so take the socket and quit this loop
- $socketInstance = $socketArray[self::SOCKET_ARRAY_INSTANCE];
+ $socketInstance = $socketArray[Poolable::SOCKET_ARRAY_INSTANCE];
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: peerAddress=' . $peerAddress . ' matches with recipient IP address. Taking socket=' . $socketArray[self::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[self::SOCKET_ARRAY_CONN_TYPE]);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: peerAddress=' . $peerAddress . ' matches with recipient IP address. Taking socket=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE]);
break;
} // END - if
} // END - foreach
*/
class SocketRegistry extends BaseRegistry implements Register, RegisterableSocket {
// Exception constants
- const SOCKET_NOT_REGISTERED = 0xd200;
+ const EXCEPTION_SOCKET_NOT_REGISTERED = 0xd200;
/**
* Instance of this class
// The socket must be registered before we can return it
if (!$this->isInfoRegistered($listenerInstance)) {
// Throw the exception
- throw new NoSocketRegisteredException ($listenerInstance, self::SOCKET_NOT_REGISTERED);
+ throw new NoSocketRegisteredException ($listenerInstance, self::EXCEPTION_SOCKET_NOT_REGISTERED);
} // END - if
// Now get the key from the listener
*/
function getSessionId ();
- /**
- * Setter for socket instance
- *
- * @param $socketInstance A StorableSocket instance
- * @return void
- */
- function setSocketInstance (StorableSocket $socketInstance);
-
- /**
- * Getter for socket instance
- *
- * @return $socketInstance An instance of a StorableSocket class
- */
- function getSocketInstance ();
-
}
namespace Hub\Listener;
// Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
use Hub\Generic\HubInterface;
/**
*/
function getPoolInstance ();
+ /**
+ * Setter for socket instance
+ *
+ * @param $socketInstance A StorableSocket instance
+ * @return void
+ */
+ function setSocketInstance (StorableSocket $socketInstance);
+
+ /**
+ * Getter for socket instance
+ *
+ * @return $socketInstance An instance of a StorableSocket class
+ */
+ function getSocketInstance ();
+
}
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface Poolable extends HubInterface {
+ /**
+ * Socket array elements
+ */
+ const SOCKET_ARRAY_INSTANCE = 'instance';
+ const SOCKET_ARRAY_CONN_TYPE = 'connection_type';
/**
* Pre-shuts down the pool
-Subproject commit ca40302a326b814bbd5273a0540e18d672cf2d70
+Subproject commit b89f58d4d90b6d608b8e16b0e5e3235eaff4f54e