Ejemplo n.º 1
0
void destroyConnection(Connection *conn) {

	if (pthread_rwlock_destroy(&(conn->state.rwlock)) > 0)
		ERREXIT("Cannot destroy connection state read-write lock.");

	if (pthread_mutex_destroy(&(conn->sock.mtx)) > 0)
		ERREXIT("Cannot destroy connection socket mutex.");

	destroyTimeout(&(conn->timeout));

	destroyWindow(&(conn->sndwnd));

	destroyWindow(&(conn->rcvwnd));

	destroySgmBuff(&(conn->sndsgmbuff));

	destroySgmBuff(&(conn->rcvsgmbuff));

	destroyStrBuff(&(conn->sndusrbuff));

	destroyStrBuff(&(conn->rcvusrbuff));

	close(conn->sock.fd);

	removeElementFromList(&CONPOOL, conn->connid);
}
Ejemplo n.º 2
0
void removeElementFromHashset(struct HashSet *hashset, const char *word)
{
	unsigned int code;

	code = hashset->hashFunc(word, hashset->numberBuckets);
	removeElementFromList(hashset->buckets[code], word);
}
static char *test_removeElementFromList_firstElement() {
    Person *testPerson1 = (Person *) malloc(sizeof(Person));
    testPerson1->first_name = "John";
    testPerson1->last_name = "Kowalsky";
    Person *testPerson2 = (Person *) malloc(sizeof(Person));
    testPerson2->first_name = "Wladimir";
    testPerson2->last_name = "Nowak";

    Node *testListHead = initList(testPerson1);
    testListHead = pushFront(testListHead, testPerson2);

    Node *secondNode = testListHead->next;

    Person *removePerson = (Person *) malloc(sizeof(Person));
    removePerson->first_name = "Wladimir";
    removePerson->last_name = "Nowak";
    Node *nodeToRemove = (Node *) malloc(sizeof(Node));
    nodeToRemove->person = removePerson;
    nodeToRemove->previous = NULL;
    nodeToRemove->next = secondNode;

    Node *listAfterRemoval = removeElementFromList(testListHead, nodeToRemove);
    mu_assert("error in removeElementFromList_firstElement",
              strcmp(listAfterRemoval->person->first_name ,"John") == 0);
    removeList(listAfterRemoval);
    free(removePerson);
    return 0;
}
static char *test_removeElementFromList_lastElement() {
    Person *testPerson1 = (Person *) malloc(sizeof(Person));
    Person *testPerson2 = (Person *) malloc(sizeof(Person));
    Person *testPerson3 = (Person *) malloc(sizeof(Person));

    testPerson1->first_name = "Zbigniew";
    testPerson1->last_name = "Ostatek";

    testPerson2->first_name = "Wladimir";
    testPerson2->last_name = "Srodkowy";

    testPerson3->first_name = "Andrzej";
    testPerson3->last_name = "Pierwszy";

    Node *testListHead = initList(testPerson1);
    testListHead = pushFront(testListHead, testPerson2);
    testListHead = pushFront(testListHead, testPerson3);

    Node *secondNode = testListHead->next;

    Node *nodeToRemove = (Node *) malloc(sizeof(Node));
    Person *removePerson = (Person *) malloc(sizeof(Person));
    removePerson->first_name = "Zbigniew";
    removePerson->last_name = "Ostatek";
    nodeToRemove->person = removePerson;
    nodeToRemove->previous = secondNode;

    Node *listAfterRemoval = removeElementFromList(testListHead, nodeToRemove);
    mu_assert("error in testRemoveElementFromList_lastElement",
              listAfterRemoval->next->next == NULL);
    removeList(listAfterRemoval);
    free(nodeToRemove);
    free(removePerson);
    return 0;
}
static char *test_removeElementFromList_emptyElementFromExistingList() {
    Node *emptyNode = (Node *) malloc(sizeof(Node));

    Person *testPerson1 = (Person *) malloc(sizeof(Person));
    testPerson1->first_name = "John";
    testPerson1->last_name = "Kowalsky";
    testPerson1->address = "Walbrzych";
    Person *testPerson2 = (Person *) malloc(sizeof(Person));
    testPerson2->first_name = "Wladimir";
    testPerson2->last_name = "Nowak";
    testPerson2->address = "Wroclaw";


    Node *testListHead = initList(testPerson1);
    testListHead = pushFront(testListHead, testPerson2);

    Node *listAfterRemoval = removeElementFromList(testListHead, emptyNode);

    mu_assert("error in removeElementFromList_emptyElementFromExistingList",
              testListHead == listAfterRemoval);
    removeList(listAfterRemoval);
    return 0;
}