OSDN Git Service

websocket error handling enhance
authorISHIKAWA Mutsumi <ishikawa@hanzubon.jp>
Mon, 29 Nov 2010 00:31:40 +0000 (09:31 +0900)
committerISHIKAWA Mutsumi <ishikawa@hanzubon.jp>
Mon, 29 Nov 2010 00:31:40 +0000 (09:31 +0900)
data/public/webkit.js
keitairc

index 4cb8a4b..ec9ece1 100644 (file)
@@ -51,7 +51,6 @@ jQuery(document).ready(function($) {
     var map_load = true;
     var myScroll;
     var ws = false;
-    var prev_cid = 0;
 
     $(window).bind('orientationchange', function(){
        adjust_height();
@@ -75,33 +74,27 @@ jQuery(document).ready(function($) {
        $('#loading').css('display', 'block').height($(document).height());
        $('body').append($('<div id="'+url.replace('/','_')+'"></div>').attr('animation', anim).load(web_root + session_id + '/' + url, param, reinit));
 
+       if (ws) {
+           ws.close();
+           ws = false;
+       }
        try  {
             if (url.match(/all\/([0-9]+)/)) {
                var cid = RegExp.$1;
-               if (cid != prev_cid && ws) {
-                   ws.close();
-                   ws = false;
-               }
-               if (!ws) {
-                   ws = new WebSocket('ws://' + location.host + '/' + session_id + '/push/' + cid);
-                   ws.addEventListener("open",
-                                       function () {
-                                           /* alert('open'); */
-                                       },false);
-                   ws.addEventListener("close",
-                                       function () {
-                                           /* alert('close'); */
-                                       },false);
-                   ws.addEventListener("message",
-                                       function (e) {
-                                           var data = JSON.parse(e.data);
-                                           $('div.scroll_wrap ul.edgetoedge li.sep').after(data.formatted);
-                                       },false);
-                   prev_cid = cid;
-               }
-           } else {
-               ws.close();
-               ws = false;
+               ws = new WebSocket('ws://' + location.host + '/' + session_id + '/push/' + cid);
+               ws.addEventListener("open",
+                                   function () {
+                                       /* alert('open'); */
+                                   },false);
+               ws.addEventListener("close",
+                                   function () {
+                                       /* alert('close'); */
+                                   },false);
+               ws.addEventListener("message",
+                                   function (e) {
+                                       var data = JSON.parse(e.data);
+                                       $('div.scroll_wrap ul.edgetoedge li.sep').after(data.formatted);
+                                   },false);
            }
        } catch(e) {
 
index 8da3723..34a0750 100755 (executable)
--- a/keitairc
+++ b/keitairc
@@ -107,7 +107,9 @@ POE::Component::Server::TCP->new(
        Alias => 'keitairc',
        Port => $cf->web_listen_port(),
        ClientFilter => 'POE::Filter::HTTPD::Keitairc',
-       ClientInput => \&http_request);
+       ClientInput => \&http_request,
+       ClientError => \&on_error,
+    );
 
 # fire up main loop
 $poe_kernel->run();
@@ -134,6 +136,10 @@ sub http_request{
        $kernel->yield('shutdown');
 }
 
+sub on_error {
+       warn 'ClientError';
+       $ib->remove_stream($_[ARG3]);
+}
 ################################################################
 sub dispatch{
        my ($request, $heap) = @_;