implement main_loop interface by select