Commits

Ginés Martínez Sánchez  committed 79ade52

improving named gobjs

  • Participants
  • Parent commits 66b63cb

Comments (0)

Files changed (5)

File ginsfsm/c_sock.py

     'host': [str, '', 0, None, "server or client host (ip or name)"],
     'port': [int, 0, 0, None, "server or client port"],
     'ssl_options': [dict, {}, 0, None, "ssl options"],
+    'use_named_clisrv': [bool, False, 0, None, "True if clisrv must be named"],
     'tx_buffer_size': [int, 4096, 0, None, ""],
     'connected_event_name': [str, 'EV_CONNECTED', 0, None,
         "Must be empty if you don't want receive this event"],
                 # the user and remove it from the socket_map (to prevent
                 # polling of broken sockets).
                 self.remove_socket()
-                raise
+                #raise
         self.sockname = self.socket.getsockname()
 
     def __repr__(self):
         return (self.host, self.port)
 
     def handle_connect(self):
+        if not self.addr:
+            # must use try? it should not raise!
+            self.addr = self.socket.getpeername()
+
+        self.sockname = self.socket.getsockname()
         data = {}
-        data['peername'] = self.socket.getpeername()
-        self.sockname = data['sockname'] = self.socket.getsockname()
-        logging.info("%s <== Connected! %s host '%s'" % (
+        data['sockname'] = self.sockname
+        data['peername'] = self.addr
+
+        logging.info("%s <== Connected! %s host %s" % (
             self.name,
             "FROM" if self._clisrv else "TO",
-            str(data['peername'])))
+            str(self.addr)))
         # remove WRITE
         self._impl_poll.modify(self._fileno, IOLoop.READ | IOLoop.ERROR)
         if self.connected_event_name is not None:
         """ Drop the connexion.
         """
         logging.info(
-            "%s ==> Disconnecting from host '%s', ip '%s', port %s..." % (
-            self.name, self.host, self.ip, self.port))
+            "%s ==> Drop from host '%s', %s..." % (
+            self.name, self.host, str(self.addr)))
         if self.socket:
             self.socket.shutdown(socket.SHUT_RDWR)
             self._impl_poll.modify(
                     'Unknown exception while trying to close outbuf')
         self.close()
         self.remove_socket()
-        if 0:
+        if 1:
             logging.info(
-                "%s <== Disconnected! from host '%s', port %s" % (
-                self.name, self.host, self.port))
+                "%s <== Disconnected! from %s" % (
+                self.name, str(self.addr)))
         #TODO: pon la causa del disconnect
         if self.disconnected_event_name is not None:
             self.broadcast_event(self.disconnected_event_name)

File ginsfsm/c_srv_sock.py

     'host': [str, '', 0, None, "server host (ip or name)"],
     'port': [int, 0, 0, None, "server port"],
     'ssl_options': [dict, {}, 0, None, "ssl options"],
+    'use_named_clisrv': [bool, False, 0, None, "True if clisrv must be named"],
 }
 
 
                     raise
 
         self._n_clisrv += 1
-        if self.name:
+        if self.name and self.use_named_clisrv:
             prefix_name = self.name
         else:
             prefix_name = None
-        channel = '.clisrv-gsock-%x' % self._n_clisrv
+        channel = '.clisrv-%x' % self._n_clisrv
 
         if self.ssl_options:
             gsock_class = GSSLSock

File ginsfsm/protocols/http/server/c_http_clisrv.py

 
 def ac_http_response(self, event):
     response = event.response
-    if response != self.responding_request:
-        logging.error("ERROR doesn't mach response %s" % response.request.path)
+    if response.request != self.responding_request:
+        logging.error("ERROR doesn't mach responding request %s" %
+                      response.request.path)
     self.stop_responseless_timer()
     self.responding_request = None
 

File ginsfsm/protocols/http/server/c_http_server.py

     gsock = event.source[-1]
     gsock.delete_all_subscriptions()
 
-    if self.name:
-        prefix_name = self.name
+    if gsock.name:
+        prefix_name = gsock.name
     else:
         prefix_name = None
-    channel = '.http.%s' % gsock.name
     clisrv = self.create_gobj(
-        prefix_name + channel if prefix_name else None,
+        prefix_name + '.channel' if prefix_name else None,
         GHttpCliSrv,
         self,
         gsock=gsock,
         else:
             prefix_name = None
         self.gserversock = self.create_gobj(
-            prefix_name + '.http-server' if prefix_name else None,
+            prefix_name + '.server-sock' if prefix_name else None,
             GServerSock,
             self,
             subscriber=self,  # Iniatially capture all events from new clisrv.

File ginsfsm/protocols/wsgi/server/c_wsgi_server.py

             prefix_name = None
 
         self.ghttpserver = self.create_gobj(
-            prefix_name + '.sock-server' if prefix_name else None,
+            prefix_name + '.http-server' if prefix_name else None,
             GHttpServer,
             self,
             subscriber=self,