/*! */ void BasicClient::runOnline( SoccerAgent * agent ) { if ( ! agent->handleStart() || ! isServerAlive() ) { agent->handleExit(); return; } // set interval timeout struct timeval interval; fd_set read_fds; fd_set read_fds_back; FD_ZERO( &read_fds ); FD_SET( M_socket->fd(), &read_fds ); read_fds_back = read_fds; int timeout_count = 0; long waited_msec = 0; while ( isServerAlive() ) { read_fds = read_fds_back; interval.tv_sec = M_interval_msec / 1000; interval.tv_usec = ( M_interval_msec % 1000 ) * 1000; int ret = ::select( M_socket->fd() + 1, &read_fds, static_cast< fd_set * >( 0 ), static_cast< fd_set * >( 0 ), &interval ); if ( ret < 0 ) { perror( "select" ); break; } else if ( ret == 0 ) { // no meesage. timeout. waited_msec += M_interval_msec; ++timeout_count; agent->handleTimeout( timeout_count, waited_msec ); } else { // received message, reset wait time waited_msec = 0; timeout_count = 0; agent->handleMessage(); } } }
/*! */ void BasicClient::runOffline( SoccerAgent * agent ) { if ( ! agent->handleStartOffline() ) { agent->handleExit(); return; } while ( isServerAlive() ) { agent->handleMessageOffline(); } }
bool BasicClient::runStep( SoccerAgent * agent ) { if (! isServerAlive() ) { agent->handleExit(); return false; } // set interval timeout struct timeval interval; read_fds_ = read_fds_back_; interval.tv_sec = M_interval_msec / 1000; interval.tv_usec = ( M_interval_msec % 1000 ) * 1000; int ret = ::select( M_socket->fd() + 1, &read_fds_, static_cast< fd_set * >( 0 ), static_cast< fd_set * >( 0 ), &interval ); if ( ret < 0 ) { perror( "select" ); exit(1); } else if ( ret == 0 ) { // no meesage. timeout. waited_msec_ += M_interval_msec; ++timeout_count_; return agent->handleTimeoutStep( timeout_count_, waited_msec_ ); } else { // received message, reset wait time waited_msec_ = 0; timeout_count_ = 0; return agent->handleMessageStep(); } }