class SSLSocketEngineTest(object):
    
    th = None
    running = False
    engine = None

    server_addr = None
    server_sock = None

    def __init__(self, logger):
        self.engine = SSLSocketEngine(iopoll.Poll(), SSL_CERT, is_blocking=False)
        self.engine.set_logger(logger)
        self.engine.set_timeout(5, 5)

    def start_client(self):
        assert not self.running
        self.running = True
        def _run(self):
            print "client started"
            while self.running:
                try:
                    l = self.engine.poll(1)
                except Exception, e:
                    traceback.print_exc()
                    os._exit(1)
            return
        self.th = threading.Thread(target=_run, args=(self, ))
        self.th.setDaemon(1)
        self.th.start()
Esempio n. 2
0
class SSLSocketEngineTest(object):

    th = None
    running = False
    engine = None

    server_addr = None
    server_sock = None

    def __init__(self, logger):
        self.engine = SSLSocketEngine(iopoll.Poll(),
                                      SSL_CERT,
                                      is_blocking=False)
        self.engine.set_logger(logger)
        self.engine.set_timeout(5, 5)

    def start_client(self):
        assert not self.running
        self.running = True

        def _run(self):
            print "client started"
            while self.running:
                try:
                    l = self.engine.poll(1)
                except Exception, e:
                    traceback.print_exc()
                    os._exit(1)
            return

        self.th = threading.Thread(target=_run, args=(self, ))
        self.th.setDaemon(1)
        self.th.start()
def test_client_unblock():
    poll = None
    if 'EPoll' in dir(iopoll):
        poll = iopoll.EPoll(True)
        print "client using epoll et mode"
    else:
        poll = iopoll.Poll()
    engine = SSLSocketEngine(poll, SSL_CERT, debug=True)
#    engine.get_time = tc.time
    engine.set_logger(getLogger("client"))
    start_time = time.time()
    def __on_conn_err(e, client_id):
        print "client", client_id, "connect error", str(e)
        os._exit(1)
        return
    def __on_err(conn, client_id, count):
        print client_id, count, type(conn.error), conn.error
        raise conn.error
        return
    def __on_recv(conn, client_id, count):
#        print count
        global g_done_client
        if count >= 0:
            buf = conn.get_readbuf()
            if buf != data:
                print "data recv invalid, client:", client, "data:", buf
                os._exit(0)
        if count < round:
            print "send", client_id, count + 1, time.time()
            engine.write_unblock(conn, data, __on_send, __on_err, (client_id, count + 1))
        else:
            engine.close_conn(conn)
            g_done_client += 1
            print "client", client_id, "done", time.time()
            if g_done_client == g_client_num:
                print "test client done time: ", time.time() - start_time
        return
    def __on_send( conn, client_id, count):
        engine.read_unblock(conn, len(data), __on_recv, __on_err, (client_id, count))
        return
    def __on_conn(sock, client_id):
        print "ssl conn", client_id, time.time()
        __on_recv(Connection(sock), client_id, -1)
        return
    def _run(engine):
        global g_done_client
        while g_done_client < g_client_num:
            try:
                engine.poll(1)
            except Exception, e:
                traceback.print_exc()
                os._exit(1)
        print g_done_client
        return
 def __init__(self, logger):
     self.engine = SSLSocketEngine(iopoll.Poll(), SSL_CERT, is_blocking=False)
     self.engine.set_logger(logger)
     self.engine.set_timeout(5, 5)
Esempio n. 5
0
 def __init__(self, logger):
     self.engine = SSLSocketEngine(iopoll.Poll(),
                                   SSL_CERT,
                                   is_blocking=False)
     self.engine.set_logger(logger)
     self.engine.set_timeout(5, 5)