+ /**
+ * Registeres the given socket resource for "this" listener instance. This
+ * will be done in a seperate class to allow package writers to use it
+ * again.
+ *
+ * @param $socketResource A valid server socket resource
+ * @return void
+ * @throws InvalidServerSocketException If the given resource is no server socket
+ * @throws SocketAlreadyRegisteredException If the given resource is already registered
+ */
+ protected function registerServerSocketResource ($socketResource) {
+ // First check if it is valid
+ if (!$this->isServerSocketResource($socketResource)) {
+ // No server socket
+ throw new InvalidServerSocketException(array($this, $socketResource), self::EXCEPTION_INVALID_SOCKET);
+ } elseif ($this->isServerSocketRegistered($socketResource)) {
+ // Already registered
+ throw new SocketAlreadyRegisteredException($this, self::EXCEPTION_SOCKET_ALREADY_REGISTERED);
+ }
+
+ // Get a socket registry instance (singleton)
+ $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
+
+ // Register the socket
+ $registryInstance->registerSocket($this, $socketResource);
+ }
+
+ /**
+ * Checks wether given socket resource is registered in socket registry
+ *
+ * @param $socketResource A valid server socket resource
+ * @return $isRegistered Wether given server socket is registered
+ */
+ protected function isServerSocketRegistered ($socketResource) {
+ // Get a socket registry instance (singleton)
+ $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
+
+ // Check it
+ $isRegistered = $registryInstance->isSocketRegistered($this, $socketResource);
+
+ // Return result
+ return $isRegistered;
+ }
+
+ /**
+ * Getter for "this" socket resource
+ *
+ * @return $socketResource A valid socket resource
+ */
+ public final function getSocketResource () {
+ // Get a socket registry instance (singleton)
+ $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
+
+ // Get the socket resource
+ $socketResource = $registryInstance->getSocketResource($this);
+
+ // Return it
+ return $socketResource;
+ }
+