Commits

Ginés Martínez Sánchez committed 93ecdd6 Draft

fixed bug in large messages of websocket

  • Participants
  • Parent commits 3ebf9cd
  • Tags 0.5.3

Comments (0)

Files changed (5)

File ginsfsm/gconfig.py

                 continue
             try:
                 self._write_parameter(parameter, value)
-            except:
+            except Exception as e:
                 # In real time don't raise exceptions, only at setup
-                pass
+                if self.logger:
+                    self.logger.exception(e)
 
     def write_parameters(self, **kw):
         """ Write parameters.

File ginsfsm/gmsg.py

                     #
                     #  Con los bytes de este segm hay suficiente
                     #
-                    data = self.rd_segm.data[
+                    data += self.rd_segm.data[
                         self.rd_segm.head:self.rd_segm.head + ln]
                     self.rd_segm.head += ln
                     return data

File ginsfsm/protocols/sockjs/server/c_websocket.py

             unmasked = gmsg.getdata(ln)
             if cur_frame.h_mask:
                 h_mask = cur_frame.masking_key
-                for i in range(ln):
+                for i in list(range(ln)):
                     unmasked[i] = unmasked[i] ^ h_mask[i % 4]
 
         if cur_frame.h_fin:
                     try:
                         message = message.decode("utf-8")
                     except:
-                        pass
+                        self.logger.error("ERROR websocket decoding utf-8")
+                        self.logger.error(hexdump('<==', message))
+
                     if self.trace_mach:
-                        self.logger.debug(
-                            "%r: RECEIVE Websocket text FRAME: %r" % (
-                            self, message)
+                        self.logger.info(
+                            "%r: RECEIVE Websocket text FRAME" % (self)
                         )
+                        self.logger.info(hexdump('<==', message))
+
                     self.gaplic.add_callback(
                         self.broadcast_event,
                         'EV_ON_MESSAGE',
         """
         _m = array.array("B", mask_key)
         _d = array.array("B", data)
-        for i in range(len(_d)):
+        for i in list(range(len(_d))):
             _d[i] ^= _m[i % 4]
         return _d.tostring()
 

File ginsfsm/router.py

     """
     websocket = event.source[-1]
     msg = event.data
-    print("KKKKKKKKKKKKKKKKKKjson_decode:\n%s" % (hexdump('<==', msg)))
 
     try:
         msg = json_decode(msg)

File ginsfsm/tests/test_gmsg.py

         self.assertEqual(data, b"123")
 
     def test_getdata_full(self):
+        self.gmsg.putdata("123ab")
+        data = self.gmsg.getdata(5)
+        self.assertEqual(data, b"123ab")
+
+    def test_getdata_all(self):
         self.gmsg.putdata("1234567890abcde")
-        data = self.gmsg.getdata(3)
-        self.assertEqual(data, b"123")
-        data = self.gmsg.getdata(3)
-        self.assertEqual(data, b"45")
-        data = self.gmsg.getdata(3)
-        self.assertEqual(data, None)
 
     def test_getchar(self):
         self.gmsg.putdata("123ab")