Esempio n. 1
0
 def close(self):
     """
     Closes this bus and all services registered on it.
     """
     if self.closed: # Already closed
         return
     self.closed = True
     # First we shut down all of our discoverers
     for discoverer in self.discoverers:
         discoverer.shutdown()
     # Then we need to close all of our services. Closing a service causes
     # self._close_service to be called, which removes the service from the
     # list of services, which causes self.local_service_changed to be
     # called, which unpublishes the service. So we don't need to worry
     # about unpublishing services aside from this.
     for service_id in list(self.local_services):
         self.local_services[service_id].close()
     # Then we shut down all of the publishers
     for publisher in self.publishers:
         publisher.shutdown()
     # Then we shut down the server socket
     net.shutdown(self.server)
     # Then we close all of the connections currently connected to us
     for c in self.bound_connections:
         with no_exceptions:
             c.close()
Esempio n. 2
0
 def shutdown(self):
     with self.bus.lock:
         for k in self.services:
             self.bus.undiscover(self, *k)
         self.services.clear()
     self.running = False
     net.shutdown(self.receiver)
Esempio n. 3
0
 def cleanup(self):
     """
     Cleans up this connection, removing all event listeners and object
     watches it's registered, closing network connections, shutting down
     threads, etc. This is used as the InputThread's cleanup function.
     """
     with self.bus.lock:
         # Make sure the OutputThread closes down
         self.queue.put(None)
         # Remove ourselves from the bus's list of connections
         self.bus.bound_connections.remove(self)
         # Shut down our socket
         net.shutdown(self.socket)
         # If we've bound to a service, remove any object watches and event
         # listeners we've registered
         if self.service:
             for name in self.watched_objects:
                 self.service.object_values.unwatch(name, self.watched_object_changed)
             for name in self.listened_events:
                 self.service.event_listeners.unlisten(name, self.listened_event_fired)
Esempio n. 4
0
 def receive_loop(self):
     while True:
         message = None
         try:
             message = self.receiver.recvfrom(16384)[0]
         except (SocketError, SocketTimeout):
             pass
         if not self.running:
             net.shutdown(self.sender)
             return
         self.run_recurring()
         if not message:
             continue
         try:
             message = json.loads(message)
             if message["command"] == "query":
                 self.broadcast_services()
         except:
             print "Couldn't read message in BroadcastPublisher"
             print_exc()
             continue
Esempio n. 5
0
 def receive_loop(self):
     while True:
         message = None
         try:
             message, (host, port) = self.receiver.recvfrom(16384)
         except (SocketError, SocketTimeout):
             pass
         if not self.running:
             net.shutdown(self.sender)
             return
         self.run_recurring()
         if not message:
             continue
         try:
             message = json.loads(message)
             if message["command"] == "add":
                 self.process_add(host, message["port"], message["service"], message["info"])
             elif message["command"] == "remove":
                 self.process_remove(host, message["port"], message["service"])
         except:
             print "Couldn't read message"
             print_exc()
             continue
Esempio n. 6
0
 def close(self):
     """
     Forces this connection to close and disconnect its client.
     """
     self.queue.put(None)
     net.shutdown(self.socket)
Esempio n. 7
0
 def shutdown(self):
     # print "Shutting down"
     self.running = False
     net.shutdown(self.receiver)