void update_ui_comms (void) { static int update_ticks = 0; if (update_ticks < get_system_time ()) { data_exchange (); update_ticks = get_system_time () + (ONE_SECOND / command_line_max_game_update_rate); set_delta_time (); } }
int process_http_proxy( int sockfd_new ) { while(1) { fd_set readfd; FD_ZERO(&readfd); FD_SET(sockfd_new, &readfd); struct timeval tv; tv.tv_sec = TIME_OUT_DEFAULT; tv.tv_usec = 0; if( select(sockfd_new+1, &readfd, NULL, NULL, &tv) < 0 ) { if( EINTR == errno ) { continue; } SERVER_DEBUG( "select error:%s\n", strerror(errno) ); return -1; } else if( FD_ISSET(sockfd_new, &readfd) ) { char buffer[SO_BUF_LEN_MAX]; SERVER_DEBUG( "receive downstream message:\n" ); ssize_t length = 0; if( ( length = read_wrapper(sockfd_new, buffer, sizeof(buffer)) ) < 0 ) { SERVER_DEBUG( "read error:%s\n", strerror(errno) ); return -1; } SERVER_DEBUG( "read size = %d \n", length ); if( length > 0 ) { //to do buffer[length] = '\0'; //parse http_data char host_ip[HOST_IP_LEN_MAX] = {0}; if( parse_http_data( buffer, length, host_ip, sizeof(host_ip) ) < 0 ) { SERVER_DEBUG( "parse_http_data error\n" ); return -1; } else { int sockfd = 0; if( ( sockfd = initial_socket() ) < 0 ) { SERVER_DEBUG( "initial_socket error\n" ); return -1; } struct sockaddr_in client_addr; memset( &client_addr, 0, sizeof(client_addr) ); client_addr.sin_family = AF_INET; client_addr.sin_port = htons(HOST_PORT_DEFAULT); inet_pton( AF_INET, host_ip, &client_addr.sin_addr ); if( connect( sockfd, (struct sockaddr*)&client_addr, sizeof(client_addr) ) < 0 ) { SERVER_DEBUG( "client connect %s:%d error:%s\n", host_ip, HOST_PORT_DEFAULT, strerror(errno) ); close( sockfd ); return -1; } else { SERVER_DEBUG( "connect successfully %s:%d \n", host_ip, HOST_PORT_DEFAULT ); if( setsockopt_nonblock(sockfd) < 0 ) { SERVER_DEBUG( "setsockopt_nonblock error\n" ); close( sockfd ); return -1; } SERVER_DEBUG( "send message to upsteam:\n" ); if( ( length = write_wrapper( sockfd, buffer, length ) ) == -1 ) { SERVER_DEBUG( "write error:%s\n", strerror(errno) ); close( sockfd ); return -1; } SERVER_DEBUG( "write size = %d\n", length ); while(1) { FD_ZERO(&readfd); FD_SET(sockfd_new, &readfd); FD_SET(sockfd ,&readfd); tv.tv_sec = TIME_OUT_DEFAULT; tv.tv_usec = 0; if( select(sockfd+1, &readfd, NULL, NULL, &tv) < 0 ) { if( EINTR == errno ) { continue; } SERVER_DEBUG( "select error:%s\n", strerror(errno) ); return -1; } else if( FD_ISSET(sockfd, &readfd) ) { SERVER_DEBUG( "receive upstream message:\n" ); if( data_exchange( sockfd_new, sockfd, buffer, sizeof(buffer) ) < 0) { SERVER_DEBUG( "data_exchange error\n" ); close( sockfd ); return -1; } } else if( FD_ISSET(sockfd_new, &readfd) ) { SERVER_DEBUG( "receive downstream message:\n" ); if( data_exchange( sockfd, sockfd_new, buffer, sizeof(buffer) ) < 0) { SERVER_DEBUG( "data_exchange error\n" ); close( sockfd ); return -1; } } else { SERVER_DEBUG( "receive upstream message timeout\n" ); continue; } //select timeout } //while(1) } //connect } //parse_http_data } else { //read_wrapper <= 0 SERVER_DEBUG( "receive downstream message error, client socket closed\n" ); return -1; } } else { //select timeout SERVER_DEBUG( "receive downstream message timeout\n" ); } } kill( parent, SIGCHLD ); return 0; }
void test () { int n_proc; #ifdef HAVE_MPI MPI_Comm_size(MPI_COMM_WORLD, &n_proc); #else n_proc = 1; #endif int my_id; #ifdef HAVE_MPI MPI_Comm_rank(MPI_COMM_WORLD, &my_id); #else my_id = 0; #endif //All processes should own 10 entries const int entries_per_process = 10; const long long begin_index = ((long long)my_id)*entries_per_process; const long long end_index = ((long long)(my_id+1))*entries_per_process; const long long local_begin = std::max(0LL, begin_index-entries_per_process/2); const long long local_end = entries_per_process*n_proc; //create Epetra maps std::vector<unsigned long long> ghosted_indices; ghosted_indices.reserve(local_end-local_begin); for (long long i = local_begin; i< local_end; ++i) ghosted_indices.push_back(i); Epetra_Map map_ghosted (-1LL, local_end-local_begin, reinterpret_cast<long long*>(&ghosted_indices[0]), 0, #ifdef HAVE_MPI Epetra_MpiComm(MPI_COMM_WORLD)); #else Epetra_SerialComm()); #endif std::vector<unsigned long long> distributed_indices; distributed_indices.reserve(entries_per_process*n_proc); for (long long i = begin_index; i< end_index; ++i) distributed_indices.push_back(i); Epetra_Map map_distributed (entries_per_process*n_proc, entries_per_process, reinterpret_cast<long long*>(&distributed_indices[0]), 0, #ifdef HAVE_MPI Epetra_MpiComm(MPI_COMM_WORLD)); #else Epetra_SerialComm()); #endif Epetra_FEVector v_ghosted(map_ghosted); Epetra_FEVector v_distributed(map_distributed); v_distributed.PutScalar(2.); v_ghosted.PutScalar(1.); Epetra_Import data_exchange (v_distributed.Map(), v_ghosted.Map()); int ierr = v_distributed.Import(v_ghosted, data_exchange, Epetra_AddLocalAlso); std::cout << "Distributed:" << std::endl; for (long long i=begin_index; i<end_index; ++i) { int trilinos_i = v_distributed.Map().LID(i); double value = v_distributed[0][trilinos_i]; std::cout<<"proc "<<my_id<<" "<< i << ": " << value << std::endl; if(value != 3) std::cerr << "tests FAILED: value = " << value << std::endl; } }