int main(int argc, char* argv[]) { //WSAData wsaData; //WSAStartup(MAKEWORD(2, 2), &wsaData); ASockIOInit(); MsgLoop_Init(); Async_Init(); if(OptGetValue(argc-1, &argv[1], "play", NULL)) { bReplayMode = true; pLoop = MsgLoop_Create(); pLoop->Playback(CSGGameLoopCallback::GetSingleton(), OptGetValue(argc-1, &argv[1], "play", NULL)); } else { pLoop = MsgLoop_Create(); pLoop->Start(CSGGameLoopCallback::GetSingleton(), 1000, OptGetValue(argc-1, &argv[1], "record", NULL)); InitTCPServer(1980); getchar(); FinalTCPServer(); pLoop->Stop(); pLoop->Wait(); CSGGameLoopCallback::Cleanup(); } Async_Final(); MsgLoop_Final(); ASockIOFini(); //WSACleanup(); return 0; }
TEST_F(SSFFixtureTest, CloseWhileConnecting) { // Init server int server_port = 15000; boost::asio::ip::tcp::acceptor server(get_io_service()); InitTCPServer(server, server_port); // Init timer (if client hangs) boost::system::error_code timer_ec; auto timer_callback = [this](const boost::system::error_code& ec) { EXPECT_NE(0, ec.value()) << "Timer should be canceled. Client is hanging"; if (!ec) { SendNotification(false); } }; StartTimer(std::chrono::seconds(20), timer_callback, timer_ec); ASSERT_EQ(0, timer_ec.value()) << "Could not start timer"; // Init client auto client_callback = [this](ssf::Status status) { switch (status) { case ssf::Status::kEndpointNotResolvable: case ssf::Status::kServerUnreachable: SSF_LOG("test", critical, "Network initialization failed"); SendNotification(true); break; case ssf::Status::kServerNotSupported: SSF_LOG("test", critical, "Transport initialization failed"); SendNotification(true); break; case ssf::Status::kConnected: SendNotification(true); break; case ssf::Status::kDisconnected: SSF_LOG("test", info, "client: disconnected"); break; case ssf::Status::kRunning: SendNotification(false); break; default: break; } }; boost::system::error_code run_ec; StartClient(std::to_string(server_port), client_callback, run_ec); ASSERT_EQ(0, run_ec.value()); // Wait new server connection boost::asio::ip::tcp::socket socket(get_io_service()); server.async_accept(socket, [this](const boost::system::error_code& ec) { EXPECT_EQ(0, ec.value()) << "Accept connection in error"; // Stop client while connecting StopClient(); }); // Wait client action WaitNotification(); EXPECT_TRUE(IsNotificationSuccess()) << "Stop failed"; StopTimer(); boost::system::error_code close_ec; socket.close(close_ec); server.close(close_ec); }
int main() { if(read_config_files(&cf)== -1) { printf("\nError in reading config files"); exit(0); } //---declare variable of program----// int listen_sd, accept_sd; struct sockaddr_in addr; int i; //--------------load action record from file-----------------------// int numberofac; char *filename = cf.action_record; ActionRecord *ac; ac = ReadOutputFile(filename,&numberofac); if(ac == NULL) { printf("\nCannot read action record file"); return 0; } //sort the array with the action's starting time SortActionArray(ac,numberofac); printf("\nnumber of action record:%d",numberofac); //-------------load action mapping file------------------------// char *action_mapping_file = cf.action_mapping; action_mapping *ap ; int numberofap =0; ap = read_action_mapping_file(action_mapping_file,&numberofap); if(ap == NULL) { printf("\nCannot read action mapping file"); return 0; } action_mapping *temp; temp = ap; while(temp!=NULL) { print_action_mapping(temp); temp=temp->next; } //-------------------------------load setting file ---------------// char *setting_file = cf.setting_file; id_ip *ID_IP; int numberofnode; ID_IP = read_setting_file(setting_file,&numberofnode); if(ID_IP == NULL) { printf("\nCannot read setting file"); return 0; } printf("\nnumber of node in setting file:%d\n",numberofnode); //------------INIT main process to control child processes----------------// main_process_init(); //--------------INIT server for listening the time value from QOMET-------// /* If an argument was specified, use it to */ /* control the number of incoming connections */ listen_sd = InitTCPServer(SERVER_PORT); if(listen_sd < 1) { fprintf(stderr,"Server cannot init"); return 0; } //--------------------------main loop----------------------// do_actions(listen_sd,ac,numberofac,ap,ID_IP); //------------------------close program--------------------// /* Close the listen socket */ close(listen_sd); //kill all child processes// kill_all_processes(main_p->pgid); //wait for close main process// wait_to_close(); return 0; //--------------close program in bad cases-----------------------// bad_main: printf("\nclose do action program\n"); close(listen_sd); close(accept_sd); kill_all_processes(main_p->pgid); exit(-1); }