Exemplo n.º 1
0
static void *probing(void *arg) //master probe the time_sheet in every 5 seconds
{
    Pthread_detach(pthread_self());
    while (1)
    {
        sleep(5);
        printf("start probing\n");
        time_t cur_time = time(NULL);
        for(map<pair<int, int>, time_t >::iterator it = ms.Gettimesheet().begin(); it != ms.Gettimesheet().end(); ++it)
        {
            if (cur_time - (it->second) > 5) //if certain server's last ping from now is more than 5 seconds, it means the server fails, start notify client and server the failure
            {
                printf("%s\n",seperator);
                printf("Server 127.0.0.1:%d FAILS\n",it->first.second);
                ms.client_notify(it->first, false);
                ms.server_notify(it->first, false);
                it = ms.Gettimesheet().erase(it);
                if (it == ms.Gettimesheet().end())
                    break;
            }
        }
    }
}