int pfring_bundle_read(pfring_bundle *bundle, u_char** buffer, u_int buffer_len, struct pfring_pkthdr *hdr, u_int8_t wait_for_incoming_packet) { u_int i, sock_id = 0, num_found, rc; struct timeval ts = { 0 }; redo_pfring_bundle_read: switch(bundle->policy) { case pick_round_robin: for(i=0; i<bundle->num_sockets; i++) { bundle->last_read_socket = (bundle->last_read_socket + 1) % bundle->num_sockets; if(pfring_there_is_pkt_available(bundle->sockets[bundle->last_read_socket])) { return(pfring_recv(bundle->sockets[bundle->last_read_socket], buffer, buffer_len, hdr, wait_for_incoming_packet)); } } break; case pick_fifo: num_found = 0; for(i=0; i<bundle->num_sockets; i++) { pfring *ring = bundle->sockets[i]; if(pfring_there_is_pkt_available(ring)) { struct pfring_pkthdr *header = (struct pfring_pkthdr*)&ring->slots[ring->slots_info->remove_off]; if((num_found == 0) || is_before(&header->ts, &ts)) { memcpy(&ts, &header->ts, sizeof(struct timeval)); num_found++, sock_id = i; } } } if(num_found > 0) { return(pfring_recv(bundle->sockets[sock_id], buffer, buffer_len, hdr, wait_for_incoming_packet)); } break; } if(wait_for_incoming_packet) { rc = pfring_bundle_poll(bundle, bundle->sockets[0]->poll_duration); if(rc > 0) { goto redo_pfring_bundle_read; } else return(rc); } return(0); }
void test_insert(list_t *list) { result_t insert_result; insert_result = insert_at_begin(list, 10); assert(insert_result == SUCCESS && is_at_begining(list, 10) == TRUE); insert_result = insert_at_end(list, 40); assert(insert_result == SUCCESS && is_at_end(list, 40) == TRUE); insert_result = insert_before_data(list, 40, 30); assert(insert_result == SUCCESS && is_before(list, 30, 40) == TRUE); insert_result = insert_before_data(list, 10, 5); assert(insert_result == SUCCESS && is_before(list, 5, 10) == TRUE); insert_result = insert_before_data(list, 100, 50); assert(insert_result == ERROR && is_before(list, 50, 100) == FALSE); insert_result = insert_after_data(list, 40, 50); assert(insert_result == SUCCESS && is_after(list, 50, 40) == TRUE); insert_result = insert_after_data(list, 5, 8); assert(insert_result == SUCCESS && is_after(list, 8, 5) == TRUE); insert_result = insert_after_data(list, 35, 45); assert(insert_result == ERROR && is_after(list, 45, 35) == FALSE); }
int main() { long i; o_t *o; printf("starting \n"); o = create_order(); for(i=100000; i>=0; i-- ) insert_bottom( o, p(i) ); for(i=100001; i< 300007; i+=2 ) { insert_after(o, p(i+1), p(i-1) ); insert_before( o, p(i), p(i+1) ); } printf("inserted 300000 elements. "); for(i = 250000; i < 300007; i++ ) delete_o( o, p(i) ); printf("deleted 50000 elements. "); insert_top( o, p(300006) ); for(i = 250000; i < 300006; i++ ) insert_before( o, p(i) , p(300006) ); printf("reinserted. now testing order\n"); for( i=0; i < 299000; i +=42 ) { if( is_before( o, p(i), p(i+23) ) != 1 ) { printf(" found error (1) \n"); exit(0); } } for( i=300006; i >57; i -=119 ) { if( is_before( o, p(i), p(i-57) ) != 0 ) { printf(" found error (0) \n"); exit(0); } } printf("finished. no problem found.\n"); }
static void mkreftable (void) { int i, j, k, yr; const char *era, *sfx; /* Japanese era year to be checked. */ static const int yrj[] = { 43, 44, 45, 2, 63, 64, 1, 2, 9, 10, 22, 23, 31, 1 }; /* Buddhist calendar year to be checked. */ static const int yrb[] = { 2453, 2454, 2455, 2456, 2531, 2532, 2532, 2533, 2540, 2541, 2553, 2554, 2562, 2562 }; /* R.O.C. calendar year to be checked. Negative number is prior to Minguo counting up. */ static const int yrc[] = { -2, -1, 1, 2, 77, 78, 78, 79, 86, 87, 99, 100, 108, 108 }; for (i = 0; i < array_length (locales); i++) for (j = 0; j < array_length (formats); j++) for (k = 0; k < array_length (dates); k++) { if (i == ja_JP) { era = (is_before (k, 30, 7, 1912)) ? "\u660e\u6cbb" : (is_before (k, 25, 12, 1926)) ? "\u5927\u6b63" : (is_before (k, 8, 1, 1989)) ? "\u662d\u548c" : (is_before (k, 1, 5, 2019)) ? "\u5e73\u6210" : "\u4ee4\u548c"; yr = yrj[k], sfx = "\u5e74"; } else if (i == lo_LA) era = "\u0e9e.\u0eaa. ", yr = yrb[k], sfx = ""; else if (i == th_TH) era = "\u0e1e.\u0e28. ", yr = yrb[k], sfx = ""; else if (i == zh_TW || i == cmn_TW || i == hak_TW || i == nan_TW || i == lzh_TW) { era = (is_before (k, 1, 1, 1912)) ? "\u6c11\u524d" : "\u6c11\u570b"; yr = yrc[k], sfx = "\u5e74"; } else FAIL_EXIT1 ("Invalid table index!"); if (yr == 1) sprintf (ref[i][j][k], "%s\u5143%s", era, sfx); else if (j == 0) sprintf (ref[i][j][k], "%s%02d%s", era, abs (yr), sfx); else if (j == 1) sprintf (ref[i][j][k], "%s%2d%s", era, abs (yr), sfx); else if (j == 2) sprintf (ref[i][j][k], "%s%d%s", era, abs (yr), sfx); else FAIL_EXIT1 ("Invalid table index!"); } }