예제 #1
0
 def stop_server(self):
     if self.server is None:
         return
     try:
         # The server has been started successfully, shut it down now.  As
         # soon as we stop serving, no more connection are accepted except
         # one to get out of the blocking listen.
         self.set_ignored_exceptions(
             self.server.ignored_exceptions_during_shutdown)
         self.server.serving = False
         if debug_threads():
             sys.stderr.write('Server thread %s will be joined\n'
                              % (self._server_thread.name,))
         # The server is listening for a last connection, let's give it:
         last_conn = None
         try:
             last_conn = osutils.connect_socket((self.host, self.port))
         except socket.error, e:
             # But ignore connection errors as the point is to unblock the
             # server thread, it may happen that it's not blocked or even
             # not started.
             pass
         # We start shutting down the clients while the server itself is
         # shutting down.
         self.server.stop_client_connections()
         # Now we wait for the thread running self.server.serve() to finish
         self.server.stopped.wait()
         if last_conn is not None:
             # Close the last connection without trying to use it. The
             # server will not process a single byte on that socket to avoid
             # complications (SSL starts with a handshake for example).
             last_conn.close()
         # Check for any exception that could have occurred in the server
         # thread
         try:
             self._server_thread.join()
         except Exception, e:
             if self.server.ignored_exceptions(e):
                 pass
             else:
                 raise
 def connect(self, addr):
     if self.sock is not None:
         raise AssertionError('Already connected to %r' %
                              (self.sock.getsockname(), ))
     self.sock = osutils.connect_socket(addr)
예제 #3
0
 def connect(self, addr):
     if self.sock is not None:
         raise AssertionError('Already connected to %r'
                              % (self.sock.getsockname(),))
     self.sock = osutils.connect_socket(addr)