コード例 #1
0
class CoroSocketEngineTest(object):
    
    th = None
    running = False
    engine = None

    server_addr = None
    server_sock = None

    def __init__(self, logger):
        self.engine = CoroSocketEngine(iopoll.EPoll(), is_blocking=False, debug=True)
        self.engine.set_logger(logger)
        self.engine.set_timeout(5, 5)

    # NOTE: you can only be client/server at one time
    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()
コード例 #2
0
                print "time:", time.time() - start_time
                global_lock.release()
                os._exit(0)
            global_lock.release()
        except socket.error, e:
            engine.logger.exception(e)
            print e
            os._exit(1)
        return

    engine = CoroSocketEngine(io_poll.get_poll())
    engine.set_logger(getLogger("client"))
    for i in xrange(g_client_num):
        engine.run_coro(client(engine, i, server_addr, g_round))
    while True:
        engine.poll()


def main():
    Log("client", config=conf)
    Log("server", config=conf)
    server = start_echo_server()
    time.sleep(1)
    test_client()

if __name__ == '__main__':
    main()



# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 :