Beispiel #1
0
// Removes the queue completely from memory.
void aqueue_free(ArrayQueue* q)
{
	if (q == NULL)
		return;

	aqueue_clear(q);
	free(q->data);
	free(q);
}
Beispiel #2
0
void exampleArrayQueue()
{
	ArrayQueue* Q = newArrayQueue(8);

	// A queue with strings
	aqueue_offer(Q, "First");
	aqueue_offer(Q, "In");
	aqueue_offer(Q, "First");
	aqueue_offer(Q, "Out.");
	
	// Peek at the head of the queue
	printf("%s\n", (char*)aqueue_peek(Q));

	// Traverse through the queue polling each string
	while (!aqueue_isEmpty(Q))
		printf("%s ", (char*)aqueue_poll(Q));
	printf("\n");

	// A queue with integers, primitive data types require some trickyness
	aqueue_clear(Q);
	int x[] = {1, 2};
	int y = 3;
	aqueue_offer(Q, &x[0]);
	aqueue_offer(Q, &x[1]);
	aqueue_offer(Q, &y);
	
	while (!aqueue_isEmpty(Q))
		// You first need to cast it using (int*) and since its a pointer to
		// an integer you need to get the value of the pointer using *
		// You could similarly use:
		// 	int* z = queue_poll(Q);
		//		printf("%d ", *z);
		printf("%d ", *((int*)aqueue_poll(Q)));

	printf("\n");
	
	// Fill it up and resize it if an offer has failed
	char* letters[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K"};
	for (y = 0; y < 11; y++)
		aqueue_offerf(Q, letters[y]);

	while (!aqueue_isEmpty(Q))
		printf("%s ", (char*)aqueue_poll(Q));
	printf("\n");

	// This will clear the queue of any nodes and pool them and then free
	// the queue itself from memory
	aqueue_free(Q);
}
static
void ldap_connection_abort_all_requests(struct ldap_connection *conn)
{
	struct ldap_result res;
	memset(&res, 0, sizeof(res));
	res.openldap_ret = LDAP_TIMEOUT;
	res.error_string = "Aborting LDAP requests due to failure";

	unsigned int n = aqueue_count(conn->request_queue);
	for (unsigned int i = 0; i < n; i++) {
		struct ldap_op_queue_entry **reqp =
			array_idx_modifiable(&(conn->request_array),
		aqueue_idx(conn->request_queue, i));
		if ((*reqp)->to_abort != NULL)
			timeout_remove(&(*reqp)->to_abort);
		if ((*reqp)->result_callback != NULL)
			(*reqp)->result_callback(&res, (*reqp)->result_callback_ctx);
		ldap_connection_request_destroy(reqp);
	}
	aqueue_clear(conn->request_queue);
}
Beispiel #4
0
static const char *test_aqueue2(unsigned int initial_size)
{
	ARRAY(unsigned int) aqueue_array;
	unsigned int i, j, k;

	for (i = 0; i < N_ELEMENTS(aqueue_input); i++) {
		for (k = 0; k < N_ELEMENTS(aqueue_input); k++) {
			struct aqueue *aqueue;

			t_array_init(&aqueue_array, initial_size);
			aqueue = aqueue_init(&aqueue_array.arr);
			aqueue->head = aqueue->tail = initial_size - 1;
			for (j = 0; j < k; j++) {
				aqueue_append(aqueue, &aqueue_input[j]);
				if (aqueue_count(aqueue) != j + 1) {
					return t_strdup_printf("Wrong count after append %u vs %u)",
							       aqueue_count(aqueue), j + 1);
				}
				if (!aqueue_is_ok(aqueue, UINT_MAX))
					return "Invalid data after append";
			}

			if (k != 0 && i < k) {
				aqueue_delete(aqueue, i);
				if (aqueue_count(aqueue) != k - 1)
					return "Wrong count after delete";
				if (!aqueue_is_ok(aqueue, i))
					return "Invalid data after delete";
			}
			aqueue_clear(aqueue);
			if (aqueue_count(aqueue) != 0)
				return "aqueue_clear() broken";
			aqueue_deinit(&aqueue);
		}
	}
	return NULL;
}