From eb13f8968c9d8193fb8f519b53d3aabf81451837 Mon Sep 17 00:00:00 2001 From: Simon Samtleben Date: Sun, 15 Jan 2012 19:10:07 +0100 Subject: [PATCH] Some improvements/bugfixes on receiving binary frames. --- client/coffee/client.coffee | 3 +-- server/lib/WebSocket/Application/DemoApplication.php | 11 +++++++++-- server/lib/WebSocket/Connection.php | 2 +- server/lib/WebSocket/Server.php | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/client/coffee/client.coffee b/client/coffee/client.coffee index be6f3b8..e7147b5 100644 --- a/client/coffee/client.coffee +++ b/client/coffee/client.coffee @@ -33,8 +33,7 @@ $(document).ready -> payload = new Object() payload.action = 'setFilename' payload.data = $('#file').val() - socket.send JSON.stringify payload - i for i in [1..1000000] + socket.send JSON.stringify payload socket.send(data) return false \ No newline at end of file diff --git a/server/lib/WebSocket/Application/DemoApplication.php b/server/lib/WebSocket/Application/DemoApplication.php index a1cc3da..5f58ba6 100644 --- a/server/lib/WebSocket/Application/DemoApplication.php +++ b/server/lib/WebSocket/Application/DemoApplication.php @@ -71,8 +71,15 @@ private function _actionEcho($text) private function _actionSetFilename($filename) { - $filename = basename($filename); - if(!empty($filename)) + if(strpos($filename, '\\') !== false) + { + $filename = substr($filename, strrpos($filename, '\\')+1); + } + elseif(strpos($filename, '/') !== false) + { + $filename = substr($filename, strrpos($filename, '/')+1); + } + if(!empty($filename)) { $this->_filename = $filename; return true; diff --git a/server/lib/WebSocket/Connection.php b/server/lib/WebSocket/Connection.php index cbc931f..d6200ce 100644 --- a/server/lib/WebSocket/Connection.php +++ b/server/lib/WebSocket/Connection.php @@ -480,7 +480,7 @@ private function hybi10Decode($data) * data is transferd. */ if(strlen($data) < $dataLength) - { + { return false; } diff --git a/server/lib/WebSocket/Server.php b/server/lib/WebSocket/Server.php index 3d83d98..82f477b 100644 --- a/server/lib/WebSocket/Server.php +++ b/server/lib/WebSocket/Server.php @@ -35,7 +35,7 @@ public function run() while(true) { $changed_sockets = $this->allsockets; - socket_select($changed_sockets, $write = null, $except = null, null); + socket_select($changed_sockets, $write = null, $except = null, 0, 5000); foreach($changed_sockets as $socket) { if($socket == $this->master) @@ -76,7 +76,7 @@ public function run() else { $client = $this->clients[(int)$socket]; - $bytes = socket_recv($socket, $data, 1024, 0); + $bytes = socket_recv($socket, $data, 8192, 0); if($bytes === false) {