int main(int argc,char *argv[]) { srand(time(NULL)); int gen_no,tra_no; vote_t *votes=parse_input(&gen_no,&tra_no); int loy_no=gen_no-tra_no; print_input(gen_no,loy_no,tra_no,votes); mb_t *mbs=create_mailboxes(gen_no+1); mbi_t *mbis=mailbox_addresses(mbs,gen_no+1); mbo_t mbo=mbs[0].mbo; role_t *roles=init_roles(gen_no,tra_no); gen_t *gens=create_generals(roles,mbs,mbis,gen_no,tra_no,votes); sig_t sig=getpid(); int rounds=max_traitors(gen_no)+1; for(int round=1;round<=rounds;round++) { sync_phase_wait(mbo,gen_no); print_round(round,rounds); print_phase(1,3); sync_phase_signal(mbis,sig,gen_no); sync_phase_wait(mbo,gen_no); print_phase(2,3); sync_phase_signal(mbis,sig,gen_no); sync_phase_wait(mbo,gen_no); print_phase(3,3); sync_phase_signal(mbis,sig,gen_no); } votes=get_final_votes(mbo,loy_no); print_output(loy_no,votes); free(votes); destroy_mailboxes(mbs,gen_no+1); free(mbs); free(mbis); free(gens); free(roles); return 0; }
void ibmasm_handle_mouse_interrupt(struct service_processor *sp) { unsigned long reader; unsigned long writer; struct remote_input input; reader = get_queue_reader(sp); writer = get_queue_writer(sp); while (reader != writer) { memcpy_fromio(&input, get_queue_entry(sp, reader), sizeof(struct remote_input)); print_input(&input); if (input.type == INPUT_TYPE_MOUSE) { send_mouse_event(sp->remote.mouse_dev, &input); } else if (input.type == INPUT_TYPE_KEYBOARD) { send_keyboard_event(sp->remote.keybd_dev, &input); } else break; reader = advance_queue_reader(sp, reader); writer = get_queue_writer(sp); } }
/** **************************************************************************************** * @brief print menu function * **************************************************************************************** */ void print_menu(void) { printf_string("\n\r====================================\n\r"); printf_string("= DA14580 Peripheral Examples Menu =\n\r"); printf_string("\n\r====================================\n\r"); printf_string("u. UART Print String Example\n\r"); #ifdef SPI_ENABLED printf_string("f. SPI Flash Memory Example\n\r"); #else printf_string("f. (disabled in this build) SPI Flash Memory Example\n\r"); #endif //SPI_ENABLED #ifdef EEPROM_ENABLED printf_string("e. I2C EEPROM Example\n\r"); #else printf_string("e. (disabled in this build) I2C EEPROM Example\n\r"); #endif //EEPROM_ENABLED #ifdef QUADEC_ENABLED printf_string("q. Quadrature Encoder Example\n\r"); #else printf_string("q. (disabled in this build) Quadrature (Rotary Encoder) Example\n\r"); #endif //QUADEC_ENABLED #ifdef BUZZER_ENABLED printf_string("t. Timer0 (PWM0, PWM1) Example\n\r"); printf_string("p. Timer2 (PWM2, PWM3, PWM4) Example\n\r"); #else printf_string("t. (disabled in this build) Timer0 (PWM0, PWM1) Example\n\r"); printf_string("p. (disabled in this build) Timer2 (PWM2, PWM3, PWM4) Example\n\r"); #endif //BUZZER_ENABLED printf_string("b. Battery Example\n\r"); printf_string("x. Exit\n\r\n\r"); print_input(); }
/** @brief Prints all the needed outputs */ void print_output() { optimize(0); print_input(); print_c_matix(); print_best_combination(); }
void solve_problem() { int i, j; scanf("%d %d", &R,&C); for(i =1; i<=R; i++) { for(j =1; j<=C; j++) { scanf("%s", input[i][j].str); integer[i][j] =0; string[i][j] ='A'; visited[i][j] = 0; visited_temple[i][j] = 0; find_int_char(i, j, input[i][j].str); } } front = 0; rear = -1; Answer =0; fill_lava(triger_r, triger_c, 1); // printf("start_r = %d start_c = %d\n", start_r, start_c); temple_run(start_r, start_c, 1, integer[start_r][start_c]); #if 0 print_string(); printf("***************************\n"); print_int(); printf("***************************\n"); print_input(); printf("***************************\n"); #endif }
int main(int argc, char *argv[]) { PetscErrorCode ierr; params params; Mat H; SlepcInitialize(&argc,&argv,(char*)0,help); ierr = PetscPrintf(PETSC_COMM_WORLD,"--------------------------------------------------------------------------------------\n");CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD," _______ __ __ _______ _______ ______ _______ \n");CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD," |__ __| \\/ |/ ____\\ \\ / /_ _| ____|__ __| \n");CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD," | | | \\ / | (___ \\ \\ /\\ / / | | | |__ | | \n");CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD," | | | |\\/| |\\___ \\ \\ \\/ \\/ / | | | __| | | \n");CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD," | | | | | |____) | \\ /\\ / _| |_| | | | \n");CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD," |_| |_| |_|_____/ \\/ \\/ |_____|_| |_| \n");CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD," True Muonium Solver with Iterative Front-Form Techniques \n");CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD," \n");CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"--------------------------------------------------------------------------------------\n");CHKERRQ(ierr); read_input(ierr,argv,¶ms); print_input(ierr,¶ms); if(check_file(params.hfile)) { PetscViewer viewer_H; PetscViewerBinaryOpen(PETSC_COMM_WORLD,params.hfile.c_str(),FILE_MODE_READ,&viewer_H); MatCreate(PETSC_COMM_WORLD,&H); MatSetFromOptions(H); MatLoad(H,viewer_H); PetscViewerDestroy(&viewer_H); }else { discretize(ierr,¶ms); // ierr = VecView(params.mu,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); // ierr = VecView(params.theta,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); write_output(ierr,¶ms); coulomb_trick(ierr,¶ms); // ierr = VecView(params.CT,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ct_discrete(ierr,¶ms); // ierr = VecView(params.CT,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); hamiltonian(ierr,¶ms,H); // ierr = PetscViewerSetFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_DENSE);//DENSE<-->COMMON // MatView(H,PETSC_VIEWER_STDOUT_WORLD); } cleanup(ierr,¶ms); eigensolver(ierr,¶ms,H,argc,argv); ierr = MatDestroy(&H);CHKERRQ(ierr); ierr = SlepcFinalize(); return 0; }
/** * Generally, prints current value, and possible range of values for each * control then provides option to change the current value of controls. */ int main() { fd = open("/dev/video0", O_RDWR); if(fd < 0){ perror("/dev/video0"); exit (EXIT_FAILURE); } print_input(); read_controls(); disable_autos(); change_input(); print_input(); while(1){ read_controls(); change_controls(); } return 0; }
/** **************************************************************************************** * @brief Main routineof the DA14580 Peripheral Examples Functions * DA14580 Peripherals Udage Examples * - UART * - SPI Flash * - Boot From SPI flash * - EEPROM * - Timers * - Battery Level Indication - ADC * - Quadrature * - Buzzer * Due to HW Development Kit limitations, user must select one of the follwoing configuartion for UART, SPI, I2C. * Addicional Hardware (SPI, EEPROM boadrs) or Hardware modification may needed for some tof the tests. * More information in the file periph_setup.h, Application Notes, and User Guide for DA14580 * - UART only ( No HW modifications on rev C2 motherboard, No additional hardware) * - SPI Flash with UART (HW modifications & additional Hardware needed , SPI_DI_PIN on the additional SPI / EEPROM daughterboard ) * - Boot From SPI Flash with UART (HW modifications & additional Hardware needed, (UART TX) ) * - Boot From SPI Flash without UART (Additional Hardware needed) * - Boot From EEPROM with UART (Additional Hardware needed) * **************************************************************************************** */ int main (void) { short int index = 0; char mchoice; periph_init(); printf_string("\n\rDA14580 Peripheral Examples\n\r"); printf_string( "---------------------------\n\r"); printf_string("Before running the tests:\n\r"); printf_string(" 1) Make sure you have connected the appropriate peripheral(s).\n\r"); printf_string(" 2) Select the associated hardware configuration in 'periph_setup.h'.\n\r"); printf_string(" 3) Build.\n\r"); printf_string("Please, refer to DA14580 Peripheral Examples User Manual\n\r"); printf_string("for detailed instructions.\n\r"); print_menu(); while(1){ if (index==1) break; mchoice = uart_receive_byte(); switch (mchoice){ case 'u': uart_test(); endtest_bridge(&index); break; #ifdef SPI_ENABLED case 'f': spi_test(); endtest_bridge(&index); break; #endif //SPI_ENABLED #ifdef EEPROM_ENABLED case 'e': i2c_test(); endtest_bridge(&index); break; #endif //EEPROM_ENABLED #ifdef QUADEC_ENABLED case 'q': quad_decoder_test(); endtest_bridge(&index); break; #endif //QUADEC_ENABLED #ifdef BUZZER_ENABLED case 't': timer0_test(); endtest_bridge(&index); break; case 'p': timer2_test(); endtest_bridge(&index); break; #endif //BUZZER_ENABLED case 'b': batt_test(); endtest_bridge(&index); break; case 'x': index=1;break; default: print_input(); continue; }; }; printf_string("\n\r End of tests\n\r"); while(1); }
/** **************************************************************************************** * @brief print menu function * **************************************************************************************** */ void print_menu(void) { printf_string("\n\r=====================================\n\r"); printf_string("= DA14580 Engineering Examples Menu =\n\r"); printf_string("\n\r=====================================\n\r"); printf_string("u. UART Print String Example\n\r"); printf_string("f. SPI Flash Memory Example\n\r"); printf_string("i. SPI Flash Memory Image Write\n\r"); printf_string("e. I2C EEPROM Example\n\r"); printf_string("d. I2C EEPROM Image Write/Verify Example\n\r"); #ifdef QUADEC_ENABLED printf_string("q. Quadrature (Rotary Encoder) Example\n\r"); #else printf_string("q. (disabled in this build) Quadrature (Rotary Encoder) Example\n\r"); #endif //QUADEC_ENABLED printf_string("t. Timer0 (PWM0, PWM1) Example\n\r"); printf_string("p. Timer2 (PWM2, PWM3, PWM4) Example\n\r"); printf_string("b. Battery Example\n\r"); printf_string("x. Exit Example\n\r\n\r"); print_input(); }
/** **************************************************************************************** * @brief Main routineof the DA14580 Engineering Examples Functions * DA14580 Peripherals Udage Examples * - UART * - SPI Flash * - Boot From SPI flash * - EEPROM * - Timers * - Battery Level Indication - ADC * - Quadrature * - Buzzer * Due to HW Development Kit limitations, user must select one of the follwoing configuartion for UART, SPI, I2C. * Addicional Hardware (SPI, EEPROM boadrs) or Hardware modification may needed for some tof the tests. * More information in the file periph_setup.h, Application Notes, and User Guide for DA14580 * - UART only ( No HW modifications on rev C2 motherboard, No additional hardware) * - SPI Flash with UART (HW modifications & additional Hardware needed , SPI_DI_PIN on the additional SPI / EEPROM daughterboard ) * - Boot From SPI Flash with UART (HW modifications & additional Hardware needed, (UART TX) ) * - Boot From SPI Flash without UART (Additional Hardware needed) * - Boot From EEPROM with UART (Additional Hardware needed) * **************************************************************************************** */ int main (void) { short int index = 0; char mchoice; periph_init(); printf_string("DA14580 Engineering Examples\n\r"); printf_string("Connect the appropriate peripheral before choosing each test\n\r\n\r"); printf_string("Refer to Engineering Examples User Guide\n\r\n\r"); print_menu(); while(1){ if (index==1) break; mchoice = uart_receive_byte(); switch (mchoice){ case 'u': uart_test(); endtest_bridge(&index); break; case 'f': spi_test(); endtest_bridge(&index); break; case 'i': spi_image(); endtest_bridge(&index); break; case 'e': i2c_test(); endtest_bridge(&index); break; case 'd': i2c_image(); endtest_bridge(&index); break; // case 't': swt_test(); endtest_bridge(&index); break; #ifdef QUADEC_ENABLED case 'q': quad_decoder_test(); endtest_bridge(&index); break; #endif //QUADEC_ENABLED case 't': timer0_test(); endtest_bridge(&index); break; case 'p': timer2_test(); endtest_bridge(&index); break; case 'b': batt_test(); endtest_bridge(&index); break; case 'x': index=1;break; default: print_input(); continue; }; }; printf_string("\n\r End of tests\n\r"); while(1); }
static int command_read_line(char buf[]) { char input_c; int cur_pos = 0; int cur_max = 0; int hst_pos = g_cmd_stack.hist; int esc_sequence = 0; int spec_key = 0; int ret; memset(buf, 0, MAX_ARG_LEN); while (0 == cur_max) { input_c = 0; printf("\033[4h"); show_prompt(); printf("\033[4h"); while (input_c != '\r' && input_c != '\n') { input_c = shell_getchar(); //fixme: support F1 F2 F3 ... if (input_c == '\033') { spec_key = 1; input_c = shell_getchar(); if (input_c == '[') { esc_sequence = 1; input_c = shell_getchar(); } } else { spec_key = 0; esc_sequence = 0; } switch (input_c) { case '\t': #if 0 pre_space_count = get_pre_space_count(buf); for (exe = g_exe_begin; exe < g_exe_end; exe++) { if (!cur_pos || strncmp(exe->name, buf + pre_space_count, strlen(exe->name)) == 0) { if (exe->usr_cmd_match && (cmd_line_status(buf, &cur_pos) == IS_CMD_MATCH)) { if (match_count != 1) { match_count = exe->usr_cmd_match(buf, &cur_pos, &cur_max); cmd_last_pos = cur_pos; } if (cur_pos != cmd_last_pos) match_count = exe->usr_cmd_match(buf, &cur_pos, &cur_max); } break; } } #endif if (IS_CMD_MATCH == cmd_line_status(buf, &cur_pos)) cmd_match(buf, &cur_pos, &cur_max); break; case '\r': case '\n': putchar('\n'); break; case 0x03: // ctrl + c cur_pos = 0; cur_max = 0; input_c = '\n'; putchar(input_c); break; case 0x08: case 0x7f: if (cur_pos > 0) backspace_one_key(buf, &cur_pos, &cur_max); break; case 'A': case 'B':// no filter: escape +' [' + 'A' if (1 == esc_sequence) { if ('A' == input_c) ret = cmd_up_key(buf, &cur_pos, &hst_pos, &cur_max); else ret = cmd_down_key(buf, &cur_pos, &hst_pos, &cur_max); if (ret < 0) // fixme: do something ; } else // not a up/down key, treat it as a normal input print_input(input_c, buf, &cur_pos, &cur_max); break; case 'C': case 'D': if (1 == esc_sequence) { if ('C' == input_c) ret = cmd_right_key(buf, &cur_pos, &cur_max); else ret = cmd_left_key(buf, &cur_pos, &cur_max); break; } else // not a left/right key, treat it as a normal input print_input(input_c, buf, &cur_pos, &cur_max); break; case 'O': if (1 == spec_key) { input_c = shell_getchar(); if ('H' == input_c) { if (cur_pos != 0) printf("\033[%dD", cur_pos); cur_pos = 0; } if ('F' == input_c) { if (cur_pos != cur_max) printf("\033[%dC", cur_max - cur_pos); cur_pos = cur_max; } } else // not a Home/End key, treat it as a normal input print_input(input_c, buf, &cur_pos, &cur_max); break; case '3': if (1 == spec_key) { input_c = shell_getchar(); if ('~' == input_c) delete_one_key(buf, &cur_pos, &cur_max); } else print_input(input_c, buf, &cur_pos, &cur_max); break; default: if (input_c >= 0x20 && input_c <= 0x7f) //filter the character print_input(input_c, buf, &cur_pos, &cur_max); break; } } } buf[cur_max] = '\0'; cmd_update_history(buf); printf("\033[4h"); printf("\033[4l"); return 0; }
int main(int argc, char *argv[]) { /* Packet Thread */ /* Initialize the mutex */ pthread_mutex_init(&m, 0); int i; char *lambda = "0.5"; char *mu = "0.35"; char *r = "1.5"; char *B = "10"; char *P = "3"; char *n = "20"; char *FILENAME = NULL; AVAILABLE = 0; DROPPED = 0; DROPPED_PKT = 0; TOTAL = 0; TOTAL_SERVED = 0; SERVER_DIE = 0; /* Read Options */ for(i=1;i<argc;i=i+2){ if (i%2!=0 && argv[i][0]=='-'){ if ((strcmp(argv[i]+1, "lambda") == 0) && ((i+1)<argc)){ lambda = argv[i+1]; if(check_num(lambda)== -1){ fprintf(stderr, "Value of lambda is not a number.\n"); exit(0); } continue; } else if ((strcmp(argv[i]+1, "mu") == 0) && ((i+1)<argc)){ mu = argv[i+1]; if(check_num(mu)== -1){ fprintf(stderr, "Value of mu is not a number.\n"); exit(0); } continue; } else if ((strcmp(argv[i]+1, "r") == 0) && ((i+1)<argc)){ r = argv[i+1]; if(check_num(r)== -1){ fprintf(stderr, "Value of r is not a number.\n"); exit(0); } continue; } else if ((strcmp(argv[i]+1, "B") == 0) && ((i+1)<argc)){ B = argv[i+1]; if(isNum(B)==-1){ fprintf(stderr, "Value of B is not a number.\n"); exit(0); } continue; } else if((strcmp(argv[i]+1, "P") == 0) && ((i+1)<argc)){ P = argv[i+1]; if(isNum(P) == -1){ fprintf(stderr, "Value of P is not a number.\n"); exit(0); } continue; } else if ((strcmp(argv[i]+1, "n") == 0) && ((i+1)<argc)){ n = argv[i+1]; if(isNum(n)==-1){ fprintf(stderr, "Value of n is not a number.\n"); exit(0); } continue; } else if ((strcmp(argv[i]+1, "t") == 0) && ((i+1)<argc)){ FILENAME = argv[i+1]; continue; } } fprintf(stderr, "Wrong command line argument\n"); exit(0); break; } /*Allocate memory to list*/ Q1 = malloc(sizeof(My402List)); Q2 = malloc(sizeof(My402List)); /*Initilialize the list*/ My402ListInit(Q1); My402ListInit(Q2); /* Block Signal from Main thread */ block_signal(); if(FILENAME!=NULL){ FILE *fp = fopen(FILENAME, "r"); if(fp==NULL){ perror("Error: Unable to open the file "); exit(0); } fclose(fp); } print_input(lambda, mu, FILENAME, r, B, P, n); /* Create packet thread */ fprintf(stdout, "\n"); /* Initialize the stats */ init_stats(); struct timeval current = diff_timeval(START_TIMEVAL, PKT_BEFORE); fprintf(stdout, "%08llu.%03ldms: emulation begins\n", toMilliSeconds(current), current.tv_usec%MILLI); /* Create threads */ create_packet_thread(lambda, mu, FILENAME, r, B, P, n); /* Print statistics */ //print_stats(); return(0); }
/* Walk through intermediate tree and generate code. */ void im_codegen (inst_t * head) { /* Handle threads */ static int thread_cnt = 0; if (bfthreads) { fprintf (bfout, "void *bf%d (void *x) {\n", thread_cnt); fprintf (bfout, " int ptri = %d;\n\n", thread_cnt); thread_cnt++; } indent = 1; int returned = 0; inst_t *inst = head; while (inst != NULL) { lineno = inst->lineno; if (inst->comment && pass_comments) { fprintf (bfout, "/*\n %s \n*/\n", inst->comment); } switch (inst->inst * !returned) { case IM_CINC: /* Cell increment */ print_incdec ('+', inst->src); break; case IM_CDEC: /* Cell decrement */ print_incdec ('-', inst->src); break; case IM_PRGHT: /* Move pointer right */ print_move ('>', inst->src); break; case IM_PLEFT: /* Move pointer left */ print_move ('<', inst->src); break; case IM_IN: /* Input */ print_input (); break; case IM_OUT: /* Output */ print_output (); break; case IM_CADD: /* Cell copy */ print_ccpy (inst->dst, inst->src); break; case IM_CCLR: /* Cell clear */ print_cclr (); break; } /* Select next instruction. First from loop, then from next, then from ret. */ if (inst->loop && !returned) { print_loop (); inst = inst->loop; returned = 0; indent++; } else if (inst->next) { inst = inst->next; returned = 0; } else if (inst->ret) { print_end (); inst = inst->ret; returned = 1; indent--; } else inst = NULL; } if (bfthreads) { fprintf (bfout, "\n"); fprintf (bfout, " pthread_exit (NULL);\n"); fprintf (bfout, "} /* thread %d */\n\n", thread_cnt - 1); } }
int main(int argc, char *argv[]) { srand(atoi(argv[1])); int num_errors = 0; printf("Starting test of Steward card...\n"); /*for(int i = 0; i < NUMBER_ITERATIONS; i++ )*/ { /* printf("\n\n*************************************************\n\nStarting Test# %d\n", i); */ struct gameState myState; int numPlayers = rand() % 2 + 2;//Generate valid number of players int myKingdomCards[10]; gen_valid_KC_card(myKingdomCards, embargo); int coins = rand() % 10; int numBuys = rand() % 3; int supplyCount[treasure_map+1]; gen_supply_count(supplyCount, myKingdomCards, numPlayers); int hand[MAX_PLAYERS][MAX_HAND]; int handCount[MAX_PLAYERS]; int deck[MAX_PLAYERS][MAX_DECK]; int deckCount[MAX_PLAYERS]; int discard[MAX_PLAYERS][MAX_DECK]; int discardCount[MAX_PLAYERS]; gen_hand_deck_discard(hand, handCount, deck, deckCount, discard, discardCount, numPlayers, myKingdomCards); int whoseTurn = rand() % numPlayers; int choice1 = rand() % 3; int choice2 = rand() % handCount[whoseTurn]; int choice3 = rand() % handCount[whoseTurn]; int bonus = rand() % treasure_map; int embargoTokens[treasure_map+1]; for(int i=0; i<=treasure_map; i++) { embargoTokens[i] = rand() % 2; } int handPos = rand() % handCount[whoseTurn]; hand[whoseTurn][handPos] = embargo; int numActions = rand() % 3 + 1; set_state(&myState, numPlayers, supplyCount, embargoTokens, whoseTurn, numActions, hand, handCount, deck, deckCount, discard, discardCount, numBuys, coins); struct gameState copyState; set_state(©State, numPlayers, supplyCount, embargoTokens, whoseTurn, numActions, hand, handCount, deck, deckCount, discard, discardCount, numBuys, coins); int result = cardEffect(steward, choice1, choice2, choice3, &myState, handPos, &bonus); int temp_num_errors = check_result(myState, copyState, choice1, choice2, choice3, myKingdomCards, result, handPos); if( temp_num_errors > 0 || VERBOSE) { print_input(numPlayers, myKingdomCards, supplyCount, myState.embargoTokens, whoseTurn, numActions, coins, numBuys, hand, handCount, deck, deckCount, discard, discardCount, choice1, choice2, choice3); } num_errors += temp_num_errors; } printf("\nFound %d errors.\n", num_errors); if(num_errors > 0) { return 0; } return 1; }
/** * Server loop. * * Wait for incoming data from remote peer and if echo mode is on, echo it * back. * * @param ctx Pointer to main context. * @param fd The socket to the remote peer (in SOCK_STREAM mode) or the "server * socket" in SOCK_SEQPKT mode. * @return SERVER_USER_CLOSE if user requested stop (ctrl+c was pressed), * SERVER_ERROR if there was error when receiving data, SERVER_OK if the remote * end closed connetion. */ int do_server( struct server_ctx *ctx, int fd ) { struct sockaddr_storage peer_ss; socklen_t peerlen; struct sctp_sndrcvinfo info; int ret,flags; while( ! close_req ) { memset( &peer_ss, 0, sizeof( peer_ss )); memset( &info, 0, sizeof( peer_ss )); peerlen = sizeof( struct sockaddr_in6); flags = 0; ret = recv_wait( fd, ACCEPT_TIMEOUT_MS, ctx->recvbuf, ctx->recvbuf_size, (struct sockaddr *)&peer_ss, &peerlen, &info, &flags ); if ( ret == -1 ) { if ( errno == EINTR ) continue; print_error("Unable to read data", errno); return SERVER_ERROR; } else if ( ret == -2 ) { printf("Connection closed by remote host\n" ); return SERVER_REMOTE_CLOSED; } else if ( ret > 0 ) { DBG("Received %d bytes \n", ret ); partial_store_collect(&ctx->partial, ctx->recvbuf, ret); if ( flags & MSG_NOTIFICATION ) { TRACE("Received SCTP event\n"); if ( flags & MSG_EOR ) { handle_event(partial_store_dataptr(&ctx->partial)); partial_store_flush(&ctx->partial); } continue; } if (is_flag(ctx->options, VERBOSE_FLAG)) print_input( &peer_ss, ret, flags, &info); else print_input( &peer_ss, ret, flags, NULL); if (is_flag(ctx->options, XDUMP_FLAG)) xdump_data( stdout, ctx->recvbuf, ret, "Received data" ); if ( is_flag( ctx->options, ECHO_FLAG ) && (flags & MSG_EOR) ) { if ( sendit( fd, info.sinfo_ppid, info.sinfo_stream, (struct sockaddr *)&peer_ss, peerlen, partial_store_dataptr( &ctx->partial), partial_store_len( &ctx->partial) ) < 0) { WARN("Error while echoing data!\n"); } else { if (is_flag(ctx->options, VERBOSE_FLAG)) print_output_verbose(&peer_ss, partial_store_len(&ctx->partial), info.sinfo_ppid, info.sinfo_stream); else print_output( &peer_ss, partial_store_len(&ctx->partial)); } } if ( flags & MSG_EOR ) partial_store_flush( &ctx->partial ); } } return SERVER_USER_CLOSE; }