use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
use Org\Mxchange\CoreFramework\Generic\NullPointerException;
+use Org\Mxchange\CoreFramework\Helper\Helper;
use Org\Mxchange\CoreFramework\Registry\Registerable;
use Org\Mxchange\CoreFramework\Socket\InvalidSocketException;
use Org\Mxchange\CoreFramework\Socket\NoSocketErrorDetectedException;
*/
public function shutdownSocket () {
// Debug message
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Shutting down socket ' . $this->getSocketResource() . ' with state ' . $this->getHelperInstance()->getPrintableState() . ' ...');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Shutting down socket ' . $this->getSocketResource() . ' with state ' . ($this->getHelperInstance() instanceof Helper ? $this->getHelperInstance()->getPrintableState() : 'NULL') . ' ...');
// Get a visitor instance
$visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
$socketResource = socket_accept($this->getSocketResource());
// Create socket instance from it
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socketResource=%s,serverSocket=%s', strtoupper($this->getSocketProtocol()), $socketResource, $this->getSocketResource()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s,serverSocket=%s', strtoupper($this->getSocketProtocol()), $socketResource, $this->getSocketResource()));
$socketInstance = SocketFactory::createIncomingSocketInstance($socketResource, $this->getSocketProtocol());
// Return accepted socket instance
*/
public function clearLastSocketError () {
// Should be valid socket
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Clearing socket error, socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Clearing socket error, this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
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(sprintf('%s-SOCKET: Error cleared - EXIT!', strtoupper($this->getSocketProtocol())));
}
/**
*/
public function registerInfoInstance (ShareableInfo $infoInstance) {
// Get listener/helper from info class
- //* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Calling infoInstance->getListenerInstance() - CALLED!', strtoupper($this->getSocketProtocol())));
+ /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: infoInstance=%s,this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $infoInstance->__toString(), $this->getSocketResource()));
$listenerInstance = $infoInstance->getListenerInstance();
$helperInstance = $infoInstance->getHelperInstance();
// Is there a listener instance set?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: listenerInstance[]=' . gettype($listenerInstance) . ',helperInstance[]=' . gettype($helperInstance));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: listenerInstance[]=%s,helperInstance[]=%s', strtoupper($this->getSocketProtocol()), gettype($listenerInstance), 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() . ' ...');
}
// Is some data still pending or sent all out?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Sending out %d bytes,rawBufferSize=%d,diff=%d to socketResource=%s', strtoupper($this->getSocketProtocol()), strlen($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA]), $socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE], $socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF], $this->getSocketResource()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Sending out %d bytes,rawBufferSize=%d,diff=%d to this->socketResource=%s', strtoupper($this->getSocketProtocol()), strlen($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA]), $socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE], $socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF], $this->getSocketResource()));
if ($socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF] >= 0) {
// Send all out (encodedData is smaller than or equal buffer size)
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: MD5=%s', strtoupper($this->getSocketProtocol()), md5(substr($socketBuffer[NetworkPackageHandler::RAW_INDEX_ENCODED_DATA], 0, ($socketBuffer[NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE] - $socketBuffer[NetworkPackageHandler::RAW_INDEX_DIFF])))));
use \InvalidArgumentException;
use \LogicException;
use \SplFileInfo;
+use \UnexpectedValueException;
/**
* A socket factory class
* @param $listenerInstance An instance of a Listenable class
* @return $socketInstance An instance of a StorableSocket class
* @throws InvalidSocketException If the socket cannot be completed
+ * @throws UnexpectedValueException If $socketFile is empty
*/
public static final function createListenFileSocket (Listenable $listenerInstance) {
// Create SplFileInfo
- /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: listenerInstance=%s - EXIT!', $listenerInstance->__toString()));
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: listenerInstance=%s - CALLED!', $listenerInstance->__toString()));
$fileInfo = new SplFileInfo(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('ipc_socket_file_name'));
// Create file name
$socketFile = self::createTempPathForFile($fileInfo);
- // Debug message
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: socketFile=' . $socketFile . ' ...');
-
// File name must not be empty
- assert(!empty($socketFile));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: socketFile=' . $socketFile . ' ...');
+ if (empty($socketFile)) {
+ // Something unexpected
+ throw new UnexpectedValueException('socketFile is empty');
+ }
// Init package instance
$packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
$socketResource = socket_create(AF_UNIX, SOCK_STREAM, 0);
// Get container from it
- $socketInstance = self::createObjectByConfiguredName('socket_container_class', array(
+ $socketInstance = self::createObjectByConfiguredName('socket_container_class', [
$socketResource,
StorableSocket::SOCKET_PROTOCOL_FILE,
$packageInstance,
StorableSocket::CONNECTION_TYPE_SERVER,
- ));
+ ]);
// Set socket file
$socketInstance->setSocketFile($socketFile);