int dtls1_retransmit_buffered_messages(SSL *s) { pqueue sent = s->d1->sent_messages; piterator iter; pitem *item; hm_fragment *frag; int found = 0; iter = pqueue_iterator(sent); for ( item = pqueue_next(&iter); item != NULL; item = pqueue_next(&iter)) { frag = (hm_fragment *)item->data; if ( dtls1_retransmit_message(s, (unsigned short)dtls1_get_queue_priority(frag->msg_header.seq, frag->msg_header.is_ccs), 0, &found) <= 0 && found) { fprintf(stderr, "dtls1_retransmit_message() failed\n"); return -1; } } return 1; }
static void pqueue_print(pqueue pq) { pitem *iter, *item; iter = pqueue_iterator(pq); for (item = pqueue_next(&iter); item != NULL; item = pqueue_next(&iter)) { printf("item\t%02x%02x%02x%02x%02x%02x%02x%02x\n", item->priority[0], item->priority[1], item->priority[2], item->priority[3], item->priority[4], item->priority[5], item->priority[6], item->priority[7]); } }
static int pqueue_test(pqueue pq) { pitem *iter, *item; char *buf = NULL; char *expected = NULL; int ret = 0, size, len = 0; size = asprintf(&expected, "%s%s%s", prio1_expected, prio2_expected, prio3_expected); if (size == -1) goto err; if ((buf = malloc(size)) == NULL) goto err; iter = pqueue_iterator(pq); for (item = pqueue_next(&iter); item != NULL; item = pqueue_next(&iter)) { len += snprintf(buf + len, size, "%02x%02x%02x%02x%02x%02x%02x%02x", item->priority[0], item->priority[1], item->priority[2], item->priority[3], item->priority[4], item->priority[5], item->priority[6], item->priority[7]); if (len == -1) goto err; } if (strcmp(expected, buf) != 0) { printf("expected: %s\nresult: %s\n", expected, buf); goto err; } ret = 1; err: free(expected); return ret; }
static int fixed_random() { /* Random order of 10 elements, chosen by * random.choice(list(itertools.permutations(range(10)))) */ int ordering[NUM_ITEMS] = {9, 6, 3, 4, 0, 2, 7, 1, 8, 5}; int i; pqueue q = pqueue_new(); uint8_t priority[8] = {0}; piterator iter; pitem *curr, *item; if (q == NULL) { return 0; } /* Insert the elements */ for (i = 0; i < NUM_ITEMS; i++) { priority[7] = ordering[i]; item = pitem_new(priority, &ordering[i]); if (pqueue_insert(q, item) != item) { return 0; } } /* Insert the elements again. This inserts duplicates and should * fail. */ for (i = 0; i < NUM_ITEMS; i++) { priority[7] = ordering[i]; item = pitem_new(priority, &ordering[i]); if (pqueue_insert(q, item) != NULL) { return 0; } pitem_free(item); } if (pqueue_size(q) != NUM_ITEMS) { return 0; } /* Iterate over the elements. */ iter = pqueue_iterator(q); curr = pqueue_next(&iter); if (curr == NULL) { return 0; } while (1) { pitem *next = pqueue_next(&iter); int *curr_data, *next_data; if (next == NULL) { break; } curr_data = (int*)curr->data; next_data = (int*)next->data; if (*curr_data >= *next_data) { return 0; } curr = next; } pqueue_free(q); return 1; }