diff --git a/phpws/websocket.functions.php b/phpws/websocket.functions.php index 6d38093..109b961 100644 --- a/phpws/websocket.functions.php +++ b/phpws/websocket.functions.php @@ -73,7 +73,7 @@ public static function readWholeBuffer($resource){ } $result = fread($resource, $buffsize); - if($result === false || feof($resource)) + if($result === false) { return false; } diff --git a/phpws/websocket.server.php b/phpws/websocket.server.php index e55722d..303b7d6 100644 --- a/phpws/websocket.server.php +++ b/phpws/websocket.server.php @@ -91,6 +91,28 @@ public function setStreamContext($context){ $this->_context = $context; } + /** + * Unassociate a request uri to a IWebSocketResourceHandler. + * + * @param string $script For example 'handler1' to capture request with URI '/handler1/' + * @param $disconnectUsers if true, disconnect users assosiated to handler. + */ + public function removeUriHandler($script, $disconnectUsers = true){ + + if ( empty($this->uriHandlers[$script]) ) return false; + $handler = $this->uriHandlers[$script]; + unset( $this->uriHandlers[$script] ); + + if ($disconnectUsers) foreach($handler->getConnections() as $user){ + + $handler->removeConnection($user); + $user->disconnect(); + } + + return $handler; + } + + /** * Start the server */