Commits

Ginés Martínez Sánchez committed 2a91dcd Draft

dangerous!

Comments (0)

Files changed (5)

ginsfsm/c_sock.py

 
 def ac_write(self, event):
     """ Write in the output data buffer.
-        Equivalent to waitress' write_soon().
         The data are not really sent until _send_some() is called.
     """
     self.mt_write(event.data)
         self.mt_flush(callback)
 
     def mt_write(self, data):
-        """ Write data to the output buffer.
+        """ Write in the output data buffer.
+            Equivalent to waitress' write_soon().
+            The data are not really sent until _send_some() is called.
         """
         if data:
             if data.__class__ is ReadOnlyFileBasedBuffer:
     def mt_flush(self, callback=None):
         """ Send output buffer data to the network
         """
+        if not self.connected or not self.socket:
+            self.logger.error(
+                "ERROR %r trying mt_flush but DISCONNECTED" % self)
+            return
+
         # TODO: callback when TRANSMIT_READY
         self._transmit_ready_event_done = False
         self._send_some()
             parent_name = "%s:%s" % (parent.__class__.__name__, parent.name)
             name = parent_name + '.' + name
             parent = parent.parent
-        return "%s" % (name)
+        return "%s: %s" % (name, 'Destroyed' if self._destroyed else "Lived")
 
     def create_gobj(self, name, gclass, parent, **kw):
         """ Factory function to create gobj's instances.
 
         if destination._destroyed:
             logging.error(
-                "GObj ERROR internal: "
-                "sending event %r to a destroyed gobj", event.event_name
+                "ERROR internal: sending event %r to a destroyed gobj %r" % (
+                    event.event_name, destination)
             )
             return -1
 

ginsfsm/protocols/sockjs/server/c_transport_websocket.py

 from ginsfsm.protocols.sockjs.server.session import ConnectionInfo
 from ginsfsm.protocols.wsgi.webob.websocket_response import WebsocketResponse
 from ginsfsm.deferred import Deferred
+from ginsfsm.utils import hexdump
 
 
 #----------------------------------------------------------------#
             msg = json_decode(message)
 
         except Exception:
-            logging.exception('ERROR WebSocket json_decode')
+            logging.exception(
+                'ERROR WebSocket json_decode, gobj %r, msg %s' %
+                (self, hexdump('<==', message)))
             # Close running connection
             self.gsock.mt_drop()
+            return
 
         try:
             if isinstance(msg, list):
             else:
                 self.session.on_messages((msg,))
         except Exception:
-            logging.exception('ERROR WebSocket on_messages %r' % self)
+            logging.exception(
+                'ERROR WebSocket on_messages, gobj %r, msg %s' %
+                (self, hexdump('<==', message)))
             # Close running connection
             self.gsock.mt_drop()
 

ginsfsm/protocols/sockjs/server/c_websocket.py

 def ac_timeout_waiting_handshake(self, event):
     """ Too much time waiting the handshake.
     """
-    logging.error("ERROR websocket TIMEOUT waiting HANDSHAKE")
+    logging.error("ERROR websocket TIMEOUT waiting HANDSHAKE: %r" % self)
     self.on_close_broadcasted = True  # no on_open was broadcasted
     self.close()
 

ginsfsm/protocols/wsgi/common/wsgi_response.py

                             self.remove_content_length_header()
                         self.content_length = size
                     self.write(b'')  # generate headers
-                    self.gsock.write_soon(app_iter)
+                    self.gsock.mt_write(app_iter)
                     return
 
             first_chunk_len = None