示例#1
0
    def finish_request(self, sock, client_address):
        # this method overrides TCPServer implementation and actually handles new connections
        # it may be invoked from different threads, in parallel

        try:
            orig_dst = get_original_dst(sock)
            logger.debug('original destination is %s' % str(orig_dst))
        except Exception as ex:
            logger.debug('get_original_dst() has thrown an exception: %s', ex)

        # create new conn object and obtain client id
        conn = ClientConnection(sock, client_address)
        session_id = conn.get_session_id()

        # find or create a session handler
        with self.lock:
            if not self.client_server_sessions.has_key(session_id):
                logger.debug('new session [id %s]', session_id)
                profiles = self.mk_session_profiles()
                handler = ClientServerSessionHandler(session_id, profiles,
                                                     self.post_test_action,
                                                     self.res_queue,
                                                     self.file_bag)
                self.client_server_sessions[session_id] = handler
            else:
                handler = self.client_server_sessions[session_id]

        # handle the request
        handler.handle(conn)