use \BadMethodCallException;
use \InvalidArgumentException;
use \LogicException;
+use \Socket;
use \SplFileInfo;
/**
private $senderPort;
/**
- * Socket resource
+ * Socket instance
*/
- private $socketResource = false;
+ private $socketResource = NULL;
/**
* Protected constructor
/**
* Creates an instance of this Container class and prepares it for usage
*
- * @param $socketResource A valid socket resource
+ * @param $socketResource An instance of a Socket class
* @param $socketProtocol Socket protocol (TCP, UDP, file)
* @param $packageInstance An instance of a DeliverablePackage class
* @param $socketType Socket type (incoming, outgoing, server, file, ...)
* @return $socketInstance An instance of a StorableSocket class
* @throws InvalidArgumentException If a parameter is not valid
*/
- public static final function createSocketContainer ($socketResource, string $socketProtocol, DeliverablePackage $packageInstance, string $socketType) {
+ public static final function createSocketContainer (Socket $socketResource, string $socketProtocol, DeliverablePackage $packageInstance, string $socketType) {
// Validate parameter
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-CONTAINER: socketResource[%s]=%s,socketProtocol=%s,packageInstance=%s,socketType=%s - CALLED!', gettype($socketResource), $socketResource, $socketProtocol, $packageInstance->__toString(), $socketType));
- if (!is_resource($socketResource)) {
- // Throw exception
- throw new InvalidArgumentException(sprintf('socketResource[]=%s is not valid', $socketResource));
- } elseif (empty($socketProtocol)) {
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-CONTAINER: socketResource[]=%s,socketProtocol=%s,packageInstance=%s,socketType=%s - CALLED!', gettype($socketResource), $socketProtocol, $packageInstance->__toString(), $socketType));
+ if (empty($socketProtocol)) {
// Throw again
throw new InvalidArgumentException('Parameter "socketProtocol" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
} elseif (empty($socketType)) {
/**
* Checks whether the given socket matches with stored
*
- * @param $socketResource A valid socket resource
+ * @param $socketResource An instance of a Socket class
* @return $matches Whether given socket matches
*/
- public function ifSocketResourceMatches ($socketResource) {
+ public function ifSocketResourceMatches (Socket $socketResource) {
// So, does both match?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(strtoupper($this->getSocketProtocol()) . '-SOCKET: socketResource[' . gettype($socketResource) . ']=' .$socketResource . ',storedResource[' . gettype($this->getSocketResource()) . ']=' . $this->getSocketResource());
- $matches = ((is_resource($socketResource)) && ($socketResource === $this->getSocketResource()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: socketResource[]=%s,storedResource[]=%s - CALLED!', strtoupper($this->getSocketProtocol()), gettype($socketResource)), gettype($this->getSocketResource()));
+ $matches = ($socketResource === $this->getSocketResource());
// Return result
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: matches=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($matches)));
$socketResource = socket_accept($this->getSocketResource());
// Create socket instance from it
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-SOCKET: this->socketResource=%s,serverSocket=%s', strtoupper($this->getSocketProtocol()), $socketResource, $this->getSocketResource()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-SOCKET: this->socketResource[]=%s,serverSocket=%s', strtoupper($this->getSocketProtocol()), gettype($socketResource), $this->getSocketResource()));
$socketInstance = SocketFactory::createIncomingSocketInstance($socketResource, $this->getSocketProtocol());
// Return accepted socket instance
/**
* Setter for socket resource
*
- * @param $socketResource A valid socket resource
+ * @param $socketResource An instance of a Socket class
* @return void
*/
- public final function setSocketResource ($socketResource) {
+ public final function setSocketResource (Socket $socketResource) {
$this->socketResource = $socketResource;
}
* Registers a new peer with given package data. We use the session id from it.
*
* @param $packageInstance An instance of a DeliverablePackage class
- * @param $socketResource An instance of a StorableSocket class
+ * @param $socketInstance An instance of a StorableSocket class
* @return void
* @throws PeerAlreadyRegisteredException If a peer is already registered
*/
*
* @param $packageInstance An instance of a DeliverablePackage class array
* @param $connectionType Type of connection, can be either 'incoming' or 'outgoing', but *NEVER* 'server'!
- * @return $socketResource A valid socket resource or FALSE if an error occured
+ * @return $socketInstance An instance of a StorableSocket class
* @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
// Import SPL stuff
use \InvalidArgumentException;
use \LogicException;
+use \Socket;
use \SplFileInfo;
use \UnexpectedValueException;
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketInstance=%s', $socketInstance->__toString()));
if (!$socketInstance->isValidSocket()) {
// Something bad happened
- throw new InvalidSocketException(array($listenerInstance, $socketInstance->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException([$listenerInstance, $socketInstance->getSocketResource()], self::EXCEPTION_INVALID_SOCKET);
}
// Check if there was an error else
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: packageInstance=%s - CALLED!', $packageInstance->__toString()));
$socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- // Is it a socket resource?
- /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketResource[]=%s', gettype($socketResource)));
- if (!is_resource($socketResource)) {
- // Throw UVE
- throw new UnexpectedValueException(sprintf('socketResource[]=%s is not expected, could not create socket', gettype($socketResource)));
- }
-
// Create socket instance
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketResource[]=%s', gettype($socketResource)));
$socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', [
$socketResource,
StorableSocket::SOCKET_PROTOCOL_TCP,
/* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: listenerInstance=%s - CALLED!', $listenerInstance->__toString()));
$socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- // Is it a socket resource?
+ // Debug message
/* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketResource[]=%s', gettype($socketResource)));
- if (!is_resource($socketResource)) {
- // Throw UVE
- throw new UnexpectedValueException(sprintf('socketResource[]=%s is not expected, could not create socket', gettype($socketResource)));
- }
// Init fake "package" instance, the SocketContainer class requires this
$packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
/* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: listenerInstance=%s - CALLED!', $listenerInstance->__toString()));
$socketResource = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
- // Is it a socket resource?
+ // Debug message
/* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketResource[]=%s', gettype($socketResource)));
- if (!is_resource($socketResource)) {
- // Throw UVE
- throw new UnexpectedValueException(sprintf('socketResource[]=%s is not expected, could not create socket', gettype($socketResource)));
- }
// Init fake "package" instance, the SocketContainer class requires this
$packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketInstance=%s', $socketInstance->__toString()));
if (!$socketInstance->isValidSocket()) {
// Something bad happened
- throw new InvalidSocketException(array($listenerInstance, $socketInstance), self::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException([$listenerInstance, $socketInstance], self::EXCEPTION_INVALID_SOCKET);
}
// Check if there was an error else
* @return $socketInstance An instance of a StorableSocket class
* @throws InvalidArgumentException If a parameter is not valid
*/
- public static final function createIncomingSocketInstance ($socketResource, string $socketProtocol) {
+ public static final function createIncomingSocketInstance (Socket $socketResource, string $socketProtocol) {
// Validate parameter
- /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: socketResource[%s]=%s,socketProtocol=%s - CALLED!', gettype($socketResource), $socketResource, $socketProtocol));
- if (!is_resource($socketResource)) {
- // Throw exception
- throw new InvalidArgumentException(sprintf('socketResource[]=%s is not valid', gettype($socketResource)));
- } elseif (empty($socketProtocol)) {
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: socketResource[]=%s,socketProtocol=%s - CALLED!', gettype($socketResource), $socketProtocol));
+ if (empty($socketProtocol)) {
// Throw it again
throw new InvalidArgumentException('Parameter "socketProtocol" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
}
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-SYSTEM: socketInstance->socketResource=%s - CALLED!', $socketInstance->getSocketResource()));
if (!$socketInstance->isValidSocket()) {
// Throw an exception
- throw new InvalidSocketException(array($this, $socketInstance->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException([$this, $socketInstance->getSocketResource()], self::EXCEPTION_INVALID_SOCKET);
}
// Get error code
use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
// Import PHP stuff
+use \Socket;
use \SplFileInfo;
/**
/**
* Checks whether the given socket matches with stored
*
- * @param $socketResource A valid socket resource
+ * @param $socketResource An instance of a Socket class
* @return $matches Whether given socket matches
*/
- function ifSocketResourceMatches ($socketResource);
+ function ifSocketResourceMatches (Socket $socketResource);
/**
* Shuts down a given socket resource. This method does only ease calling
-Subproject commit f993e439e838c8cea3a98b1254c2cf340d68bc77
+Subproject commit 3ad2578dc223f97de06547be49d66e7adfea677c