+ /**
+ * Creates a full-qualified file name (FQFN) for given file name by adding
+ * a configured temporary file path to it.
+ *
+ * @param $fileName Name for temporary file
+ * @return $fqfn Full-qualified file name
+ * @throw PathWriteProtectedException If the path in 'temp_file_path' is write-protected
+ * @throws FileIoException If the file cannot be written
+ */
+ protected static function createTempPathForFile ($fileName) {
+ // Get config entry
+ $basePath = FrameworkConfiguration::getSelfInstance()->getConfigEntry('temp_file_path');
+
+ // Is the path writeable?
+ if (!is_writable($basePath)) {
+ // Path is write-protected
+ throw new PathWriteProtectedException($fileName, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
+ } // END - if
+
+ // Add it
+ $fqfn = $basePath . '/' . $fileName;
+
+ // Is it reachable?
+ if (!self::isReachableFilePath($fqfn)) {
+ // Not reachable
+ throw new FileIoException($fqfn, self::EXCEPTION_FILE_NOT_REACHABLE);
+ } // END - if
+
+ // Return it
+ return $fqfn;
+ }
+
+ /**
+ * "Getter" for a printable state name
+ *
+ * @return $stateName Name of the node's state in a printable format
+ */
+ public final function getPrintableState () {
+ // Default is 'null'
+ $stateName = 'null';
+
+ // Get the state instance
+ $stateInstance = $this->getStateInstance();
+
+ // Is it an instance of Stateable?
+ if ($stateInstance instanceof Stateable) {
+ // Then use that state name
+ $stateName = $stateInstance->getStateName();
+ } // END - if
+
+ // Return result
+ return $stateName;
+ }
+
+ /**
+ * Handles socket error for given socket resource and peer data. This method
+ * validates $socketResource if it is a valid resource (see is_resource())
+ * but assumes valid data in array $recipientData, except that
+ * count($recipientData) is always 2.
+ *
+ * @param $method Value of __METHOD__ from calling method
+ * @param $line Value of __LINE__ from calling method
+ * @param $socketResource A valid socket resource
+ * @param $socketData A valid socket data array (0 = IP/file name, 1 = port)
+ * @return void
+ * @throws InvalidSocketException If $socketResource is no socket resource
+ * @throws NoSocketErrorDetectedException If socket_last_error() gives zero back
+ * @todo Move all this socket-related stuff into own class, most of it resides in BaseListener
+ */
+ protected final function handleSocketError ($method, $line, $socketResource, array $socketData) {
+ // This method handles only socket resources
+ if (!is_resource($socketResource)) {
+ // No resource, abort here
+ throw new InvalidSocketException(array($this, $socketResource), BaseListener::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+
+ // Check socket array, 1st element is mostly IP address (or file name), 2nd is port number
+ //* DEBUG-DIE: */ die(__METHOD__ . ':socketData=' . print_r($socketData, TRUE));
+ assert(isset($socketData[0]));
+ assert(isset($socketData[1]));
+
+ // Get error code for first validation (0 is not an error)
+ $errorCode = socket_last_error($socketResource);
+
+ // If the error code is zero, someone called this method without an error
+ if ($errorCode == 0) {
+ // No error detected (or previously cleared outside this method)
+ throw new NoSocketErrorDetectedException(array($this, $socketResource), BaseListener::EXCEPTION_NO_SOCKET_ERROR);
+ } // END - if
+
+ // Get handler (method) name
+ $handlerName = $this->getSocketErrorHandlerFromCode($errorCode);
+
+ // Call-back the error handler method
+ call_user_func_array(array($this, $handlerName), array($socketResource, $socketData));
+
+ // Finally clear the error because it has been handled
+ socket_clear_error($socketResource);
+ }
+
+}