// ---------- Printing things for debugging purposes ---------- static void print_lsda(const lsda_info_t* info) { size_t action_table_min_len_bytes = 0; // Print call site table. printf("Call site table:\n"); const uint8_t* p = info->call_site_table; assert(p); while (p < info->action_table) { // the call site table ends where the action table begins call_site_entry_t entry; p = parse_call_site_entry(p, info, &entry); printf(" start %p end %p landingpad %p action-plus-one %lx\n", entry.instrs_start, entry.instrs_start + entry.instrs_len_bytes, entry.landing_pad, entry.action_offset_plus_one); // Follow the action chain. for (const uint8_t* action_ptr = first_action(info, &entry); action_ptr;) { RELEASE_ASSERT(action_ptr >= info->action_table, "malformed LSDA"); ptrdiff_t offset = action_ptr - info->action_table; // add one to indicate that there is an entry here. (consider the case of an empty table, for example.) // would be nicer to set action_table_min_len_bytes to the end of the entry, but that involves uleb-size // arithmetic. if (offset + 1 > action_table_min_len_bytes) action_table_min_len_bytes = offset + 1; int64_t type_filter; action_ptr = next_action(action_ptr, &type_filter); if (action_ptr) printf(" %ld: filter %ld next %ld\n", offset, type_filter, action_ptr - info->action_table); else printf(" %ld: filter %ld end\n", offset, type_filter); } } // Print the action table. printf("Action table:\n"); RELEASE_ASSERT(p == info->action_table, "malformed LSDA"); while (p < info->action_table + action_table_min_len_bytes) { assert(p); ptrdiff_t offset = p - info->action_table; unsigned num_bytes; int64_t type_filter; const uint8_t* next = next_action(p, &type_filter, &num_bytes); p += num_bytes; if (next) printf(" %ld: filter %ld next %ld\n", offset, type_filter, p - info->action_table); else printf(" %ld: filter %ld end\n", offset, type_filter); } }
void prend(t_env *e, t_clients *player) { char **tab; char msg[4]; char tmp[BUF_SIZE]; tab = ft_strsplit(player->arg[0], ' '); ft_strcpy(msg, "ok\n"); prend2(e, player, msg, tab); sprintf(tmp, "inv %d %d %d %d %d %d %d %d %s\n", player->nb , player->life, player->linemate , player->deraumere, player->sibur, player->mendiane , player->phiras, player->thystame, player->name); sprintf(tmp + strlen(tmp), "inside %d %d %d %d %d %d %d %d %d\n" , player->X, player->Y, e->map[player->Y][player->X].nourriture , e->map[player->Y][player->X].linemate , e->map[player->Y][player->X].deraumere , e->map[player->Y][player->X].sibur , e->map[player->Y][player->X].mendiane , e->map[player->Y][player->X].phiras , e->map[player->Y][player->X].thystame); maj_gfx(e, tmp); next_action(player); ft_strcat(player->buf_write, msg); ft_tabdel(&tab); }
static apr_status_t serf_mock_readline(serf_bucket_t *bucket, int acceptable, int *found, const char **data, apr_size_t *len) { mockbkt_context_t *ctx = bucket->data; mockbkt_action *action; apr_status_t status; const char *start_line; status = next_action(ctx); if (status) { *len = 0; return status; } action = &ctx->actions[ctx->current_action]; start_line = *data = ctx->current_data; *len = ctx->remaining_data; serf_util_readline(&start_line, len, acceptable, found); /* See how much ctx->current moved forward. */ *len = start_line - ctx->current_data; ctx->remaining_data -= *len; ctx->current_data += *len; if (ctx->remaining_data == 0) ctx->remaining_times--; return ctx->remaining_data ? APR_SUCCESS : action->status; }
static apr_status_t serf_mock_read(serf_bucket_t *bucket, apr_size_t requested, const char **data, apr_size_t *len) { mockbkt_context_t *ctx = bucket->data; mockbkt_action *action; apr_status_t status; status = next_action(ctx); if (status) { *len = 0; return status; } action = &ctx->actions[ctx->current_action]; *len = requested < ctx->remaining_data ? requested : ctx->remaining_data; *data = ctx->current_data; ctx->remaining_data -= *len; ctx->current_data += *len; if (ctx->remaining_data == 0) ctx->remaining_times--; return ctx->remaining_data ? APR_SUCCESS : action->status; }
int main() { bool gameover = false; clock_t t1,t2; float diff,seconds; int action; plan = new std::deque<Actions>(); if( connect() ) { //Allocate space to world map wordl_map = (char**) std::malloc(sizeof(char*) * NUM_ROWS); for(int i = 0; i < NUM_ROWS; i++) { wordl_map[i] = (char*) std::malloc(sizeof(char) * NUM_COLS); } //Allocate space for players positions x = (int*) std::malloc(sizeof(int) * NUM_PLAYERS); y = (int*) std::malloc(sizeof(int) * NUM_PLAYERS); r = (int*) std::malloc(sizeof(int) * NUM_PLAYERS); speed = (int*) std::malloc(sizeof(int) * NUM_PLAYERS); alive = (int*) std::malloc(sizeof(int) * NUM_PLAYERS); teams = (int*) std::malloc(sizeof(int) * NUM_PLAYERS); //Game loop while( !gameover ) { gameover = update_Map(); if ( !gameover ) { //Updates players' information gameover = update_Players(); } t1=clock(); // AI agents get next action action = next_action(); t2=clock(); diff = ((float)t2-(float)t1); seconds = diff / CLOCKS_PER_SEC; std::cout << action; /* if ( seconds <= 1 ){ // 5 plays per second usleep((CLOCKS_PER_SEC/speed[PLAYER_ID])-seconds*(CLOCKS_PER_SEC/5)); // Print action to send to server std::cout << action; } else{ // Agent only have 1sec to give the next action std::cout << "TIMEOUT"<<std::endl; }*/ } } return 0; }
auto static_for(TFBody&& body) { auto step = [body = FWD(body)]( auto self, auto state, auto&& x, auto&&... xs) { auto next_state = body(state, x); constexpr auto last_iteration = bool_v<(sizeof...(xs) == 0)>; constexpr auto must_break = bool_v<( // . std::is_same< // . decltype(next_state.next_action()), // . impl::action::a_break // . >{} // . )>; return static_if(bool_v<(must_break || last_iteration)>) .then([next_state](auto&&) { return next_state.accumulator(); }) .else_([next_state, state, &xs...](auto&& xself) { // vvvvv return xself(next_state, xs...); })(self); }; return [step = std::move(step)](auto accumulator) { return [step, accumulator](auto&&... xs) { return static_if(bool_v<(sizeof...(xs) == 0)>) .then([accumulator](auto&&) { return accumulator; }) .else_([accumulator](auto&& xstep, auto&&... ys) { auto initial_state = impl::make_state( // . sz_v<0>, // . accumulator, // . impl::action::a_continue{} // . ); // vvvvvvvvvvvvvvvvvvv return y_combinator(xstep)( // . initial_state, FWD(ys)...); })(step, FWD(xs)...); }; }; }
// Determines whether to dispatch to cleanup code or an exception handler based on the action table. // Doesn't need exception info b/c in Pyston we assume all handlers catch all exceptions. // // Returns the switch value to be passed into the landing pad, which selects which handler gets run in the case of // multiple `catch' blocks, or is 0 to run cleanup code. static inline int64_t determine_action(const lsda_info_t* info, const call_site_entry_t* entry) { // No action means there are destructors/cleanup to run, but no exception handlers. const uint8_t* p = first_action(info, entry); if (!p) return CLEANUP_ACTION; // Read a chain of actions. if (VERBOSITY("cxx_unwind") >= 5) { printf(" reading action chain\n"); } // When we see a cleanup action, we *don't* immediately take it. Rather, we remember that we should clean up if none // of the other actions matched. bool saw_cleanup = false; do { ASSERT(p >= info->action_table, "malformed LSDA"); ptrdiff_t offset = p - info->action_table; int64_t type_filter; p = next_action(p, &type_filter); if (VERBOSITY("cxx_unwind") >= 5) { if (p) printf(" %ld: filter %ld next %ld\n", offset, type_filter, p - info->action_table); else printf(" %ld: filter %ld end\n", offset, type_filter); } if (0 == type_filter) { // A type_filter of 0 indicates a cleanup. saw_cleanup = true; } else { // Otherwise, the type_filter is supposed to be interpreted by looking up information in the types table and // comparing it against the type of the exception thrown. In Pyston, however, every exception handler // handles all exceptions, so we ignore the type information entirely and just run the handler. // // I don't fully understand negative type filters. For now we don't implement them. See // http://www.airs.com/blog/archives/464 for some information. RELEASE_ASSERT(type_filter > 0, "negative type filters unimplemented"); return type_filter; } } while (p); if (saw_cleanup) return CLEANUP_ACTION; // We ran through the whole action chain and none applied, *and* there was no cleanup indicated. What do we do? // This can't happen currently, but I think the answer is probably panic(). RELEASE_ASSERT(0, "action chain exhausted and no cleanup indicated"); }
/* An action { "", 0, APR_EAGAIN } means that serf should exit serf_context_run and pass the buck back to the application. As long as no new data arrives, this action remains active. This function allows the 'application' to trigger the arrival of more data. If the current action is { "", 0, APR_EAGAIN }, reduce the number of times the action should run by one, and proceed with the next action if needed. */ apr_status_t serf_bucket_mock_more_data_arrived(serf_bucket_t *bucket) { mockbkt_context_t *ctx = bucket->data; mockbkt_action *action; apr_status_t status; status = next_action(ctx); if (status) return status; action = &ctx->actions[ctx->current_action]; if (ctx->remaining_data == 0 && action->status == APR_EAGAIN) { ctx->remaining_times--; action->times--; } return APR_SUCCESS; }
bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web) { std::string action( "" ); if ( params.size() >= 1 ) { action = params[ 0 ].asString(); }; std::string next_action( "" ); if ( params.size() >= 2 ) { next_action = params[ 1 ].asString(); }; int result_code = 0; if ( params.size() >= 3 ) { result_code = params[ 2 ].asInteger(); if ( result_code != 0 ) { LL_WARNS("LLBuyCurrency") << "Received nonzero result code: " << result_code << LL_ENDL ; } }; // open the legacy XUI based currency floater if ( "open_legacy" == next_action ) { LLFloaterBuyCurrency::buyCurrency(); }; // ask the Buy Currency floater to close // note: this is the last thing we can do so make // sure any other actions are processed before this. if ( "close" == action ) { LLBuyCurrencyHTML::closeDialog(); }; return true; };
static apr_status_t serf_mock_peek(serf_bucket_t *bucket, const char **data, apr_size_t *len) { mockbkt_context_t *ctx = bucket->data; mockbkt_action *action; apr_status_t status; status = next_action(ctx); if (status) return status; action = &ctx->actions[ctx->current_action]; *len = ctx->remaining_data; *data = ctx->current_data; /* peek only returns an error, APR_EOF or APR_SUCCESS. APR_EAGAIN is returned as APR_SUCCESS. */ if (SERF_BUCKET_READ_ERROR(action->status)) return status; return action->status == APR_EOF ? APR_EOF : APR_SUCCESS; }
/* Verify received requests and take the necessary actions (return a response, kill the connection ...) */ static apr_status_t replay(serv_ctx_t *servctx, apr_int16_t rtnevents, apr_pool_t *pool) { apr_status_t status = APR_SUCCESS; test_server_action_t *action; if (rtnevents & APR_POLLIN) { if (servctx->message_list == NULL) { /* we're not expecting any requests to reach this server! */ serf__log(TEST_VERBOSE, __FILE__, "Received request where none was expected.\n"); return SERF_ERROR_ISSUE_IN_TESTSUITE; } if (servctx->cur_action >= servctx->action_count) { char buf[128]; apr_size_t len = sizeof(buf); status = servctx->read(servctx, buf, &len); if (! APR_STATUS_IS_EAGAIN(status)) { /* we're out of actions! */ serf__log(TEST_VERBOSE, __FILE__, "Received more requests than expected.\n"); return SERF_ERROR_ISSUE_IN_TESTSUITE; } return status; } action = &servctx->action_list[servctx->cur_action]; serf__log(TEST_VERBOSE, __FILE__, "POLLIN while replaying action %d, kind: %d.\n", servctx->cur_action, action->kind); /* Read the remaining data from the client and kill the socket. */ if (action->kind == SERVER_IGNORE_AND_KILL_CONNECTION) { char buf[128]; apr_size_t len = sizeof(buf); status = servctx->read(servctx, buf, &len); if (status == APR_EOF) { serf__log(TEST_VERBOSE, __FILE__, "Killing this connection.\n"); apr_socket_close(servctx->client_sock); servctx->client_sock = NULL; next_action(servctx); return APR_SUCCESS; } return status; } else if (action->kind == SERVER_RECV || (action->kind == SERVER_RESPOND && servctx->outstanding_responses == 0)) { apr_size_t msg_len, len; char buf[128]; test_server_message_t *message; message = &servctx->message_list[servctx->cur_message]; msg_len = strlen(message->text); do { len = msg_len - servctx->message_buf_pos; if (len > sizeof(buf)) len = sizeof(buf); status = servctx->read(servctx, buf, &len); if (SERF_BUCKET_READ_ERROR(status)) return status; if (status == APR_EOF) { serf__log(TEST_VERBOSE, __FILE__, "Server: Client hung up the connection.\n"); break; } if (servctx->options & TEST_SERVER_DUMP) fwrite(buf, len, 1, stdout); if (strncmp(buf, message->text + servctx->message_buf_pos, len) != 0) { /* ## TODO: Better diagnostics. */ printf("Expected: (\n"); fwrite(message->text + servctx->message_buf_pos, len, 1, stdout); printf(")\n"); printf("Actual: (\n"); fwrite(buf, len, 1, stdout); printf(")\n"); return SERF_ERROR_ISSUE_IN_TESTSUITE; } servctx->message_buf_pos += len; if (servctx->message_buf_pos >= msg_len) { next_message(servctx); servctx->message_buf_pos -= msg_len; if (action->kind == SERVER_RESPOND) servctx->outstanding_responses++; if (action->kind == SERVER_RECV) next_action(servctx); break; } } while (!status); } else if (action->kind == PROXY_FORWARD) { apr_size_t len; char buf[BUFSIZE]; serf_bucket_t *tmp; /* Read all incoming data from the client to forward it to the server later. */ do { len = BUFSIZE; status = servctx->read(servctx, buf, &len); if (SERF_BUCKET_READ_ERROR(status)) return status; serf__log(TEST_VERBOSE, __FILE__, "proxy: reading %d bytes %.*s from client with " "status %d.\n", len, len, buf, status); if (status == APR_EOF) { serf__log(TEST_VERBOSE, __FILE__, "Proxy: client hung up the connection. Reset the " "connection to the server.\n"); /* We have to stop forwarding, if a new connection opens the CONNECT request should not be forwarded to the server. */ next_action(servctx); } if (!servctx->servstream) servctx->servstream = serf__bucket_stream_create( servctx->allocator, detect_eof,servctx); if (len) { tmp = serf_bucket_simple_copy_create(buf, len, servctx->allocator); serf_bucket_aggregate_append(servctx->servstream, tmp); } } while (!status); } } if (rtnevents & APR_POLLOUT) { action = &servctx->action_list[servctx->cur_action]; serf__log(TEST_VERBOSE, __FILE__, "POLLOUT when replaying action %d, kind: %d.\n", servctx->cur_action, action->kind); if (action->kind == SERVER_RESPOND && servctx->outstanding_responses) { apr_size_t msg_len; apr_size_t len; msg_len = strlen(action->text); len = msg_len - servctx->action_buf_pos; status = servctx->send(servctx, action->text + servctx->action_buf_pos, &len); if (status != APR_SUCCESS) return status; if (servctx->options & TEST_SERVER_DUMP) fwrite(action->text + servctx->action_buf_pos, len, 1, stdout); servctx->action_buf_pos += len; if (servctx->action_buf_pos >= msg_len) { next_action(servctx); servctx->outstanding_responses--; } } else if (action->kind == SERVER_KILL_CONNECTION || action->kind == SERVER_IGNORE_AND_KILL_CONNECTION) { serf__log(TEST_VERBOSE, __FILE__, "Killing this connection.\n"); apr_socket_close(servctx->client_sock); servctx->client_sock = NULL; next_action(servctx); } else if (action->kind == PROXY_FORWARD) { apr_size_t len; char *buf; if (!servctx->proxy_client_sock) { serf__log(TEST_VERBOSE, __FILE__, "Proxy: setting up connection " "to server.\n"); status = create_client_socket(&servctx->proxy_client_sock, servctx, action->text); if (!servctx->clientstream) servctx->clientstream = serf__bucket_stream_create( servctx->allocator, detect_eof,servctx); } /* Send all data received from the server to the client. */ do { apr_size_t readlen; readlen = BUFSIZE; status = serf_bucket_read(servctx->clientstream, readlen, &buf, &readlen); if (SERF_BUCKET_READ_ERROR(status)) return status; if (!readlen) break; len = readlen; serf__log(TEST_VERBOSE, __FILE__, "proxy: sending %d bytes to client.\n", len); status = servctx->send(servctx, buf, &len); if (status != APR_SUCCESS) { return status; } if (len != readlen) /* abort for now, return buf to aggregate if not everything could be sent. */ return APR_EGENERAL; } while (!status); } } else if (rtnevents & APR_POLLIN) { /* ignore */ } else { printf("Unknown rtnevents: %d\n", rtnevents); abort(); } return status; }
void main_loop(void) { EVENT ev; bool menu_chg; long as_timer = 0, t; /* Message-Handler f�r Fenster-Dialoge und -Alerts */ set_mdial_wincb(handle_msg); update_menu(); menu_chg = FALSE; onblink_edit(); do { quick_close = FALSE; /* Sichern der Texte ohne Nachfrage */ next_action (&ev); /* get_realtop(); */ if (ev.which == MU_TIMER) /* Zeit (nur wenn nichts anderes anliegt) */ { timer_se(); if (blinking_cursor) blink_edit(); if (clip_on_disk) save_clip(); if (as_text || as_prj) { /* * Weil der do_all_icon() recht viel Rechenzeit verheizt, und * AutoSave min. 1 min wartet, wird er nur jede Minute aufgerufen. */ t = Tgettime(); if ((t - as_timer) >= 32) { do_all_icon(ALL_TYPES, DO_AUTOSAVE); as_timer = t; } } } if (ev.which & MU_KEYBD) /* Taste */ { offblink_edit(); handle_keybd(ev.kstate, ev.kreturn); menu_chg = TRUE; onblink_edit(); while (idle()) /* Auch f�r Makro-Play-Abbruch */ ; } if (ev.which & MU_BUTTON) /* Mausknopf */ { offblink_edit(); handle_button(ev.m_x, ev.m_y, ev.bstate, ev.kstate, ev.breturn); menu_chg = TRUE; onblink_edit(); } if (ev.which & MU_MESAG) /* Meldung */ { if (ev.msg[0] == MN_SELECTED) menu_ctrl = (ev.kstate & K_CTRL); offblink_edit(); handle_msg(ev.msg); menu_chg = TRUE; onblink_edit(); } if (ev.which & MU_M1) /* Maus bewegt */ wake_mouse(); if (menu_chg && !is_event()) /* Wenn Zeit */ { update_menu(); /* Eine Aktion kann Men�s ver�ndern */ menu_chg = FALSE; } end_undo_seq(); if (abort_prog) { int msg[] = {0,0,0,0,0,0,0,0}; msg[0] = AP_TERM; msg[1] = gl_apid; appl_write(gl_apid, 16, msg); } } while (! done); }
void stress_subscriber::on_udate(const pubsub::node_name& name, const pubsub::node& /* data */) { // this call back will be called when ever a value has been changed or next_action(); }
void stress_subscriber::start() { next_action(); }
int main() { bool gameover = false; clock_t t1,t2; float diff,seconds; int action; int count = 1; if( connect_RL() ) { Q = (float***) std::malloc(sizeof(float**) * num_actions); for(int i = 0; i < num_actions; i++) { Q[i] = (float**) std::malloc(sizeof(float*) * NUM_ROWS); for(int ir = 0; ir < NUM_ROWS; ir++) { Q [i][ir] = (float*) std::malloc(sizeof(float) * NUM_COLS); } } //Allocate space to world map wordl_map = (char**) std::malloc(sizeof(char*) * NUM_ROWS); eligibility = (float**) std::malloc(sizeof(float*) * NUM_ROWS); parameter_vector = (float**) std::malloc(sizeof(float*) * NUM_ROWS); for(int i = 0; i < NUM_ROWS; i++) { wordl_map[i] = (char*) std::malloc(sizeof(char) * NUM_COLS); eligibility[i] = (float*) std::malloc(sizeof(float) * NUM_COLS); parameter_vector[i] = (float*) std::malloc(sizeof(float) * NUM_COLS); } //Allocate space for players positions x = (int*) std::malloc(sizeof(int) * NUM_PLAYERS); y = (int*) std::malloc(sizeof(int) * NUM_PLAYERS); r = (int*) std::malloc(sizeof(int) * NUM_PLAYERS); speed = (int*) std::malloc(sizeof(int) * NUM_PLAYERS); alive = (int*) std::malloc(sizeof(int) * NUM_PLAYERS); teams = (int*) std::malloc(sizeof(int) * NUM_PLAYERS); counts = (int*) std::malloc(sizeof(int) * num_actions); //Game loop while( !gameover ) { gameover = update_Map(); if ( !gameover ) { //Updates players' information gameover = update_Players(); } t1=clock(); // AI agents get next action action = next_action(); /* Print action to send to server */ std::cout << action; count++; if ( count % 1000 ) { count = 1; save_log(); } } } return 0; }
static apr_status_t replay(test_baton_t *tb, apr_pool_t *pool) { apr_status_t status = APR_SUCCESS; test_server_action_t *action; if (tb->cur_action >= tb->action_count) { char buf[128]; apr_size_t len = sizeof(buf); status = apr_socket_recv(tb->client_sock, buf, &len); if (! APR_STATUS_IS_EAGAIN(status)) { /* we're out of actions! */ printf("Received more requests than expected\n"); return APR_EGENERAL; } return status; } if (tb->action_list == NULL) { /* we're not expecting any requests to reach this server! */ printf("Received request where none was expected\n"); return APR_EGENERAL; } action = &tb->action_list[tb->cur_action]; if (action->kind == SERVER_RECV) { apr_size_t msg_len, len; char buf[128]; msg_len = strlen(action->text); len = msg_len - tb->action_buf_pos; if (len > sizeof(buf)) len = sizeof(buf); status = apr_socket_recv(tb->client_sock, buf, &len); if (status != APR_SUCCESS) return status; if (tb->options & TEST_SERVER_DUMP) fwrite(buf, len, 1, stdout); if (strncmp(buf, action->text + tb->action_buf_pos, len) != 0) { /* ## TODO: Better diagnostics. */ printf("Expected: (\n"); fwrite(action->text + tb->action_buf_pos, len, 1, stdout); printf(")\n"); printf("Actual: (\n"); fwrite(buf, len, 1, stdout); printf(")\n"); return APR_EGENERAL; } tb->action_buf_pos += len; if (tb->action_buf_pos >= msg_len) next_action(tb); } else if (action->kind == SERVER_SEND) { apr_size_t msg_len; apr_size_t len; msg_len = strlen(action->text); len = msg_len - tb->action_buf_pos; status = apr_socket_send(tb->client_sock, action->text + tb->action_buf_pos, &len); if (status != APR_SUCCESS) return status; if (tb->options & TEST_SERVER_DUMP) fwrite(action->text + tb->action_buf_pos, len, 1, stdout); tb->action_buf_pos += len; if (tb->action_buf_pos >= msg_len) next_action(tb); } else if (action->kind == SERVER_KILL_CONNECTION) { apr_socket_close(tb->client_sock); tb->client_sock = NULL; next_action(tb); } else { abort(); } return status; }