From d338568b1e20e9f4569674b5fec1185c01ba2e10 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 13:50:12 -0700 Subject: [PATCH 01/56] Deleted main.c (list test cases) --- main.c | 811 --------------------------------------------------------- 1 file changed, 811 deletions(-) delete mode 100644 main.c diff --git a/main.c b/main.c deleted file mode 100644 index 1e8183b..0000000 --- a/main.c +++ /dev/null @@ -1,811 +0,0 @@ -#include -#include -#include -#include -#include"list.h" - -// Funcion to free statically allocated items -// Empty because deletion of statically allocated items are handled by the compiler -void freeStatic(void* pItem) -{ - return; -} - -// Function to free dynamically allocated items -void freeDynamic (void* pItem) -{ - free(pItem); -} - -// Function to compare integers -bool compareInt (void* pItem, void* pComparisonArg) -{ - return *(int*)pItem==*(int*)pComparisonArg; -} - -// Testing List_Create(), List_Free() and the head max limit to see if memory management works -void testHeadRelated() -{ - printf("\n\nTesting list create and head limit \n"); - int i; - List* heads[12]; - printf("Creating an array of size 12 of pointers to heads \n"); - for (i=0;i<12;i++) - { - heads[i]=List_create(); - } - - printf("Printing the pointers to the heads in the array \n"); - for(i=0;i<12;i++) - { - printf("Value inside heads[%d]: %p \n",i,heads[i]); - } - printf("Expected result : heads[10] and heads[11] are NULL pointers \n"); - - printf("\nTesting List_free \n"); - printf("Deleting all currently allocated heads \n"); - for (i=0;i<12;i++) - { - if(heads[i]!=NULL) - { - List_free(heads[i],&freeStatic); - } - } - printf("Re-creating an array of size 10 of pointers to heads \n"); - for (i=0;i<10;i++) - { - heads[i]=List_create(); - printf("Value inside heads[%d]: %p \n",i,heads[i]); - } - printf("Expected: No null pointers\n"); - printf("Deleting all currently allocated heads \n"); - for (i=0;i<12;i++) - { - if(heads[i]!=NULL) - { - List_free(heads[i],&freeStatic); - } - } -} - -void testListCount() -{ - printf("\n\nTesting List_count function\n"); - printf("Creating empty head\n"); - List* head = List_create(); - printf("List_count(head) = %d (expected = 0)\n",List_count(head)); - printf("Adding a node to head\n"); - int testItem = 0; - List_add(head, &testItem); - printf("List_count(head) = %d (expected = 1)\n",List_count(head)); - printf("Deleting a node\n"); - List_remove(head); - printf("List_count(head) = %d (expected = 0)\n",List_count(head)); - printf("Deleting all currently allocated heads \n"); - List_free(head,&freeStatic); - -} - -// Testing traversal functions; List_first, List_last, List_next, List_prev, List_curr -void testListTraversal() -{ - printf("\n\nTesting traversal functions \n"); - printf("Creating empty head\n"); - List* head = List_create(); - printf("List_first(head) = %p (expected NULL)\n", List_first(head)); - printf("List_last(head) = %p (expected NULL)\n", List_last(head)); - printf("List_next(head) = %p (expected NULL)\n", List_next(head)); - printf("List_prev(head) = %p (expected NULL)\n", List_prev(head)); - printf("List_curr(head) = %p (expected NULL)\n", List_curr(head)); - - printf("\nAdding one node to the head with value integer 0 \n"); - int testItem = 0; - List_add(head, &testItem); - printf("*(int*)List_first(head) = %d (expected 0)\n", *(int*)List_first(head)); - printf("*(int*)List_last(head) = %d (expected 0)\n", *(int*)List_last(head)); - printf("*(int*)List_curr(head) = %d (expected 0)\n", *(int*)List_curr(head)); - - printf("\n Testing next and prev with 1 node, also testing behaviour when beyond start/end\n"); - printf("List_next(head) = %p (expected NULL)\n",List_next(head)); - printf("head->oob = %d (expected 1 (oob end)) \n",head->oob); - printf("List_next(head) = %p (expected NULL)\n",List_next(head)); - printf("head->oob = %d (expected 1 (oob end)) \n",head->oob); - printf("*(int*)List_prev(head) = %d (expected 0)\n", *(int*)List_prev(head)); - printf("List_prev(head) = %p (expected NULL)\n",List_prev(head)); - printf("head->oob = %d (expected 0 (oob start)) \n",head->oob); - printf("List_prev(head) = %p (expected NULL)\n",List_prev(head)); - printf("head->oob = %d (expected 0 (oob start)) \n",head->oob); - printf("*(int*)List_next(head) = %d (expected 0)\n", *(int*)List_next(head)); - - printf("\nAdding another node to the head with value integer 1 (current item count =2)\n"); - int testItem1=1; - List_add(head, &testItem1); - printf("*(int*)List_first(head) = %d (expected 0)\n", *(int*)List_first(head)); - printf("*(int*)List_last(head) = %d (expected 1)\n", *(int*)List_last(head)); - printf("*(int*)List_curr(head) = %d (expected 1)\n", *(int*)List_curr(head)); - - printf("\n Testing next and prev with 2 nodes\n"); - printf("*(int*)List_prev(head) = %d (expected 0)\n", *(int*)List_prev(head)); - printf("*(int*)List_next(head) = %d (expected 1)\n", *(int*)List_next(head)); - - - printf("\nDeleting all currently allocated heads \n"); - List_free(head,&freeStatic); -} - -// Testing the addition functions: List_add, List_insert, List_append, List_prepend -void testListAddition() -{ - printf("\n\nTesting addition functions\n"); - printf("\nTesting adding into empty lists \n"); - List* heads[4]; - for (int i=0;i<4;i++) - { - heads[i] = List_create(); - } - int testItem0=0; - List_add(heads[0], &testItem0); - List_insert(heads[1], &testItem0); - List_append(heads[2], &testItem0); - List_prepend(heads[3], &testItem0); - printf("Current item in heads[0] after adding 0 = %d \n", *(int* ) List_curr(heads[0])); - printf("Current item in heads[1] after inserting 0 = %d \n", *(int* ) List_curr(heads[1])); - printf("Current item in heads[2] after appending 0 = %d \n", *(int* ) List_curr(heads[2])); - printf("Current item in heads[3] after prepending 0 = %d \n", *(int* ) List_curr(heads[3])); - - printf("\nAdding 1 and 2 with each addition method for each element of heads\n"); - int testItem1=1; - List_add(heads[0], &testItem1); //0 1 - List_insert(heads[1], &testItem1); // 1 0 - List_append(heads[2], &testItem1); // 0 1 - List_prepend(heads[3], &testItem1); // 1 0 - - int testItem2=2; - List_add(heads[0], &testItem2); //0 1 2 - List_insert(heads[1], &testItem2); // 2 1 0 - List_append(heads[2], &testItem2); // 0 1 2 - List_prepend(heads[3], &testItem2); // 2 1 0 - - for(int i=0;i<4;i++) - { - printf("\nPrinting nodes in heads[%d] \n",i); - int j=0; - List_first(heads[i]); - while(heads[i]->current!=NULL) - { - printf("\t Value in Node #%d: %d",j,*(int*)List_curr(heads[i])); - List_next(heads[i]); - j++; - if(j%5==0) - { - printf("\n"); - } - } - printf("\nPrinting head and tail nodes in heads[%d] \n",i); - printf("\tHead of heads[%d] : %d",i,*(int*)heads[i]->head->item); - printf("\tTail of heads[%d] : %d",i,*(int*)heads[i]->tail->item); - printf("\n"); - } - - printf("\nChanging current node into the middle node, and adding 3 to the list with each addition method \n"); - for(int i=0;i<4;i++) - { - List_first(heads[i]); - List_next(heads[i]); - } - int testItem3=3; - List_add(heads[0], &testItem3); //0 1 3 2 - List_insert(heads[1], &testItem3); // 2 3 1 0 - List_append(heads[2], &testItem3); // 0 1 2 3 - List_prepend(heads[3], &testItem3); // 3 2 1 0 - for(int i=0;i<4;i++) - { - printf("\nPrinting nodes in heads[%d] \n",i); - int j=0; - List_first(heads[i]); - while(heads[i]->current!=NULL) - { - printf("\t Value in Node #%d: %d",j,*(int*)List_curr(heads[i])); - List_next(heads[i]); - j++; - if(j%5==0) - { - printf("\n"); - } - } - printf("\n"); - } - - printf("\nTesting additions when current is before start\n"); - for(int i=0;i<4;i++) - { - List_first(heads[i]); - List_prev(heads[i]); - } - int testItem4=4; - List_add(heads[0], &testItem4); //4 0 1 3 2 - List_insert(heads[1], &testItem4); //4 2 3 1 0 - List_append(heads[2], &testItem4); //0 1 2 3 4 - List_prepend(heads[3], &testItem4); //4 3 2 1 0 - for(int i=0;i<4;i++) - { - printf("\nPrinting nodes in heads[%d] \n",i); - int j=0; - List_first(heads[i]); - while(heads[i]->current!=NULL) - { - printf("\t Value in Node #%d: %d",j,*(int*)List_curr(heads[i])); - List_next(heads[i]); - j++; - if(j%5==0) - { - printf("\n"); - } - } - printf("\nPrinting head and tail nodes in heads[%d] \n",i); - printf("\tHead of heads[%d] : %d",i,*(int*)heads[i]->head->item); - printf("\tTail of heads[%d] : %d",i,*(int*)heads[i]->tail->item); - - printf("\n"); - } - - printf("\nTesting additions when current is before start\n"); - for(int i=0;i<4;i++) - { - List_last(heads[i]); - List_next(heads[i]); - } - int testItem5=5; - List_add(heads[0], &testItem5); //4 0 1 3 2 5 - List_insert(heads[1], &testItem5); //4 2 3 1 0 5 - List_append(heads[2], &testItem5); //0 1 2 3 4 5 - List_prepend(heads[3], &testItem5); //5 4 3 2 1 0 - for(int i=0;i<4;i++) - { - printf("\nPrinting nodes in heads[%d] \n",i); - int j=0; - List_first(heads[i]); - while(heads[i]->current!=NULL) - { - printf("\t Value in Node #%d: %d",j,*(int*)List_curr(heads[i])); - List_next(heads[i]); - j++; - if(j%6==0) - { - printf("\n"); - } - } - printf("\nPrinting head and tail nodes in heads[%d] \n",i); - printf("\tHead of heads[%d] : %d",i,*(int*)heads[i]->head->item); - printf("\tTail of heads[%d] : %d",i,*(int*)heads[i]->tail->item); - - printf("\n"); - } - for(int i=0;i<4;i++) - { - printf("Current size of list (expected 6) : %d\n", List_count(heads[i])); - } - - printf("\nDeleting all currently allocated heads \n"); - for (int i=0;i<4;i++) - { - List_free(heads[i],&freeStatic); - } - - printf("\nTesting addition on non available heads \n"); - printf("List_add(heads[0], &testItem5) = %d (expected -1) \n",List_add(heads[0], &testItem5)); //empty - printf("List_insert(heads[1], &testItem5) = %d (expected -1) \n",List_insert(heads[1], &testItem5)); //empty - printf("List_append(heads[2], &testItem5) = %d (expected -1) \n",List_append(heads[2], &testItem5)); //empty - printf("List_prepend(heads[3], &testItem5) = %d (expected -1) \n",List_prepend(heads[3], &testItem5)); //empty -} - -// Testing the node max limits to see if memory management works -void testNodeLimit() -{ - printf("\n\nTesting node limit \n"); - printf("Testing with 1 head \n"); - List* head = List_create(); - int testItems[102]; - for (int i=0;i<102;i++) - { - testItems[i]=i; - } - printf("Adding 100 nodes containing ints 0 to 99 to the head \n"); - for (int i=0;i<100;i++) - { - List_add(head, &testItems[i]); - } - - printf("Attempting to add ints 100 and 101 to the head \n"); - List_add(head, &testItems[100]); - List_add(head, &testItems[101]); - - printf("Printing the items in the nodes in the array \n"); - int i=0; - List_first(head); - while(head->current!=NULL) - { - printf("Value in Node #%d : %d ",i,*(int*)List_curr(head)); - List_next(head); - i++; - if(i%5==0) - { - printf("\n"); - } - } - printf("\n"); - printf("Expected result : no node with item 100 and 101 \n"); - - printf("Deleting the list \n"); - List_free(head,&freeStatic); - - printf("\n\nTesting with multiple heads \n"); - printf("Creating 10 heads \n"); - List* heads[10]; - for (int i=0;i<10;i++) - { - heads[i]=List_create(); - } - - printf("Populating each of the 10 heads with 10 nodes\n"); - for(int i=0;i<100;i++) - { - List_add(heads[i/10],&testItems[i]); - } - - printf("Attempting to add one node to each head with item 100\n"); - for(int i=0;i<10;i++) - { - List_add(heads[i], &testItems[100]); - } - - for(int i=0;i<10;i++) - { - printf("Printing nodes in heads[%d] \n",i); - int j=0; - List_first(heads[i]); - while(heads[i]->current!=NULL) - { - printf("\t Value in Node #%d: %d",j,*(int*)List_curr(heads[i])); - List_next(heads[i]); - j++; - if(j%5==0) - { - printf("\n"); - } - } - printf("\n"); - } - - printf("Expected: No node with item 100\n"); - - printf("\nDeleting all currently allocated heads \n"); - for (i=0;i<10;i++) - { - List_free(heads[i],&freeStatic); - } -} - -// Testing removal functions: List_remove, List_trim -void testRemovalFunctions() -{ - printf("\n\nTesting node removal functions\n"); - printf("\nTesting removing empty lists \n"); - List* head; - head = List_create(); - printf("List_remove(head) : %p (expected NULL) \n",List_remove(head)); - printf("List_trim(head) : %p (expected NULL) \n",List_trim(head)); - - printf("\nAdding 0 to 10 to the list\n"); - int testItems[10]; - for (int i=0;i<10;i++) - { - testItems[i]=i; - List_add(head, &testItems[i]); - } - int i=0; - List_first(head); - while(head->current!=NULL) - { - printf("Value in Node #%d : %d ",i,*(int*)List_curr(head)); - List_next(head); - i++; - if(i%5==0) - { - printf("\n"); - } - } - printf("Current size of list (expected 10) : %d\n", List_count(head)); - printf("\n"); - - printf("Current node is in beyond end\n"); - printf("List_remove(head) : %p (expected NULL) \n",List_remove(head)); - printf("*(int*)List_trim(head) : %d (expected 9) \n",*(int*)List_trim(head)); - printf("Tail after trimming: %d (expected 8) \n",*(int*)List_last(head)); - printf("Current size of list (expected 9) : %d\n", List_count(head)); - - printf("\nMoving current node to be before start \n"); - List_first(head); - List_prev(head); - printf("List_remove(head) : %p (expected NULL) \n",List_remove(head)); - printf("*(int*)List_trim(head) : %d (expected 8) \n",*(int*)List_trim(head)); - printf("Tail after trimming: %d (expected 7) \n",*(int*)List_last(head)); - printf("Current size of list (expected 8) : %d\n", List_count(head)); - - printf("\nMoving current node to start\n"); - printf("Head before removing: %d (expected 0) \n",*(int*)List_first(head)); - printf("List_remove(head) : %d (expected 0) \n",*(int*)List_remove(head)); - printf("Head after removing: %d (expected 1) \n",*(int*)List_first(head)); - printf("Current size of list (expected 7) : %d\n", List_count(head)); - - printf("\nMoving current node to end\n"); - printf("Tail before removing: %d (expected 7) \n",*(int*)List_last(head)); - printf("List_remove(head) : %d (expected 7) \n",*(int*)List_remove(head)); - printf("Tail after removing: %d (expected 6) \n",*(int*)List_last(head)); - printf("Current size of list (expected 6) : %d\n", List_count(head)); - - printf("\nPrinting current list\n"); - i=0; - List_first(head); - while(head->current!=NULL) - { - printf("Value in Node #%d : %d ",i,*(int*)List_curr(head)); - List_next(head); - i++; - if(i%5==0) - { - printf("\n"); - } - } - printf("Current size of list (expected 6) : %d\n", List_count(head)); - printf("\n"); - - printf("\nMoving current node to the third node (item stored 3)\n"); - List_first(head); - List_next(head); - printf("Third node before removing: %d (expected 3) \n",*(int*)List_next(head)); - printf("List_remove(head) : %d (expected 3) \n",*(int*)List_remove(head)); - - printf("\nPrinting current list after third node removal\n"); - i=0; - List_first(head); - while(head->current!=NULL) - { - printf("Value in Node #%d : %d ",i,*(int*)List_curr(head)); - List_next(head); - i++; - if(i%5==0) - { - printf("\n"); - } - } - printf("Current size of list (expected 5) : %d\n", List_count(head)); - - printf("\nDeleting all currently allocated heads \n"); - List_free(head,&freeStatic); -} - -// Testing List_concat -void testConcat() -{ - printf("\nTesting List_concat\n"); - printf("\nTesting concat with 2 empty heads\n"); - printf("Creating 2 empty heads\n"); - List* head1=List_create(); - List* head2=List_create(); - printf("Concatenating both empty heads \n"); - List_concat(head1,head2); - printf("\tTo test whether or not head2 no longer exists, we create 9 more heads\n"); - printf("\tIf all 9 heads are successfully created, then List_concat properly removes head2\n"); - List* heads[10]; - for (int i=0;i<10;i++) - { - heads[i]=List_create(); - if(i<9) - { - printf("heads[%d] = %p (expected not NULL)\n",i,heads[i]); - } - else - { - printf("heads[%d] = %p (expected NULL)\n",i,heads[i]); - } - } - printf("\nDeleting the temporary array heads[] \n"); - for (int i=0;i<10;i++) - { - if(heads[i]!=NULL) - { - List_free(heads[i],&freeStatic); - } - } - - printf("\nTesting concat of non-empty head1 and empty head2\n"); - head2=List_create(); - printf("Adding 0 and 1 to head1\n"); - int testItems[10]; - for (int i=0;i<10;i++) - { - testItems[i]=i; - } - List_add(head1, &testItems[0]); - List_add(head1, &testItems[1]); - - printf("\nPrinting head1\n"); - int i=0; - List_first(head1); - while(head1->current!=NULL) - { - printf("Value in Node #%d : %d ",i,*(int*)List_curr(head1)); - List_next(head1); - i++; - if(i%5==0) - { - printf("\n"); - } - } - printf("\n"); - printf("Current size of list (expected 2) : %d\n", List_count(head1)); - - printf("\nConcatenating head1 with empty head2\n"); - List_concat(head1,head2); - - printf("\nPrinting head1 after concatenating with empty head2\n"); - i=0; - List_first(head1); - while(head1->current!=NULL) - { - printf("Value in Node #%d : %d ",i,*(int*)List_curr(head1)); - List_next(head1); - i++; - if(i%5==0) - { - printf("\n"); - } - } - printf("\n"); - printf("Current size of list (expected 2) : %d\n", List_count(head1)); - - printf("\tTo test whether or not head2 no longer exists, we create 9 more heads\n"); - printf("\tIf all 9 heads are successfully created, then List_concat properly removes head2\n"); - for (int i=0;i<10;i++) - { - heads[i]=List_create(); - if(i<9) - { - printf("heads[%d] = %p (expected not NULL)\n",i,heads[i]); - } - else - { - printf("heads[%d] = %p (expected NULL)\n",i,heads[i]); - } - } - printf("\nDeleting the temporary array heads[] \n"); - for (int i=0;i<10;i++) - { - if(heads[i]!=NULL) - { - List_free(heads[i],&freeStatic); - } - } - - printf("\nTesting concat of empty head1 and non-empty head2\n"); - List_free(head1,&freeStatic); - head1=List_create(); - head2=List_create(); - printf("Adding 0 and 1 to head2 \n"); - List_add(head2, &testItems[0]); - List_add(head2, &testItems[1]); - - printf("\nPrinting head2\n"); - i=0; - List_first(head2); - while(head2->current!=NULL) - { - printf("Value in Node #%d : %d ",i,*(int*)List_curr(head2)); - List_next(head2); - i++; - if(i%5==0) - { - printf("\n"); - } - } - printf("\n"); - printf("Current size of list (expected 2) : %d\n", List_count(head2)); - - printf("\nConcatenating empty head1 with non-empty head2\n"); - List_concat(head1,head2); - - printf("\nPrinting the previously empty head1 after concatenating with non-empty head2\n"); - i=0; - List_first(head1); - while(head1->current!=NULL) - { - printf("Value in Node #%d : %d ",i,*(int*)List_curr(head1)); - List_next(head1); - i++; - if(i%5==0) - { - printf("\n"); - } - } - printf("\n"); - printf("Current size of list (expected 2) : %d\n", List_count(head1)); - - printf("head1 = %p\n",head1); - - printf("\tTo test whether or not head2 no longer exists, we create 9 more heads\n"); - printf("\tIf all 9 heads are successfully created, then List_concat properly removes head2\n"); - for (int i=0;i<10;i++) - { - heads[i]=List_create(); - if(i<9) - { - printf("heads[%d] = %p (expected not NULL)\n",i,heads[i]); - } - else - { - printf("heads[%d] = %p (expected NULL)\n",i,heads[i]); - } - } - printf("\nDeleting the temporary array heads[] \n"); - for (int i=0;i<10;i++) - { - if(heads[i]!=NULL) - { - List_free(heads[i],&freeStatic); - } - } - - printf("\nConcatenating non-empty head1 with non-empty head2\n"); - List_free(head1,&freeStatic); - List_free(head2,&freeStatic); - head1=List_create(); - head2=List_create(); - printf("Adding 0 and 1 to head1 and 2 3 to head2"); - List_add(head1,&testItems[0]); - List_add(head1,&testItems[1]); - List_add(head2,&testItems[2]); - List_add(head2,&testItems[3]); - - printf("\nPrinting head1\n"); - i=0; - List_first(head1); - while(head1->current!=NULL) - { - printf("Value in Node #%d : %d ",i,*(int*)List_curr(head1)); - List_next(head1); - i++; - if(i%5==0) - { - printf("\n"); - } - } - printf("\n"); - printf("Current size of list (expected 2) : %d\n", List_count(head1)); - - printf("\nPrinting head2\n"); - i=0; - List_first(head2); - while(head2->current!=NULL) - { - printf("Value in Node #%d : %d ",i,*(int*)List_curr(head2)); - List_next(head2); - i++; - if(i%5==0) - { - printf("\n"); - } - } - printf("\n"); - printf("Current size of list (expected 1) : %d\n", List_count(head2)); - - printf("\nMoving current of head1 to tail of head1\n"); - printf("Current node of head1 is : %d\n",*(int*)List_last(head1)); - printf("\nConcatenating head1 and head2\n"); - List_concat(head1,head2); - - printf("Checking current node of head 1: %d (expected 1)\n",*(int*)List_curr(head1)); - - printf("\nPrinting head1 after concatenation with head2\n"); - i=0; - List_first(head1); - while(head1->current!=NULL) - { - printf("Value in Node #%d : %d ",i,*(int*)List_curr(head1)); - List_next(head1); - i++; - if(i%5==0) - { - printf("\n"); - } - } - printf("\n"); - printf("Current size of list (expected 4) : %d\n", List_count(head1)); - - printf("\nDeleting all currently allocated heads \n"); - List_free(head1,&freeStatic); - List_free(head2,&freeStatic); -} - -// Testing List_search -void testSearch() -{ - int i; - printf("\nTesting List_search\n"); - printf("\nCreating testItems[10] with values 0 to 9\n"); - int testItems[10]; - for(int i=0;i<10;i++) - { - testItems[i]=i; - } - printf("Testing with empty head\n"); - List* head=List_create(); - printf("List_search(head, &compareInt, &testItems[0]) = %p (expected NULL)\n",List_search(head, &compareInt, &testItems[0])); - - printf("\nPopulating the list with 0-9\n"); - for (int i=0;i<10;i++) - { - List_add(head, &testItems[i]); - } - - printf("\nPrinting head\n"); - i=0; - List_first(head); - while(head->current!=NULL) - { - printf("Value in Node #%d : %d ",i,*(int*)List_curr(head)); - List_next(head); - i++; - if(i%5==0) - { - printf("\n"); - } - } - printf("Current size of list (expected 10) : %d\n", List_count(head)); - - printf("\nMoving current node to beyond end and testing List_search\n"); - List_last(head); - List_next(head); - printf("List_search(head, &compareInt, &testItems[0]) = %p (expected NULL)\n",List_search(head, &compareInt, &testItems[0])); - - printf("\nMoving current node to before start and searching for 5\n"); - int test5=5; - List_first(head); - List_prev(head); - printf("*(int*)List_search(head, &compareInt, &test5) = %d (expected 5)\n",*(int*)List_search(head, &compareInt, &test5)); - printf("*(int*)List_curr(head) = %d (expected 5)\n",*(int*)List_curr(head)); - - printf("\nSearching for 8\n"); - int test8=8; - printf("*(int*)List_search(head, &compareInt, &test5) = %d (expected 8)\n",*(int*)List_search(head, &compareInt, &test8)); - printf("*(int*)List_curr(head) = %d (expected 8)\n",*(int*)List_curr(head)); - - printf("\nSearching for 5 which is behind current\n"); - printf("List_search(head, &compareInt, &test5) = %p (expected NULL)\n",List_search(head, &compareInt, &test5)); - printf("List_curr(head) = %p (expected NULL)\n",List_curr(head)); - printf("head->oob = %d (expected 1 (oob end) )\n",head->oob); - - printf("\nDeleting all currently allocated heads \n"); - List_free(head,&freeStatic); -} - -int main () -{ - testHeadRelated(); - printf("\n------------------------------------------------------\n"); - testListCount(); - printf("\n------------------------------------------------------\n"); - testListTraversal(); - printf("\n------------------------------------------------------\n"); - testListAddition(); - printf("\n------------------------------------------------------\n"); - testNodeLimit(); - printf("\n------------------------------------------------------\n"); - testRemovalFunctions(); - printf("\n------------------------------------------------------\n"); - testConcat(); - printf("\n------------------------------------------------------\n"); - testSearch(); - - return 0; -} \ No newline at end of file From 8b742ae73ceb728a85f9efa618c4278cbcd8b402 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 13:50:25 -0700 Subject: [PATCH 02/56] Added guard clauses for null fpointers --- list.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/list.c b/list.c index 8d5c025..c5e4df2 100644 --- a/list.c +++ b/list.c @@ -477,6 +477,10 @@ typedef void (*FREE_FN)(void* pItem); void List_free(List* pList, FREE_FN pItemFreeFn) { assert(pList!=NULL); + if(pItemFreeFn==NULL) + { + return; + } if(!pList->isAvailable) { @@ -530,6 +534,10 @@ typedef bool (*COMPARATOR_FN)(void* pItem, void* pComparisonArg); void* List_search(List* pList, COMPARATOR_FN pComparator, void* pComparisonArg) { assert(pList!=NULL); + if(pComparator==NULL) + { + return NULL; + } if(pList->numItems==0) { From cf7225bdc3eb48fba381bc4dc133ceafc89916bf Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 13:55:09 -0700 Subject: [PATCH 03/56] reset merge with master --- .vscode/launch.json | 29 ----------------------------- .vscode/settings.json | 6 ------ .vscode/tasks.json | 27 --------------------------- 3 files changed, 62 deletions(-) delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/settings.json delete mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index e3550a9..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "gcc-7 - Build and debug active file", - "type": "cppdbg", - "request": "launch", - "program": "${fileDirname}/${fileBasenameNoExtension}", - "args": [], - "stopAtEntry": false, - "cwd": "${fileDirname}", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ], - "preLaunchTask": "C/C++: gcc-7 build active file", - "miDebuggerPath": "/usr/bin/gdb" - } - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 7a8c31a..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "C_Cpp.errorSquiggles": "Enabled", - "files.associations": { - "list.h": "c" - } -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index c3d0bee..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "tasks": [ - { - "type": "cppbuild", - "label": "C/C++: gcc-7 build active file", - "command": "/usr/bin/gcc-7", - "args": [ - "-g", - "${workspaceFolder}/*.c", - "-o", - "${fileDirname}/${fileBasenameNoExtension}" - ], - "options": { - "cwd": "${fileDirname}" - }, - "problemMatcher": [ - "$gcc" - ], - "group": { - "kind": "build", - "isDefault": true - }, - "detail": "Task generated by Debugger." - } - ], - "version": "2.0.0" -} \ No newline at end of file From 44c5a8bc18b709e601c52b8b2159f0d4e82ca70a Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 13:59:13 -0700 Subject: [PATCH 04/56] Added related modules --- launcher.c | 0 readInput.c | 0 readInput.h | 0 receiveUDP.c | 0 receiveUDP.h | 0 sendUDP.c | 0 sendUDP.h | 0 writeOutput.c | 0 writeOutput.h | 0 9 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 launcher.c create mode 100644 readInput.c create mode 100644 readInput.h create mode 100644 receiveUDP.c create mode 100644 receiveUDP.h create mode 100644 sendUDP.c create mode 100644 sendUDP.h create mode 100644 writeOutput.c create mode 100644 writeOutput.h diff --git a/launcher.c b/launcher.c new file mode 100644 index 0000000..e69de29 diff --git a/readInput.c b/readInput.c new file mode 100644 index 0000000..e69de29 diff --git a/readInput.h b/readInput.h new file mode 100644 index 0000000..e69de29 diff --git a/receiveUDP.c b/receiveUDP.c new file mode 100644 index 0000000..e69de29 diff --git a/receiveUDP.h b/receiveUDP.h new file mode 100644 index 0000000..e69de29 diff --git a/sendUDP.c b/sendUDP.c new file mode 100644 index 0000000..e69de29 diff --git a/sendUDP.h b/sendUDP.h new file mode 100644 index 0000000..e69de29 diff --git a/writeOutput.c b/writeOutput.c new file mode 100644 index 0000000..e69de29 diff --git a/writeOutput.h b/writeOutput.h new file mode 100644 index 0000000..e69de29 From 00010e1fd4ece5ecd35ea10fcd206525b7029e6e Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 15:57:49 -0700 Subject: [PATCH 05/56] Added header guards to .h files --- readInput.h | 4 ++++ receiveUDP.h | 9 +++++++++ sendUDP.h | 4 ++++ writeOutput.h | 4 ++++ 4 files changed, 21 insertions(+) diff --git a/readInput.h b/readInput.h index e69de29..22a867f 100644 --- a/readInput.h +++ b/readInput.h @@ -0,0 +1,4 @@ +#ifndef _READ_INPUT_H +#define _READ_INPUT_H + +#endif \ No newline at end of file diff --git a/receiveUDP.h b/receiveUDP.h index e69de29..bfefc64 100644 --- a/receiveUDP.h +++ b/receiveUDP.h @@ -0,0 +1,9 @@ +#ifndef _RECEIVE_UDP_H +#define _RECEIVE_UDP_H + +#include "list.h" + +void receiverInit(char* hostname, char* port, List* list); +void receiverShutdown(); + +#endif \ No newline at end of file diff --git a/sendUDP.h b/sendUDP.h index e69de29..f62e485 100644 --- a/sendUDP.h +++ b/sendUDP.h @@ -0,0 +1,4 @@ +#ifndef _SEND_UDP_H +#define _SEND_UDP_H + +#endif \ No newline at end of file diff --git a/writeOutput.h b/writeOutput.h index e69de29..616e59a 100644 --- a/writeOutput.h +++ b/writeOutput.h @@ -0,0 +1,4 @@ +#ifndef _WRITE_OUTPUT_H +#define _WRITE_OUTPUT_H + +#endif \ No newline at end of file From a7b99265ae906f563781e79a99e832a98eea89d1 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 15:57:56 -0700 Subject: [PATCH 06/56] Implemented receiveUDP --- receiveUDP.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/receiveUDP.c b/receiveUDP.c index e69de29..474b522 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -0,0 +1,116 @@ +// Code is adapted (not copied) from Brian Fraser's Workshops and Beej's Guide to Network Programming examples +// IPv4 is exclusively used here + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "list.h" + +// Max size of the message, theoretical max size of a UDP packet in IPv4. +#define MAXBUFLEN 65508 + +// Preparing variables we'll use +static int sockfd; +static struct addrinfo hints, *servinfo, *p; +static int gaiVal; +static int bindVal; +static int numbytes; +char buf[MAXBUFLEN]; +static struct sockaddr_in their_addr; +static socklen_t addr_len; +static char s[INET_ADDRSTRLEN]; +char* message; + +void receiverInit(char* hostname, char* port, List* list) +{ + + // Setting up the hints addrinfo for the getaddrinfo function + memset(&hints, 0 ,sizeof (hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_flags = AI_PASSIVE; + + //Getting address information with getaddrinfo + //You can replace the IP address with your hostname, this is how we'll do things in the assignment + gaiVal = getaddrinfo(hostname, port, &hints, &servinfo); + + // Error checking for getaddrinfo + if (gaiVal != 0 ) + { + fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(gaiVal)); + return; + } + + // Initializing a socket and binding it to any port we find + // Doing a for loop because getaddrinfo generates a linked list of addrinfos + for(p = servinfo; p!=NULL; p=p->ai_next) + { + sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol); + + // Error checking for socket + if (sockfd ==-1) + { + perror("receiver: socket() error"); + continue; + } + + bindVal = bind(sockfd, p->ai_addr, p->ai_addrlen); + + // Error checking for bind + if(bindVal ==-1) + { + close(sockfd); + perror("receiver: bind() error in receiver"); + continue; + } + break; + } + + // Error checking if no sockets are binded + if(p==NULL) + { + fprintf(stderr, "receiver: failed to bind socket"); + return; + } + + // Freeing our results from getaddrinfo + freeaddrinfo(servinfo); + + while(1) + { + // Receiving + addr_len = sizeof(their_addr); + numbytes = recvfrom(sockfd, buf, MAXBUFLEN-1, 0, (struct sockaddr* ) &their_addr, &addr_len); + + // Error checking recvfrom + if(numbytes ==-1) + { + perror("receiver: recvfrom error"); + return; + } + + buf[numbytes]='\0'; + + // Copying buf to a smaller string to put to the list + // TODO: REMEMBER TO FREE THE LIST LATER! + message = (char*)malloc(sizeof(char)*(numbytes+1)); + strncpy(message, buf, numbytes); + message[numbytes] = '\0'; + + // Adding message to the list, using prepend to implement FIFO + List_prepend(list, message); + } + +} +void receiverShutdown() +{ + close(sockfd); +} \ No newline at end of file From 353c819811135f2e3b82855f31d20a7d95c7acba Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 16:02:06 -0700 Subject: [PATCH 07/56] updated gitignore to ignore launch and tasks --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8887b3e..a8fccc6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,7 @@ *.code-workspace # Local History for Visual Studio Code -.history/ \ No newline at end of file +.history/ +.vscode/launch.json +.gitignore +.vscode/tasks.json From a566a6e9f27f0ae9dea78b2754c92968bd320828 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 20:29:12 -0700 Subject: [PATCH 08/56] Implemented sendUDP --- sendUDP.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ sendUDP.h | 5 ++++ 2 files changed, 90 insertions(+) diff --git a/sendUDP.c b/sendUDP.c index e69de29..5d1a4fb 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -0,0 +1,85 @@ +// Code is adapted (not copied) from Brian Fraser's Workshops and Beej's Guide to Network Programming examples +// IPv4 is exclusively used here + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "list.h" + +// Preparing variables we'll use +static int sockfd; +static struct addrinfo hints, *servinfo, *p; +static int gaiVal; +static int numbytes; +static char* message; + +void senderInit(char* hostname, char* port, List* list) +{ + // Setting up the hints addrinfo for the getaddrinfo function + memset(&hints, 0 ,sizeof (hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_DGRAM; + + //Getting address information with getaddrinfo + gaiVal = getaddrinfo(hostname, port, &hints, &servinfo); + // Error checking for getaddrinfo + if (gaiVal != 0 ) + { + fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(gaiVal)); + return; + } + + // Initializing a socket and binding it to any port we find + // Doing a for loop because getaddrinfo generates a linked list of addrinfos + for(p = servinfo; p!=NULL; p=p->ai_next) + { + sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol); + + // Error checking for socket + if (sockfd ==-1) + { + perror("sender: socket() error"); + continue; + } + break; + } + // Error checking if no sockets are binded + if(p==NULL) + { + fprintf(stderr, "sender: failed to create socket"); + return; + } + + while(1) + { + // Getting message from list + message = (char *) List_trim(list); + + // Sending + numbytes = sendto(sockfd, message, strlen(message), 0, p->ai_addr, p->ai_addrlen); + + // Error checking recvfrom + if(numbytes ==-1) + { + perror("sender: sendto error"); + return; + } + + + } + + // Freeing our results from getaddrinfo + freeaddrinfo(servinfo); +} +void senderShutdown() +{ + close(sockfd); +} \ No newline at end of file diff --git a/sendUDP.h b/sendUDP.h index f62e485..4f600f7 100644 --- a/sendUDP.h +++ b/sendUDP.h @@ -1,4 +1,9 @@ #ifndef _SEND_UDP_H #define _SEND_UDP_H +#include "list.h" + +void senderInit(char* hostname, char* port, List* list); +void senderShutdown(); + #endif \ No newline at end of file From 13fd07e973cf97ef1acbd4a4393d4402b45d941d Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 20:34:42 -0700 Subject: [PATCH 09/56] Fixed comments --- receiveUDP.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/receiveUDP.c b/receiveUDP.c index 474b522..232659c 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -39,7 +39,6 @@ void receiverInit(char* hostname, char* port, List* list) hints.ai_flags = AI_PASSIVE; //Getting address information with getaddrinfo - //You can replace the IP address with your hostname, this is how we'll do things in the assignment gaiVal = getaddrinfo(hostname, port, &hints, &servinfo); // Error checking for getaddrinfo @@ -68,7 +67,7 @@ void receiverInit(char* hostname, char* port, List* list) if(bindVal ==-1) { close(sockfd); - perror("receiver: bind() error in receiver"); + perror("receiver: bind() error"); continue; } break; From 04cda22397fb33fda3f53537976bb7986ee94d8f Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 20:42:07 -0700 Subject: [PATCH 10/56] Added sendMessage function, freed message --- sendUDP.c | 11 +++++++++-- sendUDP.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/sendUDP.c b/sendUDP.c index 5d1a4fb..498ca3f 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -21,7 +21,7 @@ static int gaiVal; static int numbytes; static char* message; -void senderInit(char* hostname, char* port, List* list) +void sendMessage(char* hostname, char* port, List* list) { // Setting up the hints addrinfo for the getaddrinfo function memset(&hints, 0 ,sizeof (hints)); @@ -66,6 +66,9 @@ void senderInit(char* hostname, char* port, List* list) // Sending numbytes = sendto(sockfd, message, strlen(message), 0, p->ai_addr, p->ai_addrlen); + // De-allocating + free(message); + // Error checking recvfrom if(numbytes ==-1) { @@ -73,12 +76,16 @@ void senderInit(char* hostname, char* port, List* list) return; } - } // Freeing our results from getaddrinfo freeaddrinfo(servinfo); } + +void senderInit(char* hostname, char* port, List* list) +{ + sendMessage(hostname, port, list); +} void senderShutdown() { close(sockfd); diff --git a/sendUDP.h b/sendUDP.h index 4f600f7..a0e2090 100644 --- a/sendUDP.h +++ b/sendUDP.h @@ -3,6 +3,7 @@ #include "list.h" +void sendMessage(char* hostname, char* port, List* list); void senderInit(char* hostname, char* port, List* list); void senderShutdown(); From e9dec9eebfadc33946a2ff64f88e18ccb4eb76dc Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 20:42:21 -0700 Subject: [PATCH 11/56] Updated null guards for list --- list.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/list.c b/list.c index c5e4df2..1d8a4f7 100644 --- a/list.c +++ b/list.c @@ -477,10 +477,6 @@ typedef void (*FREE_FN)(void* pItem); void List_free(List* pList, FREE_FN pItemFreeFn) { assert(pList!=NULL); - if(pItemFreeFn==NULL) - { - return; - } if(!pList->isAvailable) { @@ -493,7 +489,10 @@ void List_free(List* pList, FREE_FN pItemFreeFn) Node* temp = pList->current; pList->current = pList->current->next; - (*pItemFreeFn)(temp->item); + if(pItemFreeFn!=NULL) + { + (*pItemFreeFn)(temp->item); + } pushNodeMem(temp); } From 0069d5d4c503f46b75ef26cf083fc9e4a54a7c10 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 20:46:26 -0700 Subject: [PATCH 12/56] Changed the sender helper function to static --- sendUDP.c | 4 ++-- sendUDP.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/sendUDP.c b/sendUDP.c index 498ca3f..1962e45 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -21,7 +21,7 @@ static int gaiVal; static int numbytes; static char* message; -void sendMessage(char* hostname, char* port, List* list) +static void senderLoop(char* hostname, char* port, List* list) { // Setting up the hints addrinfo for the getaddrinfo function memset(&hints, 0 ,sizeof (hints)); @@ -84,7 +84,7 @@ void sendMessage(char* hostname, char* port, List* list) void senderInit(char* hostname, char* port, List* list) { - sendMessage(hostname, port, list); + senderLoop(hostname, port, list); } void senderShutdown() { diff --git a/sendUDP.h b/sendUDP.h index a0e2090..4f600f7 100644 --- a/sendUDP.h +++ b/sendUDP.h @@ -3,7 +3,6 @@ #include "list.h" -void sendMessage(char* hostname, char* port, List* list); void senderInit(char* hostname, char* port, List* list); void senderShutdown(); From 172853bc9232b942a671d95b6984d25c7573a27a Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 20:46:42 -0700 Subject: [PATCH 13/56] Added helper function to decouple init fn --- receiveUDP.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/receiveUDP.c b/receiveUDP.c index 232659c..ad6d31a 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -29,9 +29,8 @@ static socklen_t addr_len; static char s[INET_ADDRSTRLEN]; char* message; -void receiverInit(char* hostname, char* port, List* list) +static void receiverLoop (char* hostname, char* port, List* list) { - // Setting up the hints addrinfo for the getaddrinfo function memset(&hints, 0 ,sizeof (hints)); hints.ai_family = AF_INET; @@ -107,7 +106,11 @@ void receiverInit(char* hostname, char* port, List* list) // Adding message to the list, using prepend to implement FIFO List_prepend(list, message); } +} +void receiverInit(char* hostname, char* port, List* list) +{ + receiverLoop(hostname, port, list); } void receiverShutdown() { From aec5cf7b7ea489a58897b4af8f20838f9051a46f Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 21:51:52 -0700 Subject: [PATCH 14/56] Initialized pthreads in sendUDP --- sendUDP.c | 52 +++++++++++++++++++++++++++++++++++++--------------- sendUDP.h | 2 +- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/sendUDP.c b/sendUDP.c index 1962e45..7ce884f 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -11,18 +11,25 @@ #include #include #include +#include #include "list.h" -// Preparing variables we'll use +//Preparing variables to use static int sockfd; -static struct addrinfo hints, *servinfo, *p; -static int gaiVal; -static int numbytes; -static char* message; +static struct addrinfo *servinfo; +static char* hostname; +static char* port; +static List* list; +static pthread_t senderThread; -static void senderLoop(char* hostname, char* port, List* list) +static void* senderLoop(void* unused) { + struct addrinfo hints, *p; + int gaiVal; + int bindVal; + int numbytes; + char* message; // Setting up the hints addrinfo for the getaddrinfo function memset(&hints, 0 ,sizeof (hints)); hints.ai_family = AF_INET; @@ -34,7 +41,7 @@ static void senderLoop(char* hostname, char* port, List* list) if (gaiVal != 0 ) { fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(gaiVal)); - return; + return NULL; } // Initializing a socket and binding it to any port we find @@ -55,7 +62,7 @@ static void senderLoop(char* hostname, char* port, List* list) if(p==NULL) { fprintf(stderr, "sender: failed to create socket"); - return; + return NULL; } while(1) @@ -73,20 +80,35 @@ static void senderLoop(char* hostname, char* port, List* list) if(numbytes ==-1) { perror("sender: sendto error"); - return; + return NULL; } - } - - // Freeing our results from getaddrinfo - freeaddrinfo(servinfo); + return NULL; } -void senderInit(char* hostname, char* port, List* list) +void senderInit(char* hostnm, char* p, List* l) { - senderLoop(hostname, port, list); + hostname=hostnm; + port = p; + list = l; + + int stval = pthread_create(&senderThread, NULL, senderLoop, NULL); + if(stval != 0) + { + perror("sender: thread creation error"); + exit(-1); + } + } void senderShutdown() { + + // Freeing our results from getaddrinfo + freeaddrinfo(servinfo); + + // closing connection to the socket close(sockfd); + + pthread_cancel(senderThread); + pthread_join(senderThread, NULL); } \ No newline at end of file diff --git a/sendUDP.h b/sendUDP.h index 4f600f7..8e7a8f5 100644 --- a/sendUDP.h +++ b/sendUDP.h @@ -3,7 +3,7 @@ #include "list.h" -void senderInit(char* hostname, char* port, List* list); +void senderInit(char* hostnm, char* p, List* l); void senderShutdown(); #endif \ No newline at end of file From 42c8fccdc02d5e2af56c592f50e5d0189f7e6513 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 22:03:04 -0700 Subject: [PATCH 15/56] changed a variable to camelcase --- sendUDP.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sendUDP.c b/sendUDP.c index 7ce884f..2977005 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -92,8 +92,8 @@ void senderInit(char* hostnm, char* p, List* l) port = p; list = l; - int stval = pthread_create(&senderThread, NULL, senderLoop, NULL); - if(stval != 0) + int stVal = pthread_create(&senderThread, NULL, senderLoop, NULL); + if(stVal != 0) { perror("sender: thread creation error"); exit(-1); From 7a1f4a0dc4217e78f99c9e93566dbd5697a7b5dc Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Sun, 27 Jun 2021 22:05:22 -0700 Subject: [PATCH 16/56] initialized threads for receiveUDP --- receiveUDP.c | 58 +++++++++++++++++++++++++++++++++++++--------------- receiveUDP.h | 2 +- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/receiveUDP.c b/receiveUDP.c index ad6d31a..975fa75 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "list.h" @@ -19,18 +20,26 @@ // Preparing variables we'll use static int sockfd; -static struct addrinfo hints, *servinfo, *p; -static int gaiVal; -static int bindVal; -static int numbytes; -char buf[MAXBUFLEN]; -static struct sockaddr_in their_addr; -static socklen_t addr_len; -static char s[INET_ADDRSTRLEN]; -char* message; - -static void receiverLoop (char* hostname, char* port, List* list) +static struct addrinfo *servinfo; +static char* message; +static char* hostname; +static char* port; +static List* list; +static pthread_t receiverThread; + +static void* receiverLoop (void* unused) { + // Preparing variables we'll use + int sockfd; + struct addrinfo hints, *servinfo, *p; + int gaiVal; + int bindVal; + int numbytes; + char buf[MAXBUFLEN]; + struct sockaddr_in their_addr; + socklen_t addr_len; + char s[INET_ADDRSTRLEN]; + // Setting up the hints addrinfo for the getaddrinfo function memset(&hints, 0 ,sizeof (hints)); hints.ai_family = AF_INET; @@ -44,7 +53,7 @@ static void receiverLoop (char* hostname, char* port, List* list) if (gaiVal != 0 ) { fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(gaiVal)); - return; + return NULL; } // Initializing a socket and binding it to any port we find @@ -76,7 +85,7 @@ static void receiverLoop (char* hostname, char* port, List* list) if(p==NULL) { fprintf(stderr, "receiver: failed to bind socket"); - return; + return NULL; } // Freeing our results from getaddrinfo @@ -92,7 +101,7 @@ static void receiverLoop (char* hostname, char* port, List* list) if(numbytes ==-1) { perror("receiver: recvfrom error"); - return; + return NULL; } buf[numbytes]='\0'; @@ -106,13 +115,30 @@ static void receiverLoop (char* hostname, char* port, List* list) // Adding message to the list, using prepend to implement FIFO List_prepend(list, message); } + return NULL; } -void receiverInit(char* hostname, char* port, List* list) +void receiverInit(char* hostnm, char* p, List* l) { - receiverLoop(hostname, port, list); + hostname = hostnm; + port = p; + list = l; + + int rectVal = pthread_create(&receiverThread, NULL, receiverLoop, NULL); + if(rectVal != 0) + { + perror("sender: thread creation error"); + exit(-1); + } } void receiverShutdown() { + // Freeing our results from getaddrinfo + freeaddrinfo(servinfo); + + // closing connection to the socket close(sockfd); + + pthread_cancel(receiverThread); + pthread_join(receiverThread, NULL); } \ No newline at end of file diff --git a/receiveUDP.h b/receiveUDP.h index bfefc64..ec9406b 100644 --- a/receiveUDP.h +++ b/receiveUDP.h @@ -3,7 +3,7 @@ #include "list.h" -void receiverInit(char* hostname, char* port, List* list); +void receiverInit(char* hostnm, char* p, List* l); void receiverShutdown(); #endif \ No newline at end of file From bf1ac3f70a3edf996677f3f34319f6af1c014461 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Tue, 29 Jun 2021 00:33:20 -0700 Subject: [PATCH 17/56] Changed message to be local --- receiveUDP.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/receiveUDP.c b/receiveUDP.c index 975fa75..c180df8 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -21,7 +21,6 @@ // Preparing variables we'll use static int sockfd; static struct addrinfo *servinfo; -static char* message; static char* hostname; static char* port; static List* list; @@ -36,6 +35,7 @@ static void* receiverLoop (void* unused) int bindVal; int numbytes; char buf[MAXBUFLEN]; + char* message; struct sockaddr_in their_addr; socklen_t addr_len; char s[INET_ADDRSTRLEN]; From 586274317c6802c22c0e06310677ae0b21980f13 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Tue, 29 Jun 2021 00:33:54 -0700 Subject: [PATCH 18/56] deleted syeda's socket play directory --- Syeda's socket play/.DS_Store | Bin 6148 -> 0 bytes Syeda's socket play/.vscode/launch.json | 29 --------- Syeda's socket play/.vscode/settings.json | 5 -- Syeda's socket play/.vscode/tasks.json | 27 -------- Syeda's socket play/demoClient.c | 17 ----- Syeda's socket play/demoServer.c | 60 ------------------ Syeda's socket play/demoSocket.c | 73 ---------------------- Syeda's socket play/socketB1 | Bin 8672 -> 0 bytes Syeda's socket play/socketBrian | Bin 12760 -> 0 bytes Syeda's socket play/socketBrian.c | 67 -------------------- 10 files changed, 278 deletions(-) delete mode 100644 Syeda's socket play/.DS_Store delete mode 100644 Syeda's socket play/.vscode/launch.json delete mode 100644 Syeda's socket play/.vscode/settings.json delete mode 100644 Syeda's socket play/.vscode/tasks.json delete mode 100644 Syeda's socket play/demoClient.c delete mode 100644 Syeda's socket play/demoServer.c delete mode 100644 Syeda's socket play/demoSocket.c delete mode 100755 Syeda's socket play/socketB1 delete mode 100755 Syeda's socket play/socketBrian delete mode 100644 Syeda's socket play/socketBrian.c diff --git a/Syeda's socket play/.DS_Store b/Syeda's socket play/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 -#include -#include - -int main(int arg, char* arg[]){ - - - int myServerSock; - struct sockaddr_in server; - char buffer[1024] - - - - return 0; -} \ No newline at end of file diff --git a/Syeda's socket play/demoServer.c b/Syeda's socket play/demoServer.c deleted file mode 100644 index ed37410..0000000 --- a/Syeda's socket play/demoServer.c +++ /dev/null @@ -1,60 +0,0 @@ -// server demo - -#include -#include // textbook -#include //textbook -#include -#include -#include -#include -#include - -int main(int argCount,char* args[]){ - - - #define MESSAGE "Hello World Testing Socket" - - // variables// - int mySock; - struct sockaddr_in server; - struct hostent *hp; - char buffer[1024]; - - //creating socket// - mySock = socket(AF_INET, SOCK_DGRAM, 0); - if(mySock < 0 ){ - perror("socket failed"); - close(mySock); - exit(1); - } - - server.sin_family = AF_INET; - hp = gethostbyname (argv[1]); - if(hp == 0){ - perror("getting host name failed"); - close(mySock); - exit(1); - } - - memcpy(&server.sin_addr, hp->h_addr, hp->h_length); - server.sin_port = htons(5000); - - - if(connect(mySock, (struct sockaaddr *)&server, sizeof(server))<0){ - perror("connection failed"); - close(mySock); - exit(1); - } - - if(send(mySock,MESSAGE, sizeof(MESSAGE),0)<0){ - perror("Sending faild"); - close(mySock); - exit(1); - } - printf("Sent %s\n", MESSAGE); - close(mySock); - - - - return 0; -} \ No newline at end of file diff --git a/Syeda's socket play/demoSocket.c b/Syeda's socket play/demoSocket.c deleted file mode 100644 index 4109f12..0000000 --- a/Syeda's socket play/demoSocket.c +++ /dev/null @@ -1,73 +0,0 @@ -// demo -// following youtube demo "C Programming in Linux Tutorial #034 - Socket Programming" -// ^^ cite it : https://www.youtube.com/watch?v=pFLQkmnmD0o&list=PLypxmOPCOkHXbJhUgjRaV2pD9MJkIArhg&index=34 - -#include -#include // textbook -#include //textbook -#include -#include -#include - -#define PORT 22110 - -int main(int argCount,char* args[]){ - // variables// - - // brian no have// - int mysocket; // s in tutoial // sock in vid - char buffer[1024]; - int myAcceptingSocket; - int rval; - - //brian had// - struct sockaddr_in server; - - //creating socket// - mysocket = socket(AF_INET, SOCK_DGRAM, 0); //AF-> allows communication - - // brian had// - server.sin_family = AF_INET; - server.sin_addr.s_addr = htonl(INADDR_ANY); - server.sin_port = htons(PORT); - memset(&server,0, sizeof(server)); - - //binding socket// - - if(bind(mysocket, (struct sockaddr* )&server, sizeof(server)) ){ - perror("this bind faild"); - exit(1); - } - - - //listening// - - listen(mysocket,5); - - - //accept// - do{ - myAcceptingSocket = accept(mysocket, (struct sockaddr *)0,0); - if(myAcceptingSocket == -1){ - perror("could not accept, failed attempt"); - } - else{ - memset(buffer, 0, sizeof(buffer)); - if(rval == recv(myAcceptingSocket, buffer, sizeof(buffer),0) < 0 ){ - perror("reading the message failed"); - } - else if(rval==0){ - printf("ending connection"); - } - else{ - printf("Message is: %s\n", buffer); - - } - printf("We recieved the message: (rval = %d\n)", rval); - close(myAcceptingSocket); - } - } - while(1); - - return 0; -} \ No newline at end of file diff --git a/Syeda's socket play/socketB1 b/Syeda's socket play/socketB1 deleted file mode 100755 index 54f0967ec87162182be4fd3256ae33e39410bfa1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8672 zcmeHM-)kII6uz5A-Nv@Nc~ELw!)+i^E9OV3RD+cybZ|lwTbrba553);oz1T9?u4D0 znmhy|B07YH{1HC*P%sZsLMdenC0hk6_|%6y#1bV73dIL0MO?o#dnY?PslEw5+!M~6 z^PPL{nLFQ|S#IwA;qh;OJ;PXRA7e`$jIjjt>Qjt;$~Zj6UV!RQAuf)-t-Y^ZxmMl4z{34&>8V=|vG@xCj2#%I`0 zIbWKU3DJ6&WWAJZCmfcx+Gr5MEq#8fh zlRfp~a(qEO!qIxcoKj683aNh^UsBdPAqPM>To2zEBMn3d!zvc7QVX~9HzMop5`@Hn zE9&EO8+3+keWw%S@0{1pjR)TtkIVxw$(AfYCS0qRv86#u;EWMBaoEGKfpFgZJ;+H* z?*_H61Mi2OKh9VV_F3pfXjq63(lD>#cJg)fKM)N9<1?fo`E3KPT^=ap(*v1>LIyFC zqfi>h*T2WM?^Vy%zFL~jO@5HLeF`xSjX~L=E?>#_=cbc&oP-amcLnpeM0MzQBP=wg z*P+x#&m4Qajp>N7-LYUiQwz3Z7W>EgF|K?XNsyPIRDYE>`FvSo;!BBQKrx^gPz)#r z6a$KZ|AK)T-TPVplaU3-PwTM(0=NuY1{Bvwx&I}d}WSe{wi`G$OLb9r%7uS{;~ z-aWtX&S!r3zFv9ld)#N}+nRQVYWiu~-5a#99rvmemB~9hv>^6wdz00V7poLcRA?o+ ztW`bjdY#r}>kTa32*5}Dx?VXrkD{J-Q#WRAZgh6DWw(ka`U1_m_Z=SQIe4D-Wqq;H zXsk5)jv%|ycg(-`_*d>_E?o#`LM-w^N1bg`mo+o@TT zmrWyo&CGDyH4KEZZlSQi(+k5$f^kfHn0IyYJ{wC|8t5@7N!Zd%(7N?BEGhl3Nmx#{KN2zX3;hsLL6ugN7GK0 z&z;VB0c2^mB28n85jLhbZQRId2-SW8#cFMYriGvR>M`U>&J^iJfU~ zhm5(|EZW}O$F`1Q@1n{nfdtSO>XC>wPwr?xQf~O*w_E)f7<)1;*`KCPU9f`w#QX9vK@?I`PkvIUy{+^H|p-F#0d_Z}N N?11Jy6Np>0zX9DAe(wMP diff --git a/Syeda's socket play/socketBrian b/Syeda's socket play/socketBrian deleted file mode 100755 index dbfb2b623193343d32e12f8f466dae3b714e5919..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12760 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=`|>dG0LE>=F+OKV{mJ*^rYZdNO@VKp0?$o>e|rl2 zC~%6?d4IhGyi_}!0zS<(Tkv@xw-Oz1O@k+%Pk3592b|jZDYaWPl>uI9m29_B$aphGDohd|IAR6~0Z+u*!po7!XCwqPD5U^^H^ zOf-UmXmt_9{YA$hz|6kv05l`X0o;sAj3@h3%t!kA(&l!S@DZHJJX)!6#`ttRtynPC z(2<8st%_mlT)B{LVY(awO{Hwl>uRQYp)z=$&lzq3Q)tiYZ>9@aQBkLT7x0hq?u^Sn zpctkcKh9HRax7QGMxeA5W&6X5VY*pWn3m7PvOP}1WWr}6^7}%z=XF2RrWrWDnBD<@;C zexJ&;(0&$lobC5DVALiQA0^(uFvW_ZC^`E-hulJY-sj|Lku^Qz?Zou!4trg#3z%}e z?1p8g-*(vZx`OG4+_1_4m&^XX)5r3bHp6ie~iC{3>tfE&-(=a4x7KX=JCmP+>f-cp(?Wdu38^VQ`Sr6ZfXiVAY{&9hFobdWx>^?ol%ekEFr5t*{RouGZ+75pzu1A3E+wWH3wW8K zF4w5?oqpMlb!z}PG0KZ8`*EIllz~%s&J^~8G}$2C;V^KB;>s!Pf2t;)Lkqywfhxc_B#Y>l-J1BWR78+W*L_W%F@ diff --git a/Syeda's socket play/socketBrian.c b/Syeda's socket play/socketBrian.c deleted file mode 100644 index 640e762..0000000 --- a/Syeda's socket play/socketBrian.c +++ /dev/null @@ -1,67 +0,0 @@ -//sockett - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define PORT 22110 -#define MAX_LENGTH 1024 -char messageBuffer[MAX_LENGTH]; // buffer to store the message data - -int main(int argCount,char* args[]){ - - printf("Hello!\n"); - printf("to connect do: netcat -u 127.0.0.1 %d\n", PORT); - - - - // setting up socket -- brian had // - struct sockaddr_in server; - memset(&server,0, sizeof(server)); // clear the socket - server.sin_family = AF_INET; - server.sin_addr.s_addr = htonl(INADDR_ANY); // in address any, willing to work on any local port, - //dont care about port sending to - server.sin_port = htons(PORT); // port to connect to - - - // creating socket// - int mysocket = socket(PF_INET, SOCK_DGRAM, 0); - //before was AF instead PF -- domain = AF-> allows communication and binding so it can talk to another port - // type = DGRAM -> connectionless socket,for UDP, no need to maintain open connection - - // binding socket // - int bindval= bind(mysocket, (struct sockaddr *)&server, sizeof(server)); - - - while(1){ - - // recieve data// - struct sockaddr_in messageFrom; // lets us know who we got message from, brian had sinRemote - unsigned int messageLen = sizeof(messageFrom); // the length - int bytesOfMesssage = recvfrom(mysocket, messageBuffer, MAX_LENGTH, 0, (struct sockaddr *)&messageFrom,&messageLen); // main function to recieve - - int interminateNull = (bytesOfMesssage < MAX_LENGTH) ? bytesOfMesssage : MAX_LENGTH -1; - messageBuffer[interminateNull] = 0; - printf("message recived successfully by: %d bytes: \n\n %s\n", bytesOfMesssage,messageBuffer); - if(messageBuffer == NULL){ - printf("repeat--> %s\n", messageBuffer); - } - - - } - - - //close socket// - - close(mysocket); - - -} - From e476496eb8fba35cd4db640b8fc971e366a8c011 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Tue, 29 Jun 2021 00:41:21 -0700 Subject: [PATCH 19/56] Deleted useless files --- assn1 | Bin 38020 -> 0 bytes assn1.dSYM/Contents/Info.plist | 20 -------------------- assn1.dSYM/Contents/Resources/DWARF/assn1 | Bin 24671 -> 0 bytes list.o | Bin 9004 -> 0 bytes read.o | Bin 1984 -> 0 bytes write.o | Bin 1516 -> 0 bytes 6 files changed, 20 deletions(-) delete mode 100755 assn1 delete mode 100644 assn1.dSYM/Contents/Info.plist delete mode 100644 assn1.dSYM/Contents/Resources/DWARF/assn1 delete mode 100644 list.o delete mode 100644 read.o delete mode 100644 write.o diff --git a/assn1 b/assn1 deleted file mode 100755 index df069caf9bf34446d45c46e1226cdb9b0b29e2b6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 38020 zcmeHwdw85xwfCF0ff6VQNU_T81q!xEn@b6lOC*I3Or?cFTSU3!I&A`J5;93?m3jh` z@#`>*MlFciqd|&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G3(FvAHc;$G|LzEVs_d7fGE8QW*C%Mee(TlU6!o zCo_JU(pq2DfS&|A74^~3%DSpHq-3qHqPeNrZwKhUanSvCS{DjhBRs3aGsD#k@6zo5 He@y=mZYk}u diff --git a/assn1.dSYM/Contents/Info.plist b/assn1.dSYM/Contents/Info.plist deleted file mode 100644 index c12d12e..0000000 --- a/assn1.dSYM/Contents/Info.plist +++ /dev/null @@ -1,20 +0,0 @@ - - - - - CFBundleDevelopmentRegion - English - CFBundleIdentifier - com.apple.xcode.dsym.assn1 - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - dSYM - CFBundleSignature - ???? - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1 - - diff --git a/assn1.dSYM/Contents/Resources/DWARF/assn1 b/assn1.dSYM/Contents/Resources/DWARF/assn1 deleted file mode 100644 index 040c3508ea5c939d7d005eea86220fc922d04155..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 24671 zcmeHv3wT_`b^pD)n)OOry`PqCEE|K(OAi|x#g-rPTMru}n?=SZYgt+$Q9U-&%CW&< z*QNvlNhKh>>KNLlB&4Px`TVsmxCu=lIGBVar3ix4(8RnF3NFwz>7U2{_d7GQdsmVv zNk6`}Uv=%#&Y5%O%sFSyyw087r~l($-k;<+uHSK-45T2^DHPae3Nocgi|3vdyT58_ z!@~z|e0%G*e}8?hDR)Vjjhak&d`P5savf(jK4STf^FD|sBfl0Y64_9JeU}%0`3a^Bf2xkxi>wHl<>vek`@jLJAq1SQd%IqdVgkJCkwa?q!;v*v3$K^$i++0fW>0BAwChShOEyqxsD-{Av;{YTGBk zG4izy#QVE?uT1bywcj?w?-H+o31*{sqdXEB?EQ3CZ+oPxx1&$sRDOq1Nd4I7_MvZ_ z?qR>)hzgO&%DPQ;9xC*w*a`kL-b24-vV9YY^ma!EcJ*xU>yE_Y{io$eKerF-+lThI zyjT{AT-oPwlQH~)Mn122qxsSA>=TJ}w|rG{U*t$w+~(!>F(-{lHzpy)}B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Js|xU3aw z-?CcfMejc5@-PxsRmj(hZ&3Ke59;!*2j5e|C;m{Ek7q6Rfu2|VqAnkQuzFbd#6Rlt z{S$npeOjLQNnO5^vF_a;YCiFox_m3Z*ZgnICw^0x?*{PM)0$8Gr!F5~mL=g6KdQ_3 zEAXxQNXrv{s>}B#_;v`N_*GrLgW%iqv6d(PRhMruVng(R<`X}w%hwLR#{XzO@wd8s zS@4YtpZHx}zDL2g^uJo3od3FfyTG?Y_{0zE^6dlPo=>#AcX1|EsdJv^Bc^WuRP%{n z)s=TC_#PI%+4M_+FIG9cy!*h{D173tfq8!qe@4h%_`Kk+1)miBiQuikIk*ZJ#0g~@&Ao+eS_=sQA75Zm5 zgrxI-NQfT@J^@tYrG39(L9j(*{A?hmjPqAhh>XK_EDKBMMEkhyf}?_6f(gNxpd~nk zK^#{S+%7mO*d>?{j0swTQ5F6RH&-$VaA^qD+n zT-qjYc~;scPuV7Ilb4K2+vFkl8GbQTKiinE>vU95Uc|@wOy2ebwn3jfn^en6fEFPg z=ZK|I+9nUZ5`CnbypTV&u-yezMfgo~4JxFM;@q(y#;A6Q4HW)Q5a}jQT!ucjOgv@b4L-vh$4L(H?d4>$1C}$;FY~F#lGBUk;D*7gH>A=X zY1W5_dfi6fP}@jva(F14PPu(xw$sU!%j`C)nB6|LFnNnPeFJ^jzU2D8+tQ+ey!J%b dOgfo0lpa3mbice6b;CRst7N4NA0C>P^?z{KOU3{I diff --git a/read.o b/read.o deleted file mode 100644 index a1a873d8b129f5bc36466db82e663f31c7ce0ef4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1984 zcmbVNT}V@57=CBwPwKX)=!ZsLbkRiv?Jh`CQaHr~35B|l&(k*DaGPU0BMlac869M_ zOK-aArYHit=%y$%r6TC}CW9`D47@PdrG&Yj_v}6G$GpfF-aX&*{-1Nc@7udyKR0TL z96Ja<&}!)2D*QAN3RlgBQp7tjs;FWofXF&Q8(Avx5mC|OL#3iFLbJ5l- z056a0E#du1-Lest3Wn5RLXQRu36;;gCiSvXZ%*n7r3Rvqy=FWCJpi@RoV$ovA>5Sh zIn2S|B8Ls}9*BJEfwG{qr93C^nR@8|N}p!_&?Z*h7@&1d%RF*ZKCewTaT#s8UNgJb zH1la4jONS7-}6K(mdB23vzR$W2$&ULF?qUgO*{F)oLbLs{^~oFO%z9BZp?%&H-d7E3|ZN zc6}|UU!=s6Ho4f+zu-DT+#kKu>)f$_AraIA%|^(AK|LG^26!UKo%{FrQ*B$GJe)nX zo#d;9B-vHP3gfa&Z{aU&C?eMu{=Jg#xN@Exqi%=0v9>OYE=OTM3|;x1w?z6AbvWJE ztIjmp_Y%i-LfbbAaWcn0<06QgkvN%WQ(O))P9iUVAnbk5Hz4-9_cIXt+w&2KUFm%z z{ue-;6z_b&zwZGMJHmS#h{y2U1Y%atD6kH8zA~``+q!``E8f#Uh^G}ln8~{z$o_U9 z@@tv}0T$=?<-}n2{rF6HmJccfJ;+&&J0Hm`49r8qkAquxq3}b($AK&tq4r(Ld=@I9 zOs#vOl;5iG^YBu!TlBdbpWB>pF diff --git a/write.o b/write.o deleted file mode 100644 index dfa81335c471389a55d69b923d0bcd11ee30eafa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1516 zcmb7EQA-q26h3RFR^|>-V3BkmB8u1ti+YHJmfVt=)k$(J?DPsn{#*0&ZnQ>x7vwP z`v?oX6+YC0MZsam;a~XRAEuZKn-jDIp-Jrf`4Fac=+1@7K8Xvtp~7}-cAsU#dfdwb zmQK#K(maDPtw$>r69BdD&la-V3DbwQog%)YvE5hFx>yMV&%ZAOt#|fk`nn_8y=T+9VB9h@k2S!FYW+f33v~Pdb$l~V-7p_$?q2}|F;d= z(O0|n&9bBFrv0Rk>+8I{=7#L({mObnGSP>qx>2icG}4cF5bVXiXMmV&*WOvfYw1(? zWkpZ*zKK@zi`*4dARW#8u%p2`s*=>leDpT1jdJU?>N=$#is)pMs2W}~dQtTkYb0$g zUb+j`3g0)@=xx|ht{!co50vDBU@B0auVw=;bkCksSJa^IjFwy#P9-_sREmM?`V@0i zI1#wcm>PGyk~>BPx61iYGeA-Ly!S*RBi+;e_Z&QlNWP-@OfS)J`2 zOJJQw{v>>4s}Y+#pD5d9J#M*vxJ~Mqho7AmglGEs8?OZ3OW{dBd-PVp=^)Cy0%ER? zJqO}hnWqw0f%u+e0wCJ#(LlV1o-B}gSAkr22FN;mKTJU;4TSYv!-BdtB?yRP Date: Tue, 29 Jun 2021 00:41:32 -0700 Subject: [PATCH 20/56] added rule to gitignore to ignore .o files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a8fccc6..f26a4c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*.o + .vscode/* !.vscode/settings.json !.vscode/tasks.json From f665454454e1cd78d2ca67f35486eb2384ad690a Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Tue, 29 Jun 2021 01:13:16 -0700 Subject: [PATCH 21/56] Added exit codes for critical errors --- receiveUDP.c | 10 ++++------ sendUDP.c | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/receiveUDP.c b/receiveUDP.c index c180df8..83452d1 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -53,7 +53,7 @@ static void* receiverLoop (void* unused) if (gaiVal != 0 ) { fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(gaiVal)); - return NULL; + exit(-1); } // Initializing a socket and binding it to any port we find @@ -85,7 +85,7 @@ static void* receiverLoop (void* unused) if(p==NULL) { fprintf(stderr, "receiver: failed to bind socket"); - return NULL; + exit(-1); } // Freeing our results from getaddrinfo @@ -95,17 +95,15 @@ static void* receiverLoop (void* unused) { // Receiving addr_len = sizeof(their_addr); - numbytes = recvfrom(sockfd, buf, MAXBUFLEN-1, 0, (struct sockaddr* ) &their_addr, &addr_len); + numbytes = recvfrom(sockfd, buf, MAXBUFLEN, 0, (struct sockaddr* ) &their_addr, &addr_len); // Error checking recvfrom if(numbytes ==-1) { perror("receiver: recvfrom error"); - return NULL; + exit(-1); } - buf[numbytes]='\0'; - // Copying buf to a smaller string to put to the list // TODO: REMEMBER TO FREE THE LIST LATER! message = (char*)malloc(sizeof(char)*(numbytes+1)); diff --git a/sendUDP.c b/sendUDP.c index 2977005..ab927b4 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -41,7 +41,7 @@ static void* senderLoop(void* unused) if (gaiVal != 0 ) { fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(gaiVal)); - return NULL; + exit(-1); } // Initializing a socket and binding it to any port we find @@ -62,7 +62,7 @@ static void* senderLoop(void* unused) if(p==NULL) { fprintf(stderr, "sender: failed to create socket"); - return NULL; + exit(-1); } while(1) @@ -80,7 +80,7 @@ static void* senderLoop(void* unused) if(numbytes ==-1) { perror("sender: sendto error"); - return NULL; + exit(-1); } } return NULL; From 3340bd006fad64461c16f906dd02745c116b5b7e Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Tue, 29 Jun 2021 01:45:51 -0700 Subject: [PATCH 22/56] Adapted Syeda's read & write, deleted mutexes --- readInput.c | 126 +++++++++++++++----------------------------------- writeOutput.c | 120 ++++++++++++++--------------------------------- 2 files changed, 72 insertions(+), 174 deletions(-) diff --git a/readInput.c b/readInput.c index bb5b0ba..56aa89c 100644 --- a/readInput.c +++ b/readInput.c @@ -1,111 +1,59 @@ -// using part of Darrn's check + addrino info since its more accurate - - - +// reads off keyboard and adds to list #include #include -#include -#include #include -#include -#include -#include -#include -#include - +#include #include "list.h" -// Max size of the message, theoretical max size of a UDP packet in IPv4. #define MAXBUFLEN 65508 -// variable set up -static int sockRead; -static struct addrinfo hints, *servinfo, *p; -static int gaiVal; -static int bindVal; -static int readBytes; -char buf[MAXBUFLEN]; -static struct sockaddr_in their_addr; -static socklen_t messageLen; -static char s[INET_ADDRSTRLEN]; -char* message; - -void receiverInit(char* hostname, char* port, List* list) -{ - - //set up - memset(&hints, 0 ,sizeof (hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_DGRAM; - hints.ai_flags = AI_PASSIVE; +static List* list; +static pthread_t readerThread; - //using Darren's non hard coded values - gaiVal = getaddrinfo(hostname, port, &hints, &servinfo); - - // Error checking for getaddrinfo - if (gaiVal != 0 ) +static void* readTask(void* useless){ + while(1) { - fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(gaiVal)); - return; - } + // Declaring variables + char* message; + char bufStorageOfMessage[MAXBUFLEN]; - //crating socket + checks - for(p = servinfo; p!=NULL; p=p->ai_next) - { - sockRead = socket(p->ai_family, p->ai_socktype, p->ai_protocol); - // Error checking for socket - if (sockRead ==-1) + // Reading user input + int numbytes = read(0,bufStorageOfMessage, MAXBUFLEN); + if(numbytes==-1) { - perror("receiver: socket() error"); - continue; + perror("reader: read() failed"); + exit(-1); } + // Downsizing the size of the message to be more space efficient + message = (char*)malloc(sizeof(char)*(numbytes)); + strncpy(message, bufStorageOfMessage, numbytes); + // Note: we don't need null terminator here because we're going to send the result, not print it + // Our receiver will add the null terminator for us - // binding socket - bindVal = bind(sockRead, p->ai_addr, p->ai_addrlen); - // Error checking for bind - if(bindVal ==-1) - { - close(sockRead); - perror("receiver: bind() error in receiver"); - continue; - } - break; - } - - // Error checking if no sockets are binded - if(p==NULL) - { - fprintf(stderr, "receiver: failed to bind socket"); - return; + // TODO: CREATE A MUTEX FOR ENQUEUEING AND DEQUEUEING + // TODO: CREATE A COND VAR SUCH THAT AFTER READ, IMMEDIATELY SEND + // Adding the message to the list + List_prepend(list, message); } + return NULL; +} - // Freeing our results from getaddrinfo - freeaddrinfo(servinfo); - - while(1) - { - // Receiving - messageLen = sizeof(their_addr); - readBytes = read(sockRead,buf , MAXBUFLEN ); - // first arg -> reads from file describtor, sockRead - // second arg -> starts from the buff - // third arg -> end the read at this value, max amount allowed - - buf[readBytes]='\0'; // not sure what this does - // adding buff to list, - message = (char*)malloc(sizeof(char)*(readBytes+1)); // allocates space for new item - strncpy(message, buf, readBytes); - message[readBytes] = '\0'; //not sure what this does +void readerInit(List* l){ + list = l; - // Adding message to the front of list - List_prepend(list, message); + int readingThread = pthread_create(&readerThread, NULL, readTask, NULL); + if(readingThread !=0){//if gave error code of not 0 (0 is success) + perror("reader: thread creation error"); + exit(-1); } - + } -void receiverShutdown() + +void readerShutdown() { - close(sockRead); -} \ No newline at end of file + pthread_cancel(readerThread); + pthread_join(readerThread,NULL); +} diff --git a/writeOutput.c b/writeOutput.c index 07cea6c..b51e494 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -1,106 +1,56 @@ -// using part of Darrn's check + addrino info since its more accurate - +// take list message and write to screen #include #include -#include -#include #include -#include -#include -#include -#include -#include - +#include #include "list.h" - -// Max size of the message, theoretical max size of a UDP packet in IPv4. #define MAXBUFLEN 65508 -// variable set up -static int sockRead; -static struct addrinfo hints, *servinfo, *p; -static int gaiVal; -static int bindVal; -static int readBytes; -char buf[MAXBUFLEN]; -static struct sockaddr_in their_addr; -static socklen_t messageLen; -static char s[INET_ADDRSTRLEN]; -char* message; - -void receiverInit(char* hostname, char* port, List* list) -{ - - //set up - memset(&hints, 0 ,sizeof (hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_DGRAM; - hints.ai_flags = AI_PASSIVE; +static pthread_t writerThread; +static List* list; - //using Darren's non hard coded values - gaiVal = getaddrinfo(hostname, port, &hints, &servinfo); +static void* writeLoop(void* useless){ - // Error checking for getaddrinfo - if (gaiVal != 0 ) - { - fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(gaiVal)); - return; - } - - //crating socket + checks - for(p = servinfo; p!=NULL; p=p->ai_next) + while(1) { - sockRead = socket(p->ai_family, p->ai_socktype, p->ai_protocol); - // Error checking for socket - if (sockRead ==-1) - { - perror("receiver: socket() error"); - continue; - } - - - // binding socket - bindVal = bind(sockRead, p->ai_addr, p->ai_addrlen); - // Error checking for bind - if(bindVal ==-1) - { - close(sockRead); - perror("receiver: bind() error in receiver"); - continue; + // Declaring variables + char* message; + + // TODO: CREATE A MUTEX FOR ENQUEUEING AND DEQUEUEING + // TODO: CREATE A COND VAR SUCH THAT AFTER SEND, IMMEDIATELY WRITE + // Taking message from list + message = List_trim(list); + + int writeVar = write(1,List_trim(list), strlen(message)); // will put the message from first list onto screen + if(writeVar == -1){ + perror("Error in write() : Unable to write to screen"); + exit(-1); } - break; - } - // Error checking if no sockets are binded - if(p==NULL) - { - fprintf(stderr, "receiver: failed to bind socket"); - return; + // Freeing message (message is dynamically allocated from receiver) + free(message); } + return NULL; + +} - // Freeing our results from getaddrinfo - freeaddrinfo(servinfo); - while(1) - { - // Receiving - messageLen = sizeof(their_addr); - write(sockRead, buf, MAXBUFLEN); - - buf[readBytes]='\0'; // not sure what this does +void writerInit(List* l){ - // adding buff to list, - message = (char*)malloc(sizeof(char)*(readBytes+1)); // allocates space for new item - strncpy(message, buf, readBytes); - message[readBytes] = '\0'; //not sure what this does + list = l; - // Adding message to the front of list - List_prepend(list, message); + int writingThread = pthread_create(&writerThread, NULL, writeLoop, NULL); + if(writingThread != 0){ + perror("write thread failed"); + exit(-1); } } -void receiverShutdown() + +void writerShutdown() { - close(sockRead); -} \ No newline at end of file + pthread_cancel(writerThread); + pthread_join(writerThread, NULL); +} + From 423e295e51fffa08f049c73acbd3ffa6df936b7b Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Tue, 29 Jun 2021 01:46:13 -0700 Subject: [PATCH 23/56] Added comments, defined read & write headers --- readInput.h | 8 ++++++++ receiveUDP.h | 4 ++++ sendUDP.h | 4 ++++ writeOutput.h | 8 ++++++++ 4 files changed, 24 insertions(+) diff --git a/readInput.h b/readInput.h index 22a867f..c467c71 100644 --- a/readInput.h +++ b/readInput.h @@ -1,4 +1,12 @@ #ifndef _READ_INPUT_H #define _READ_INPUT_H +#include "list.h" + +// Reads input from the keyboard +// Starts a new pthread + +void readerInit(List* l); +void readerShutdown(); + #endif \ No newline at end of file diff --git a/receiveUDP.h b/receiveUDP.h index ec9406b..953d0b3 100644 --- a/receiveUDP.h +++ b/receiveUDP.h @@ -3,6 +3,10 @@ #include "list.h" +// Receives a string through connectionless UDP +// IPv4 is exclusively used +// Starts a new pthread + void receiverInit(char* hostnm, char* p, List* l); void receiverShutdown(); diff --git a/sendUDP.h b/sendUDP.h index 8e7a8f5..3992f76 100644 --- a/sendUDP.h +++ b/sendUDP.h @@ -3,6 +3,10 @@ #include "list.h" +// Sends a string through connectionless UDP +// IPv4 is exclusively used +// Starts a new pthread + void senderInit(char* hostnm, char* p, List* l); void senderShutdown(); diff --git a/writeOutput.h b/writeOutput.h index 616e59a..17f579c 100644 --- a/writeOutput.h +++ b/writeOutput.h @@ -1,4 +1,12 @@ #ifndef _WRITE_OUTPUT_H #define _WRITE_OUTPUT_H +#include "list.h" + +// Writer module, will print to the screen +// Starts a new pthread + +void writerInit(List* l); +void writerShutdown(); + #endif \ No newline at end of file From 95bf05e0115c3ad2751d443aa41e1acef18d62f6 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Tue, 29 Jun 2021 14:14:21 -0700 Subject: [PATCH 24/56] Added include to header files --- readInput.c | 4 +++- receiveUDP.c | 1 + sendUDP.c | 1 + writeOutput.c | 4 +++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/readInput.c b/readInput.c index 56aa89c..261d8e5 100644 --- a/readInput.c +++ b/readInput.c @@ -3,8 +3,10 @@ #include #include #include -#include +#include + #include "list.h" +#include "readInput.h" #define MAXBUFLEN 65508 diff --git a/receiveUDP.c b/receiveUDP.c index 83452d1..c4ea2ba 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -14,6 +14,7 @@ #include #include "list.h" +#include "receiveUDP.h" // Max size of the message, theoretical max size of a UDP packet in IPv4. #define MAXBUFLEN 65508 diff --git a/sendUDP.c b/sendUDP.c index ab927b4..6971720 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -14,6 +14,7 @@ #include #include "list.h" +#include "sendUDP.h" //Preparing variables to use static int sockfd; diff --git a/writeOutput.c b/writeOutput.c index b51e494..e85bf14 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -3,8 +3,10 @@ #include #include #include -#include +#include + #include "list.h" +#include "writeOutput.h" #define MAXBUFLEN 65508 static pthread_t writerThread; From 3f0d0ff61ca072cfe044855c21e98d0cdb80f0b5 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Tue, 29 Jun 2021 14:26:05 -0700 Subject: [PATCH 25/56] Implemented module to manage queue crit section --- queueOperations.c | 37 +++++++++++++++++++++++++++++++++++++ queueOperations.h | 12 ++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 queueOperations.c create mode 100644 queueOperations.h diff --git a/queueOperations.c b/queueOperations.c new file mode 100644 index 0000000..b90e5ff --- /dev/null +++ b/queueOperations.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +#include"queueOperations.h" +#include"list.h" + +static pthread_mutex_t queueMutex = PTHREAD_MUTEX_INITIALIZER; + +void enqueueMessage(List* list, char* message) +{ + pthread_mutex_lock(&queueMutex); + { + int prepVal = List_prepend(list, message); + if(prepVal==-1) + { + fprintf(stderr, "Enqueue failed, queue full"); + } + } + pthread_mutex_unlock(&queueMutex); +} +char* dequeueMessage(List* list) +{ + char* message; + pthread_mutex_lock(&queueMutex); + { + message = List_trim(list); + if(message == NULL) + { + fprintf(stderr, "Dequeue failed, queue empty"); + } + } + pthread_mutex_unlock(&queueMutex); + + return message; +} \ No newline at end of file diff --git a/queueOperations.h b/queueOperations.h new file mode 100644 index 0000000..9a58286 --- /dev/null +++ b/queueOperations.h @@ -0,0 +1,12 @@ +#ifndef _QUEUE_OPERATIONS_H +#define _QUEUE_OPERATIONS_H + +#include "list.h"; + +// Manages the shared queue operations +// Creates mutexes for both operations + +void enqueueMessage(List* list, char* message); +char* dequeueMessage(List* list); + +#endif \ No newline at end of file From 0f0e55936c9d7932e60ca76f2f5707742c630b4c Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Tue, 29 Jun 2021 14:32:07 -0700 Subject: [PATCH 26/56] Added safer deallocation for message --- sendUDP.c | 10 ++++++++-- writeOutput.c | 15 +++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/sendUDP.c b/sendUDP.c index 6971720..56bc412 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -23,6 +23,7 @@ static char* hostname; static char* port; static List* list; static pthread_t senderThread; +static char* message; static void* senderLoop(void* unused) { @@ -30,7 +31,6 @@ static void* senderLoop(void* unused) int gaiVal; int bindVal; int numbytes; - char* message; // Setting up the hints addrinfo for the getaddrinfo function memset(&hints, 0 ,sizeof (hints)); hints.ai_family = AF_INET; @@ -74,8 +74,9 @@ static void* senderLoop(void* unused) // Sending numbytes = sendto(sockfd, message, strlen(message), 0, p->ai_addr, p->ai_addrlen); - // De-allocating + // De-allocating message free(message); + message = NULL; // Error checking recvfrom if(numbytes ==-1) @@ -103,6 +104,11 @@ void senderInit(char* hostnm, char* p, List* l) } void senderShutdown() { + // De-allocating dynamically allocated message if shutdown is called while message is not yet freed + if(message!=NULL) + { + free(message); + } // Freeing our results from getaddrinfo freeaddrinfo(servinfo); diff --git a/writeOutput.c b/writeOutput.c index e85bf14..3a3da08 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -6,23 +6,22 @@ #include #include "list.h" +#include "queueOperations.h" #include "writeOutput.h" #define MAXBUFLEN 65508 static pthread_t writerThread; static List* list; +static char* message; static void* writeLoop(void* useless){ while(1) { - // Declaring variables - char* message; - // TODO: CREATE A MUTEX FOR ENQUEUEING AND DEQUEUEING // TODO: CREATE A COND VAR SUCH THAT AFTER SEND, IMMEDIATELY WRITE // Taking message from list - message = List_trim(list); + message = dequeueMessage(list); int writeVar = write(1,List_trim(list), strlen(message)); // will put the message from first list onto screen if(writeVar == -1){ @@ -32,6 +31,7 @@ static void* writeLoop(void* useless){ // Freeing message (message is dynamically allocated from receiver) free(message); + message = NULL; } return NULL; @@ -52,6 +52,13 @@ void writerInit(List* l){ void writerShutdown() { + // De-allocating dynamically allocated message if shutdown is called while message is not yet freed + if(message != NULL) + { + free(message); + message=NULL; + } + pthread_cancel(writerThread); pthread_join(writerThread, NULL); } From bf5bdbd1d4271b0dd5a109e918ccd552804b6ff9 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Tue, 29 Jun 2021 14:47:15 -0700 Subject: [PATCH 27/56] Modified modules to use the thread safe queueOps --- readInput.c | 4 ++-- receiveUDP.c | 5 +++-- sendUDP.c | 10 +++++----- writeOutput.c | 10 ++++------ 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/readInput.c b/readInput.c index 261d8e5..91ff7b1 100644 --- a/readInput.c +++ b/readInput.c @@ -6,6 +6,7 @@ #include #include "list.h" +#include "queueOperations.h" #include "readInput.h" #define MAXBUFLEN 65508 @@ -34,10 +35,9 @@ static void* readTask(void* useless){ // Note: we don't need null terminator here because we're going to send the result, not print it // Our receiver will add the null terminator for us - // TODO: CREATE A MUTEX FOR ENQUEUEING AND DEQUEUEING // TODO: CREATE A COND VAR SUCH THAT AFTER READ, IMMEDIATELY SEND // Adding the message to the list - List_prepend(list, message); + enqueueMessage(list, message); } return NULL; } diff --git a/receiveUDP.c b/receiveUDP.c index c4ea2ba..1448829 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -14,6 +14,7 @@ #include #include "list.h" +#include "queueOperations.h" #include "receiveUDP.h" // Max size of the message, theoretical max size of a UDP packet in IPv4. @@ -111,8 +112,8 @@ static void* receiverLoop (void* unused) strncpy(message, buf, numbytes); message[numbytes] = '\0'; - // Adding message to the list, using prepend to implement FIFO - List_prepend(list, message); + // Adding message to the list + enqueueMessage(list, message); } return NULL; } diff --git a/sendUDP.c b/sendUDP.c index 56bc412..5a593ce 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -14,6 +14,7 @@ #include #include "list.h" +#include "queueOperations.h" #include "sendUDP.h" //Preparing variables to use @@ -69,7 +70,7 @@ static void* senderLoop(void* unused) while(1) { // Getting message from list - message = (char *) List_trim(list); + message = dequeueMessage(list); // Sending numbytes = sendto(sockfd, message, strlen(message), 0, p->ai_addr, p->ai_addrlen); @@ -105,10 +106,9 @@ void senderInit(char* hostnm, char* p, List* l) void senderShutdown() { // De-allocating dynamically allocated message if shutdown is called while message is not yet freed - if(message!=NULL) - { - free(message); - } + // Note: if we HAVE already freed the pointer, then we've set the message pointer to NULL + // and it is okay to free a NULL pointer (it does nothing) + free(message); // Freeing our results from getaddrinfo freeaddrinfo(servinfo); diff --git a/writeOutput.c b/writeOutput.c index 3a3da08..54a8903 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -53,12 +53,10 @@ void writerInit(List* l){ void writerShutdown() { // De-allocating dynamically allocated message if shutdown is called while message is not yet freed - if(message != NULL) - { - free(message); - message=NULL; - } - + // Note: if we HAVE already freed the pointer, then we've set the message pointer to NULL + // and it is okay to free a NULL pointer (it does nothing) + free(message); + pthread_cancel(writerThread); pthread_join(writerThread, NULL); } From b18b3d5883e597a74697387fdfea762b839ace8c Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Tue, 29 Jun 2021 15:04:37 -0700 Subject: [PATCH 28/56] Added condition var to synchronize write-recv --- receiveUDP.c | 4 ++++ writeOutput.c | 18 ++++++++++++++++++ writeOutput.h | 1 + 3 files changed, 23 insertions(+) diff --git a/receiveUDP.c b/receiveUDP.c index 1448829..e6a52f7 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -15,6 +15,7 @@ #include "list.h" #include "queueOperations.h" +#include "writeOutput.h" #include "receiveUDP.h" // Max size of the message, theoretical max size of a UDP packet in IPv4. @@ -114,6 +115,9 @@ static void* receiverLoop (void* unused) // Adding message to the list enqueueMessage(list, message); + + // Signals writer to write message to screen + writerSignaller(); } return NULL; } diff --git a/writeOutput.c b/writeOutput.c index 54a8903..fd1ddf1 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -11,6 +11,8 @@ #define MAXBUFLEN 65508 static pthread_t writerThread; +static pthread_mutex_t writeAvailableCondMutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t writeAvailableCond = PTHREAD_COND_INITIALIZER; static List* list; static char* message; @@ -18,6 +20,12 @@ static void* writeLoop(void* useless){ while(1) { + // Waits the write funtion, will be signalled by receiveUDP + pthread_mutex_lock(&writeAvailableCondMutex); + { + pthread_cond_wait(&writeAvailableCond, &writeAvailableCondMutex); + } + pthread_mutex_unlock(&writeAvailableCondMutex); // TODO: CREATE A COND VAR SUCH THAT AFTER SEND, IMMEDIATELY WRITE // Taking message from list @@ -37,6 +45,16 @@ static void* writeLoop(void* useless){ } +void writerSignaller() +{ + //Signals the writer, will be called by receiveUDP + pthread_mutex_lock(&writeAvailableCondMutex); + { + pthread_cond_signal(&writeAvailableCond); + } + pthread_mutex_unlock(&writeAvailableCondMutex); +} + void writerInit(List* l){ diff --git a/writeOutput.h b/writeOutput.h index 17f579c..1626995 100644 --- a/writeOutput.h +++ b/writeOutput.h @@ -6,6 +6,7 @@ // Writer module, will print to the screen // Starts a new pthread +void writerSignaller(); void writerInit(List* l); void writerShutdown(); From 8ee67777e5f8f864bcd926770537cd786ffaf27c Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Tue, 29 Jun 2021 20:05:43 -0700 Subject: [PATCH 29/56] Changed recv to only track the listening port --- receiveUDP.c | 13 ++++++------- receiveUDP.h | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/receiveUDP.c b/receiveUDP.c index e6a52f7..41d9c9c 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -24,8 +24,7 @@ // Preparing variables we'll use static int sockfd; static struct addrinfo *servinfo; -static char* hostname; -static char* port; +static char* myPort; static List* list; static pthread_t receiverThread; @@ -49,8 +48,9 @@ static void* receiverLoop (void* unused) hints.ai_socktype = SOCK_DGRAM; hints.ai_flags = AI_PASSIVE; - //Getting address information with getaddrinfo - gaiVal = getaddrinfo(hostname, port, &hints, &servinfo); + // Getting address information with getaddrinfo + // Listening on our machine, on myPort + gaiVal = getaddrinfo(NULL, myPort, &hints, &servinfo); // Error checking for getaddrinfo if (gaiVal != 0 ) @@ -122,10 +122,9 @@ static void* receiverLoop (void* unused) return NULL; } -void receiverInit(char* hostnm, char* p, List* l) +void receiverInit(char* myP, List* l) { - hostname = hostnm; - port = p; + myPort = myP; list = l; int rectVal = pthread_create(&receiverThread, NULL, receiverLoop, NULL); diff --git a/receiveUDP.h b/receiveUDP.h index 953d0b3..55da65c 100644 --- a/receiveUDP.h +++ b/receiveUDP.h @@ -7,7 +7,7 @@ // IPv4 is exclusively used // Starts a new pthread -void receiverInit(char* hostnm, char* p, List* l); +void receiverInit(char* myP, List* l); void receiverShutdown(); #endif \ No newline at end of file From 6344b57a590961d980d8abf16173140d6dab386c Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Tue, 29 Jun 2021 20:05:52 -0700 Subject: [PATCH 30/56] renamed variables to be more concise --- sendUDP.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sendUDP.c b/sendUDP.c index 5a593ce..68ad041 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -20,8 +20,8 @@ //Preparing variables to use static int sockfd; static struct addrinfo *servinfo; -static char* hostname; -static char* port; +static char* theirHostname; +static char* theirPort; static List* list; static pthread_t senderThread; static char* message; @@ -37,8 +37,9 @@ static void* senderLoop(void* unused) hints.ai_family = AF_INET; hints.ai_socktype = SOCK_DGRAM; - //Getting address information with getaddrinfo - gaiVal = getaddrinfo(hostname, port, &hints, &servinfo); + // Getting address information with getaddrinfo + // Sending to theirHostname, on theirPort + gaiVal = getaddrinfo(theirHostname, theirPort, &hints, &servinfo); // Error checking for getaddrinfo if (gaiVal != 0 ) { @@ -91,8 +92,8 @@ static void* senderLoop(void* unused) void senderInit(char* hostnm, char* p, List* l) { - hostname=hostnm; - port = p; + theirHostname=hostnm; + theirPort = p; list = l; int stVal = pthread_create(&senderThread, NULL, senderLoop, NULL); From a4ff73e85d8c049c5d37e50548581ceca2e226da Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Tue, 29 Jun 2021 20:08:23 -0700 Subject: [PATCH 31/56] Implemented main function --- launcher.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/launcher.c b/launcher.c index e69de29..4526abd 100644 --- a/launcher.c +++ b/launcher.c @@ -0,0 +1,39 @@ +#include +#include +#include + +#include "list.h" +#include "readInput.h" +#include "writeOutput.h" +#include "receiveUDP.h" +#include "sendUDP.h" + +// Launches the s-talk program +int main (int argc, char * argv[]) +{ + // Checks if arguments are correct + if (argc!=4) + { + printf("Please enter valid arguments \n"); + printf("Valid argument strucure is: \n"); + printf("s-talk [my port number] [remote machine name] [remote port number]"); + return -1; + } + + // Storing arguments + char* myPort = argv[2]; + char* theirHostname = argv[3]; + char* theirPort = argv[4]; + + // Creates a shared list + List* list = List_create(); + + // Initializes the four modules + readerInit(list); + senderInit(theirHostname, theirPort, list); + receiverInit(myPort, list); + writerInit(list); + + // TODO: Implement stop signal + +} \ No newline at end of file From 65590eb934ab40d40ac36870814ca6ac7f105111 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Wed, 30 Jun 2021 01:06:20 -0700 Subject: [PATCH 32/56] Added exit code mechanism --- launcher.c | 12 +++++++++++- readInput.c | 14 ++++++++------ receiveUDP.c | 7 +++++-- sendUDP.c | 10 +++++++++- writeOutput.c | 9 ++++++++- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/launcher.c b/launcher.c index 4526abd..68beebe 100644 --- a/launcher.c +++ b/launcher.c @@ -29,11 +29,21 @@ int main (int argc, char * argv[]) List* list = List_create(); // Initializes the four modules + // Modules are running in an infinite loop, they will exit when given the exit code "!" readerInit(list); senderInit(theirHostname, theirPort, list); receiverInit(myPort, list); writerInit(list); - // TODO: Implement stop signal + // Cleans up the threads + readerShutdown(); + senderShutdown(); + receiverShutdown(); + writerShutdown(); + // Frees the list + // At this point, the list should already be empty + List_free(list, free); + + return 0; } \ No newline at end of file diff --git a/readInput.c b/readInput.c index 91ff7b1..95fdf38 100644 --- a/readInput.c +++ b/readInput.c @@ -30,14 +30,18 @@ static void* readTask(void* useless){ } // Downsizing the size of the message to be more space efficient - message = (char*)malloc(sizeof(char)*(numbytes)); + message = (char*)malloc(sizeof(char)*(numbytes+1)); strncpy(message, bufStorageOfMessage, numbytes); - // Note: we don't need null terminator here because we're going to send the result, not print it - // Our receiver will add the null terminator for us + message[numbytes] = '\0'; - // TODO: CREATE A COND VAR SUCH THAT AFTER READ, IMMEDIATELY SEND // Adding the message to the list enqueueMessage(list, message); + + // Checking for exit code + if (!strcmp(message,"!")) + { + return NULL; + } } return NULL; } @@ -51,11 +55,9 @@ void readerInit(List* l){ perror("reader: thread creation error"); exit(-1); } - } void readerShutdown() { - pthread_cancel(readerThread); pthread_join(readerThread,NULL); } diff --git a/receiveUDP.c b/receiveUDP.c index 41d9c9c..3a0d6ba 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -108,7 +108,6 @@ static void* receiverLoop (void* unused) } // Copying buf to a smaller string to put to the list - // TODO: REMEMBER TO FREE THE LIST LATER! message = (char*)malloc(sizeof(char)*(numbytes+1)); strncpy(message, buf, numbytes); message[numbytes] = '\0'; @@ -118,6 +117,11 @@ static void* receiverLoop (void* unused) // Signals writer to write message to screen writerSignaller(); + + if(!strcmp(message, "!")) + { + return; + } } return NULL; } @@ -142,6 +146,5 @@ void receiverShutdown() // closing connection to the socket close(sockfd); - pthread_cancel(receiverThread); pthread_join(receiverThread, NULL); } \ No newline at end of file diff --git a/sendUDP.c b/sendUDP.c index 68ad041..ead191c 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -75,6 +75,14 @@ static void* senderLoop(void* unused) // Sending numbytes = sendto(sockfd, message, strlen(message), 0, p->ai_addr, p->ai_addrlen); + + // Check for exit code + if(!strcmp(message,"!")) + { + free(message); + message = NULL; + return NULL; + } // De-allocating message free(message); @@ -110,6 +118,7 @@ void senderShutdown() // Note: if we HAVE already freed the pointer, then we've set the message pointer to NULL // and it is okay to free a NULL pointer (it does nothing) free(message); + message=NULL; // Freeing our results from getaddrinfo freeaddrinfo(servinfo); @@ -117,6 +126,5 @@ void senderShutdown() // closing connection to the socket close(sockfd); - pthread_cancel(senderThread); pthread_join(senderThread, NULL); } \ No newline at end of file diff --git a/writeOutput.c b/writeOutput.c index fd1ddf1..cbada0e 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -37,6 +37,14 @@ static void* writeLoop(void* useless){ exit(-1); } + // Checking for exit code + if(!strcmp(message, "!")) + { + free(message); + message = NULL; + return NULL; + } + // Freeing message (message is dynamically allocated from receiver) free(message); message = NULL; @@ -75,7 +83,6 @@ void writerShutdown() // and it is okay to free a NULL pointer (it does nothing) free(message); - pthread_cancel(writerThread); pthread_join(writerThread, NULL); } From c100e47a5c6336954c20d76b277dde10cf2dcab7 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Wed, 30 Jun 2021 01:28:54 -0700 Subject: [PATCH 33/56] Deleted todo comment --- writeOutput.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/writeOutput.c b/writeOutput.c index cbada0e..0389c22 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -26,8 +26,7 @@ static void* writeLoop(void* useless){ pthread_cond_wait(&writeAvailableCond, &writeAvailableCondMutex); } pthread_mutex_unlock(&writeAvailableCondMutex); - - // TODO: CREATE A COND VAR SUCH THAT AFTER SEND, IMMEDIATELY WRITE + // Taking message from list message = dequeueMessage(list); From d657e7d934a6c6b1551558ff9dbaf4c99f52aa3f Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Wed, 30 Jun 2021 15:52:23 -0700 Subject: [PATCH 34/56] modified gitignore to ignore s-talk executable --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f26a4c1..1f86a6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.o +s-talk .vscode/* !.vscode/settings.json From 997f99051b80661fe09fa9f6b3f2503541fd205c Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Wed, 30 Jun 2021 16:03:24 -0700 Subject: [PATCH 35/56] Fixed makefile error --- Makefile | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 827f0e7..f74c806 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,15 @@ CFLAGS = -Wall -Werror -all: - build +all: build build: gcc $(CFLAGS) launcher.c readInput.c writeOutput.c sendUDP.c receiveUDP.c queueOperations.c -pthread -o s-talk -run: - build +run: build ./s-talk -valgrind: - build +valgrind: build valgrind --leak-check=full ./s-talk From b964d1410115d54a39d0ba21669044bd481f65b6 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Wed, 30 Jun 2021 16:03:55 -0700 Subject: [PATCH 36/56] Added missing includes --- readInput.c | 4 +++- writeOutput.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/readInput.c b/readInput.c index 487f547..8ebd182 100644 --- a/readInput.c +++ b/readInput.c @@ -4,10 +4,12 @@ #include #include #include +#include #include "list.h" #include "queueOperations.h" #include "readInput.h" +#include "sendUDP.h" #define MAXBUFLEN 65508 @@ -39,7 +41,7 @@ static void* readLoop(void* useless){ enqueueMessage(list, message); //send signal for the senderUDP - sendSignaller(); + senderSignaller(); // Checking for exit code if (!strcmp(message,"!")) diff --git a/writeOutput.c b/writeOutput.c index 0389c22..eb24dd8 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "list.h" #include "queueOperations.h" From 4d5003b21c5ef851af707223fa5beddc2a930897 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Wed, 30 Jun 2021 16:04:18 -0700 Subject: [PATCH 37/56] Fixed syntax errors --- queueOperations.h | 2 +- receiveUDP.c | 3 +-- sendUDP.c | 5 ++--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/queueOperations.h b/queueOperations.h index 9a58286..bc04152 100644 --- a/queueOperations.h +++ b/queueOperations.h @@ -1,7 +1,7 @@ #ifndef _QUEUE_OPERATIONS_H #define _QUEUE_OPERATIONS_H -#include "list.h"; +#include "list.h" // Manages the shared queue operations // Creates mutexes for both operations diff --git a/receiveUDP.c b/receiveUDP.c index 3a0d6ba..0da45ed 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -40,7 +40,6 @@ static void* receiverLoop (void* unused) char* message; struct sockaddr_in their_addr; socklen_t addr_len; - char s[INET_ADDRSTRLEN]; // Setting up the hints addrinfo for the getaddrinfo function memset(&hints, 0 ,sizeof (hints)); @@ -120,7 +119,7 @@ static void* receiverLoop (void* unused) if(!strcmp(message, "!")) { - return; + return NULL; } } return NULL; diff --git a/sendUDP.c b/sendUDP.c index a72df85..e0d6735 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -34,7 +34,6 @@ static void* senderLoop(void* unused) { struct addrinfo hints, *p; int gaiVal; - int bindVal; int numbytes; // Setting up the hints addrinfo for the getaddrinfo function memset(&hints, 0 ,sizeof (hints)); @@ -75,11 +74,11 @@ static void* senderLoop(void* unused) while(1) { //Waits until notified by the sendSignaller = pthread_cond_wait - pthread_cond_lock(&sendAvailableCond); + pthread_mutex_lock(&sendAvailableCondMutex); { pthread_cond_wait(&sendAvailableCond, &sendAvailableCondMutex); } - pthread_cond_unlock(&sendAvailableCond); + pthread_mutex_lock(&sendAvailableCondMutex); // Getting message from list message = dequeueMessage(list); From 9f214c6bbb4082e1c8ce4d958c6e03407d571d65 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Wed, 30 Jun 2021 16:19:22 -0700 Subject: [PATCH 38/56] Added parentheses to get rid of warning --- list.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/list.c b/list.c index 1d8a4f7..f595d28 100644 --- a/list.c +++ b/list.c @@ -217,7 +217,7 @@ void* List_next(List* pList) return NULL; } - if(pList->current==pList->tail || pList->current==NULL && pList->oob==LIST_OOB_END) + if(pList->current==pList->tail || (pList->current==NULL && pList->oob==LIST_OOB_END)) { pList->oob = LIST_OOB_END; pList->current = NULL; @@ -246,7 +246,7 @@ void* List_prev(List* pList) return NULL; } - if(pList->current == pList->head || pList->current==NULL && pList->oob==LIST_OOB_START) + if(pList->current == pList->head || (pList->current==NULL && pList->oob==LIST_OOB_START)) { pList->oob = LIST_OOB_START; pList->current = NULL; From ec8c6374176e0a36f8caa7d1a461e2859177e0cc Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Wed, 30 Jun 2021 16:19:52 -0700 Subject: [PATCH 39/56] renamed sendSignaller to senderSignaller --- sendUDP.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sendUDP.c b/sendUDP.c index e0d6735..ff6e16b 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -73,7 +73,7 @@ static void* senderLoop(void* unused) while(1) { - //Waits until notified by the sendSignaller = pthread_cond_wait + //Waits until notified by the senderSignaller = pthread_cond_wait pthread_mutex_lock(&sendAvailableCondMutex); { pthread_cond_wait(&sendAvailableCond, &sendAvailableCondMutex); @@ -109,7 +109,7 @@ static void* senderLoop(void* unused) return NULL; } -void sendSignaller(){ +void senderSignaller(){ //Signals other thread,send thread, waiting on condition variable pthread_mutex_lock(&sendAvailableCondMutex); From 65ad9dd042ced25e64e48789f42276351899d5fc Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Wed, 30 Jun 2021 16:20:22 -0700 Subject: [PATCH 40/56] Added missing list.c dependency --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f74c806..24c7878 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ -CFLAGS = -Wall -Werror +CFLAGS = -Wall -Werror all: build build: - gcc $(CFLAGS) launcher.c readInput.c writeOutput.c sendUDP.c receiveUDP.c queueOperations.c -pthread -o s-talk + gcc $(CFLAGS) launcher.c readInput.c writeOutput.c sendUDP.c receiveUDP.c queueOperations.c list.c -o s-talk -lpthread run: build ./s-talk From c6809439707223a8ab96a7f2e04250fbd58b73d2 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Wed, 30 Jun 2021 16:21:52 -0700 Subject: [PATCH 41/56] Added endline --- launcher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher.c b/launcher.c index 68beebe..c04e390 100644 --- a/launcher.c +++ b/launcher.c @@ -16,7 +16,7 @@ int main (int argc, char * argv[]) { printf("Please enter valid arguments \n"); printf("Valid argument strucure is: \n"); - printf("s-talk [my port number] [remote machine name] [remote port number]"); + printf("s-talk [my port number] [remote machine name] [remote port number]\n"); return -1; } From b26a1aa2a55dfcc4cdceba52217b140d126d335f Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Wed, 30 Jun 2021 16:24:05 -0700 Subject: [PATCH 42/56] Added descriptive error messages --- receiveUDP.c | 2 +- sendUDP.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/receiveUDP.c b/receiveUDP.c index 0da45ed..012b968 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -54,7 +54,7 @@ static void* receiverLoop (void* unused) // Error checking for getaddrinfo if (gaiVal != 0 ) { - fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(gaiVal)); + fprintf(stderr, "receiver: getaddrinfo error: %s\n", gai_strerror(gaiVal)); exit(-1); } diff --git a/sendUDP.c b/sendUDP.c index ff6e16b..27cbf7c 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -46,7 +46,7 @@ static void* senderLoop(void* unused) // Error checking for getaddrinfo if (gaiVal != 0 ) { - fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(gaiVal)); + fprintf(stderr, "sender: getaddrinfo error: %s\n", gai_strerror(gaiVal)); exit(-1); } From 5858f0820f5e887ed2c35e41976528a7f2483407 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Wed, 30 Jun 2021 17:31:48 -0700 Subject: [PATCH 43/56] removed read.c and write.c --- read.c | 66 ------------------------------------------------------ write.c | 69 --------------------------------------------------------- 2 files changed, 135 deletions(-) delete mode 100755 read.c delete mode 100644 write.c diff --git a/read.c b/read.c deleted file mode 100755 index f23eede..0000000 --- a/read.c +++ /dev/null @@ -1,66 +0,0 @@ -//screen, -//reads off keyboard and adds to list - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "list.h" -#define MAXBUFLEN 65508 - -static List* list; - -static pthread_t readThread; -static pthread_cond_t ready = PTHREAD_COND_INITIALIZER; -static pthread_mutex_t readyMutex = PTHREAD_MUTEX_INITIALIZER; - - -void readTask(void* useless){ - //read gets called // done - //adds message to list // done - //notify sendUDP that read is ready // done - - - - char bufStorageOfMessage[MAXBUFLEN]; - // bufStorageOfMessage = '\0'; - read(0,bufStorageOfMessage, MAXBUFLEN -1); - List_perpend(list, bufStorageOfMessage); -} - - -void readInit(char* hostname, char* port, List* list){ - - //first read gets called and added to list - int readingThread = pthread_create(&readThread, NULL, readTask, NULL); - if(readingThread <= 0){//if gave error of -1 or 0 for false - perror("read thread failed"); - } - - //signaling sendUPD - //wrapping the signal in locks - pthread_mutex_lock(&readyMutex); // acquire a lock on the mutex - { - //signal// - pthread_cond_signal(&ready); - } - pthread_mutex_unlock(&readyMutex); // unlocks the mutex - - -} - - - -int main(int argCount,char* args[]){ - - - -} diff --git a/write.c b/write.c deleted file mode 100644 index 3359635..0000000 --- a/write.c +++ /dev/null @@ -1,69 +0,0 @@ -//keyboard, -// take list message and write to screen - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "list.h" -#define MAXBUFLEN 65508 - -static List* list; - -//brians vid on synchronozayion -static pthread_t writeThread; -static pthread_cond_t readyW = PTHREAD_COND_INITIALIZER; -static pthread_mutex_t readyWMutex = PTHREAD_MUTEX_INITIALIZER; - - -void writeTask(void* useless){ - - int writeVar = write(1,List_trim(list), MAXBUFLEN ); // will put the message from first list onto screen - if(writeVar == -1){ - perror("Error in write() : Unable to write to screen"); - - } -} - - -void writeInit(char* hostname, char* port, List* list){ - - //before write gets called needs to wait// - //wait until signalled// - pthread_mutex_lock(&readyWMutex); // acquire a lock on the mutex - { - //signal// - pthread_cond_wait(&readyW,&readyWMutex);// mutex will release while - } - pthread_mutex_unlock(&readyWMutex); // unlocks the mutex - - - //the condition it needs to check for if it was called from reciever - //if so then proceed to do the write - - - int writingThread = pthread_create(&writeThread, NULL, writeTask, NULL); - if(writingThread != 0){ - perror("Error: write thread failed"); - } - - //once done// - pthread_join(writingThread, NULL); - -} - - - -int main(int argCount,char* args[]){ - - write(1,"Test", 4); // this works! - -} From 626f320d012a14b1169a6ad78c51a916c13853b3 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Wed, 30 Jun 2021 17:32:43 -0700 Subject: [PATCH 44/56] Fixed argv variable storing --- launcher.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/launcher.c b/launcher.c index c04e390..158238f 100644 --- a/launcher.c +++ b/launcher.c @@ -21,9 +21,9 @@ int main (int argc, char * argv[]) } // Storing arguments - char* myPort = argv[2]; - char* theirHostname = argv[3]; - char* theirPort = argv[4]; + char* myPort = argv[1]; + char* theirHostname = argv[2]; + char* theirPort = argv[3]; // Creates a shared list List* list = List_create(); From 57a587f0fe7458c2010db1b3fc90bc1fbf3886a4 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Wed, 30 Jun 2021 17:52:55 -0700 Subject: [PATCH 45/56] Fixed typo bug --- sendUDP.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendUDP.c b/sendUDP.c index 27cbf7c..ea29249 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -78,7 +78,7 @@ static void* senderLoop(void* unused) { pthread_cond_wait(&sendAvailableCond, &sendAvailableCondMutex); } - pthread_mutex_lock(&sendAvailableCondMutex); + pthread_mutex_unlock(&sendAvailableCondMutex); // Getting message from list message = dequeueMessage(list); From 1638ff18a8089d5ccc3b5a15253d4f9484393466 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Wed, 30 Jun 2021 17:53:11 -0700 Subject: [PATCH 46/56] Fixed bug --- writeOutput.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/writeOutput.c b/writeOutput.c index eb24dd8..13f1641 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -31,7 +31,7 @@ static void* writeLoop(void* useless){ // Taking message from list message = dequeueMessage(list); - int writeVar = write(1,List_trim(list), strlen(message)); // will put the message from first list onto screen + int writeVar = write(1,message, strlen(message)); // will put the message from first list onto screen if(writeVar == -1){ perror("Error in write() : Unable to write to screen"); exit(-1); From fdecf63e067e92364697e2c1489bfedc3f0459fd Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Thu, 1 Jul 2021 01:45:32 -0700 Subject: [PATCH 47/56] Fixed shutdown method --- readInput.c | 11 +++++++++-- readInput.h | 1 + receiveUDP.c | 9 ++++++++- receiveUDP.h | 1 + sendUDP.c | 8 ++++++-- sendUDP.h | 1 + threadCanceller.c | 16 ++++++++++++++++ threadCanceller.h | 7 +++++++ writeOutput.c | 8 +++++++- writeOutput.h | 1 + 10 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 threadCanceller.c create mode 100644 threadCanceller.h diff --git a/readInput.c b/readInput.c index 8ebd182..b11c017 100644 --- a/readInput.c +++ b/readInput.c @@ -10,6 +10,7 @@ #include "queueOperations.h" #include "readInput.h" #include "sendUDP.h" +#include "threadCanceller.h" #define MAXBUFLEN 65508 @@ -41,11 +42,12 @@ static void* readLoop(void* useless){ enqueueMessage(list, message); //send signal for the senderUDP - senderSignaller(); + senderSignaller(); // Checking for exit code - if (!strcmp(message,"!")) + if (!strcmp(message,"!\n")) { + cancelReceiverWriter(); return NULL; } @@ -65,6 +67,11 @@ void readerInit(List* l){ } +void readerCancel() +{ + pthread_cancel(readerThread); +} + void readerShutdown() { pthread_join(readerThread,NULL); diff --git a/readInput.h b/readInput.h index c467c71..782df1f 100644 --- a/readInput.h +++ b/readInput.h @@ -8,5 +8,6 @@ void readerInit(List* l); void readerShutdown(); +void readerCancel(); #endif \ No newline at end of file diff --git a/receiveUDP.c b/receiveUDP.c index 012b968..0a99f00 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -17,6 +17,7 @@ #include "queueOperations.h" #include "writeOutput.h" #include "receiveUDP.h" +#include "threadCanceller.h" // Max size of the message, theoretical max size of a UDP packet in IPv4. #define MAXBUFLEN 65508 @@ -117,8 +118,9 @@ static void* receiverLoop (void* unused) // Signals writer to write message to screen writerSignaller(); - if(!strcmp(message, "!")) + if(!strcmp(message, "!\n")) { + cancelReaderSender(); return NULL; } } @@ -137,6 +139,11 @@ void receiverInit(char* myP, List* l) exit(-1); } } + +void receiverCancel() +{ + pthread_cancel(receiverThread); +} void receiverShutdown() { // Freeing our results from getaddrinfo diff --git a/receiveUDP.h b/receiveUDP.h index 55da65c..221941e 100644 --- a/receiveUDP.h +++ b/receiveUDP.h @@ -9,5 +9,6 @@ void receiverInit(char* myP, List* l); void receiverShutdown(); +void receiverCancel(); #endif \ No newline at end of file diff --git a/sendUDP.c b/sendUDP.c index ea29249..9d3b4c0 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -88,7 +88,7 @@ static void* senderLoop(void* unused) numbytes = sendto(sockfd, message, strlen(message), 0, p->ai_addr, p->ai_addrlen); // Check for exit code - if(!strcmp(message,"!")) + if(!strcmp(message,"!\n")) { free(message); message = NULL; @@ -119,7 +119,11 @@ void senderSignaller(){ pthread_mutex_unlock(&sendAvailableCondMutex); } - + +void senderCancel() +{ + pthread_cancel(senderThread); +} void senderInit(char* hostnm, char* p, List* l) diff --git a/sendUDP.h b/sendUDP.h index f4ca172..433256d 100644 --- a/sendUDP.h +++ b/sendUDP.h @@ -8,6 +8,7 @@ // Starts a new pthread void senderInit(char* hostnm, char* p, List* l); +void senderCancel(); void senderShutdown(); void senderSignaller(); diff --git a/threadCanceller.c b/threadCanceller.c new file mode 100644 index 0000000..a264303 --- /dev/null +++ b/threadCanceller.c @@ -0,0 +1,16 @@ +#include "readInput.h" +#include "writeOutput.h" +#include "sendUDP.h" +#include "receiveUDP.h" +#include "threadCanceller.h" + +void cancelReceiverWriter() +{ + receiverCancel(); + writerCancel(); +} +void cancelReaderSender() +{ + readerCancel(); + senderCancel(); +} \ No newline at end of file diff --git a/threadCanceller.h b/threadCanceller.h new file mode 100644 index 0000000..3a837c5 --- /dev/null +++ b/threadCanceller.h @@ -0,0 +1,7 @@ +#ifndef _THREAD_CANCELLER_H +#define _THREAD_CANCELLER_H + +void cancelReceiverWriter(); +void cancelReaderSender(); + +#endif \ No newline at end of file diff --git a/writeOutput.c b/writeOutput.c index 13f1641..50b02d4 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -9,6 +9,7 @@ #include "list.h" #include "queueOperations.h" #include "writeOutput.h" + #define MAXBUFLEN 65508 static pthread_t writerThread; @@ -38,7 +39,7 @@ static void* writeLoop(void* useless){ } // Checking for exit code - if(!strcmp(message, "!")) + if(!strcmp(message, "!\n")) { free(message); message = NULL; @@ -76,6 +77,11 @@ void writerInit(List* l){ } +void writerCancel() +{ + pthread_cancel(writerThread); +} + void writerShutdown() { // De-allocating dynamically allocated message if shutdown is called while message is not yet freed diff --git a/writeOutput.h b/writeOutput.h index 1626995..e57c595 100644 --- a/writeOutput.h +++ b/writeOutput.h @@ -8,6 +8,7 @@ void writerSignaller(); void writerInit(List* l); +void writerCancel(); void writerShutdown(); #endif \ No newline at end of file From 022e4962c0037c85a9b7943d62c63af17ef90a49 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Thu, 1 Jul 2021 01:45:48 -0700 Subject: [PATCH 48/56] Deleted valgrind and run rules --- Makefile | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 24c7878..a3dbc11 100644 --- a/Makefile +++ b/Makefile @@ -3,15 +3,7 @@ CFLAGS = -Wall -Werror all: build build: - gcc $(CFLAGS) launcher.c readInput.c writeOutput.c sendUDP.c receiveUDP.c queueOperations.c list.c -o s-talk -lpthread - -run: build - ./s-talk - - -valgrind: build - valgrind --leak-check=full ./s-talk - - + gcc $(CFLAGS) launcher.c readInput.c writeOutput.c sendUDP.c receiveUDP.c queueOperations.c list.c threadCanceller.c -o s-talk -lpthread + clean: rm -f s-talk \ No newline at end of file From 510bb14fd712b5de4f0d97f29e6f07af69708c15 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Thu, 1 Jul 2021 17:58:11 -0700 Subject: [PATCH 49/56] Fixed excess input problem --- queueOperations.c | 5 +++++ queueOperations.h | 1 + readInput.c | 56 +++++++++++++++++++++++++++------------------- receiveUDP.c | 57 +++++++++++++++++++++++++++++------------------ sendUDP.c | 47 +++++++++++++++++++++----------------- writeOutput.c | 40 ++++++++++++++++++++------------- 6 files changed, 125 insertions(+), 81 deletions(-) diff --git a/queueOperations.c b/queueOperations.c index b90e5ff..53a1c7f 100644 --- a/queueOperations.c +++ b/queueOperations.c @@ -34,4 +34,9 @@ char* dequeueMessage(List* list) pthread_mutex_unlock(&queueMutex); return message; +} + +int countMessages(List* list) +{ + return List_count(list); } \ No newline at end of file diff --git a/queueOperations.h b/queueOperations.h index bc04152..c4aa45e 100644 --- a/queueOperations.h +++ b/queueOperations.h @@ -8,5 +8,6 @@ void enqueueMessage(List* list, char* message); char* dequeueMessage(List* list); +int countMessages(List* list); #endif \ No newline at end of file diff --git a/readInput.c b/readInput.c index b11c017..6affbed 100644 --- a/readInput.c +++ b/readInput.c @@ -12,6 +12,7 @@ #include "sendUDP.h" #include "threadCanceller.h" +// Max size of the message, theoretical max size of a UDP packet in IPv4. #define MAXBUFLEN 65508 static List* list; @@ -23,34 +24,43 @@ static void* readLoop(void* useless){ // Declaring variables char* message; char bufStorageOfMessage[MAXBUFLEN]; - - // Reading user input - int numbytes = read(0,bufStorageOfMessage, MAXBUFLEN); - if(numbytes==-1) + int numbytes; + int iteration = 0; + do { - perror("reader: read() failed"); - exit(-1); - } - - // Downsizing the size of the message to be more space efficient - // Downsizing the size of the message to be more space efficient - message = (char*)malloc(sizeof(char)*(numbytes+1)); - strncpy(message, bufStorageOfMessage, numbytes); - message[numbytes] = '\0'; - - // Adding the message to the list - enqueueMessage(list, message); + iteration++; + + // Emptying input string buffer + memset(&bufStorageOfMessage, 0, MAXBUFLEN); + // Reading user input + numbytes = read(0,bufStorageOfMessage, MAXBUFLEN); + if(numbytes==-1) + { + perror("reader: read() failed"); + exit(-1); + } + + // Downsizing the size of the message to be more space efficient + message = (char*)malloc(sizeof(char)*(numbytes+1)); + strncpy(message, bufStorageOfMessage, numbytes); + message[numbytes] = '\0'; + + // Adding the message to the list + enqueueMessage(list, message); + + // Checking for exit code + // Ends the process if exit code was in the first iteration of read + if (!strcmp(message,"!\n") && iteration==1) + { + senderSignaller(); + cancelReceiverWriter(); + return NULL; + } + } while (bufStorageOfMessage[numbytes-1]!='\n'); //send signal for the senderUDP senderSignaller(); - // Checking for exit code - if (!strcmp(message,"!\n")) - { - cancelReceiverWriter(); - return NULL; - } - } return NULL; } diff --git a/receiveUDP.c b/receiveUDP.c index 0a99f00..56b3451 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -96,33 +96,46 @@ static void* receiverLoop (void* unused) while(1) { - // Receiving - addr_len = sizeof(their_addr); - numbytes = recvfrom(sockfd, buf, MAXBUFLEN, 0, (struct sockaddr* ) &their_addr, &addr_len); - - // Error checking recvfrom - if(numbytes ==-1) + int iteration = 0; + do { - perror("receiver: recvfrom error"); - exit(-1); - } - - // Copying buf to a smaller string to put to the list - message = (char*)malloc(sizeof(char)*(numbytes+1)); - strncpy(message, buf, numbytes); - message[numbytes] = '\0'; + iteration++; + + // Emptying out receiving buffer + memset(&buf, 0, MAXBUFLEN); + + // Receiving + addr_len = sizeof(their_addr); + numbytes = recvfrom(sockfd, buf, MAXBUFLEN, 0, (struct sockaddr* ) &their_addr, &addr_len); + + // Error checking recvfrom + if(numbytes ==-1) + { + perror("receiver: recvfrom error"); + exit(-1); + } + + // Copying buf to a smaller string to put to the list + message = (char*)malloc(sizeof(char)*(numbytes+1)); + strncpy(message, buf, numbytes); + message[numbytes] = '\0'; + + // Adding message to the list + enqueueMessage(list, message); + + // Checking for exit code + // Ends the process if exit code was in the first iteration of receive + if(!strcmp(message, "!\n") && iteration == 1) + { + writerSignaller(); + cancelReaderSender(); + return NULL; + } + } while (buf[numbytes-1]!='\n'); - // Adding message to the list - enqueueMessage(list, message); // Signals writer to write message to screen writerSignaller(); - - if(!strcmp(message, "!\n")) - { - cancelReaderSender(); - return NULL; - } } return NULL; } diff --git a/sendUDP.c b/sendUDP.c index 9d3b4c0..4c29f23 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -80,31 +80,38 @@ static void* senderLoop(void* unused) } pthread_mutex_unlock(&sendAvailableCondMutex); - // Getting message from list - message = dequeueMessage(list); - - - // Sending - numbytes = sendto(sockfd, message, strlen(message), 0, p->ai_addr, p->ai_addrlen); + int iteration = 0; - // Check for exit code - if(!strcmp(message,"!\n")) + do { + iteration++; + + // Getting message from list + message = dequeueMessage(list); + + // Sending + numbytes = sendto(sockfd, message, strlen(message), 0, p->ai_addr, p->ai_addrlen); + + // Check for exit code + // Ends the thread if exit code is passed in the first iteration of the read + if(!strcmp(message,"!\n") && iteration==1) + { + free(message); + message = NULL; + return NULL; + } + + // De-allocating message free(message); message = NULL; - return NULL; - } - // De-allocating message - free(message); - message = NULL; - - // Error checking recvfrom - if(numbytes ==-1) - { - perror("sender: sendto error"); - exit(-1); - } + // Error checking recvfrom + if(numbytes ==-1) + { + perror("sender: sendto error"); + exit(-1); + } + } while (countMessages(list)!=0); } return NULL; } diff --git a/writeOutput.c b/writeOutput.c index 50b02d4..51bdfdd 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -10,6 +10,7 @@ #include "queueOperations.h" #include "writeOutput.h" +// Max size of the message, theoretical max size of a UDP packet in IPv4. #define MAXBUFLEN 65508 static pthread_t writerThread; @@ -29,26 +30,33 @@ static void* writeLoop(void* useless){ } pthread_mutex_unlock(&writeAvailableCondMutex); - // Taking message from list - message = dequeueMessage(list); + int iteration = 0; - int writeVar = write(1,message, strlen(message)); // will put the message from first list onto screen - if(writeVar == -1){ - perror("Error in write() : Unable to write to screen"); - exit(-1); - } - - // Checking for exit code - if(!strcmp(message, "!\n")) + do { + iteration ++; + + // Taking message from list + message = dequeueMessage(list); + + int writeVar = write(1,message, strlen(message)); // will put the message from first list onto screen + if(writeVar == -1){ + perror("Error in write() : Unable to write to screen"); + exit(-1); + } + + // Checking for exit code + if(!strcmp(message, "!\n") && iteration == 1) + { + free(message); + message = NULL; + return NULL; + } + + // Freeing message (message is dynamically allocated from receiver) free(message); message = NULL; - return NULL; - } - - // Freeing message (message is dynamically allocated from receiver) - free(message); - message = NULL; + } while (countMessages(list)!=0); } return NULL; From 4eb565401f92ad19d67d171ed5a3b038c2b325fa Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Fri, 2 Jul 2021 02:39:30 -0700 Subject: [PATCH 50/56] added gitignore files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1f86a6b..03103b1 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ s-talk .vscode/launch.json .gitignore .vscode/tasks.json +.vscode/settings.json From ae30658c2bf975919bc9eae3dc3b5a6aa9b64d76 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Fri, 2 Jul 2021 02:45:30 -0700 Subject: [PATCH 51/56] Changed max input buffer to 4096 --- readInput.c | 4 ++-- receiveUDP.c | 4 ++-- writeOutput.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/readInput.c b/readInput.c index 6affbed..d4cf3e3 100644 --- a/readInput.c +++ b/readInput.c @@ -12,8 +12,8 @@ #include "sendUDP.h" #include "threadCanceller.h" -// Max size of the message, theoretical max size of a UDP packet in IPv4. -#define MAXBUFLEN 65508 +// Max size of the message, using max value for terminal input +#define MAXBUFLEN 4096 static List* list; static pthread_t readerThread; diff --git a/receiveUDP.c b/receiveUDP.c index 56b3451..be7ed1d 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -19,8 +19,8 @@ #include "receiveUDP.h" #include "threadCanceller.h" -// Max size of the message, theoretical max size of a UDP packet in IPv4. -#define MAXBUFLEN 65508 +// Max size of the message, using max value for terminal input +#define MAXBUFLEN 4096 // Preparing variables we'll use static int sockfd; diff --git a/writeOutput.c b/writeOutput.c index 51bdfdd..78aabd0 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -10,8 +10,8 @@ #include "queueOperations.h" #include "writeOutput.h" -// Max size of the message, theoretical max size of a UDP packet in IPv4. -#define MAXBUFLEN 65508 +// Max size of the message, using max value for terminal input +#define MAXBUFLEN 4096 static pthread_t writerThread; static pthread_mutex_t writeAvailableCondMutex = PTHREAD_MUTEX_INITIALIZER; From 4e216b3a5062cfc4d2ab0516dba7d6915716f482 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Fri, 2 Jul 2021 19:00:35 -0700 Subject: [PATCH 52/56] Changed maxbuflen to 65506 --- readInput.c | 4 ++-- receiveUDP.c | 4 ++-- writeOutput.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/readInput.c b/readInput.c index d4cf3e3..fea50f8 100644 --- a/readInput.c +++ b/readInput.c @@ -12,8 +12,8 @@ #include "sendUDP.h" #include "threadCanceller.h" -// Max size of the message, using max value for terminal input -#define MAXBUFLEN 4096 +// Max size of the message, using theoretical max length for a UDP packet +#define MAXBUFLEN 65506 static List* list; static pthread_t readerThread; diff --git a/receiveUDP.c b/receiveUDP.c index be7ed1d..6af9807 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -19,8 +19,8 @@ #include "receiveUDP.h" #include "threadCanceller.h" -// Max size of the message, using max value for terminal input -#define MAXBUFLEN 4096 +// Max size of the message, using theoretical max length for a UDP packet +#define MAXBUFLEN 65506 // Preparing variables we'll use static int sockfd; diff --git a/writeOutput.c b/writeOutput.c index 78aabd0..48436df 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -10,8 +10,8 @@ #include "queueOperations.h" #include "writeOutput.h" -// Max size of the message, using max value for terminal input -#define MAXBUFLEN 4096 +// Max size of the message, using theoretical max length for a UDP packet +#define MAXBUFLEN 65506 static pthread_t writerThread; static pthread_mutex_t writeAvailableCondMutex = PTHREAD_MUTEX_INITIALIZER; From e6c9f54a743d6c7c6b104cec81653ee40b13b88b Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Fri, 2 Jul 2021 19:16:08 -0700 Subject: [PATCH 53/56] Added mutex to countMessages --- queueOperations.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/queueOperations.c b/queueOperations.c index 53a1c7f..87764a6 100644 --- a/queueOperations.c +++ b/queueOperations.c @@ -38,5 +38,12 @@ char* dequeueMessage(List* list) int countMessages(List* list) { - return List_count(list); + int count; + pthread_mutex_lock(&queueMutex); + { + count = List_count(list); + } + pthread_mutex_unlock(&queueMutex); + + return count; } \ No newline at end of file From ceb61924413dde48d626648fd31edd83de335bb2 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Fri, 2 Jul 2021 19:44:54 -0700 Subject: [PATCH 54/56] assigned message to null after shutdown --- writeOutput.c | 1 + 1 file changed, 1 insertion(+) diff --git a/writeOutput.c b/writeOutput.c index 48436df..fade927 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -96,6 +96,7 @@ void writerShutdown() // Note: if we HAVE already freed the pointer, then we've set the message pointer to NULL // and it is okay to free a NULL pointer (it does nothing) free(message); + message = NULL; pthread_join(writerThread, NULL); } From 05e866f7de7b1c4345f38a9aa0fc8c141066234f Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Fri, 2 Jul 2021 22:41:48 -0700 Subject: [PATCH 55/56] added debugging prints --- readInput.c | 4 +++- receiveUDP.c | 5 +++-- sendUDP.c | 1 + writeOutput.c | 4 +++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/readInput.c b/readInput.c index fea50f8..4c38ba3 100644 --- a/readInput.c +++ b/readInput.c @@ -13,7 +13,7 @@ #include "threadCanceller.h" // Max size of the message, using theoretical max length for a UDP packet -#define MAXBUFLEN 65506 +#define MAXBUFLEN 3 // 65506 static List* list; static pthread_t readerThread; @@ -58,6 +58,8 @@ static void* readLoop(void* useless){ } } while (bufStorageOfMessage[numbytes-1]!='\n'); +printf("reader: number of input right now = %d\n",countMessages(list)); +printf("reader: number of chunks to send = %d\n", iteration); //send signal for the senderUDP senderSignaller(); diff --git a/receiveUDP.c b/receiveUDP.c index 6af9807..4852a73 100644 --- a/receiveUDP.c +++ b/receiveUDP.c @@ -20,7 +20,7 @@ #include "threadCanceller.h" // Max size of the message, using theoretical max length for a UDP packet -#define MAXBUFLEN 65506 +#define MAXBUFLEN 3 // 65506 // Preparing variables we'll use static int sockfd; @@ -133,7 +133,8 @@ static void* receiverLoop (void* unused) } } while (buf[numbytes-1]!='\n'); - +printf("receiver: number of input right now = %d\n",countMessages(list)); +printf("receiver: number of chunks to write = %d\n", iteration); // Signals writer to write message to screen writerSignaller(); } diff --git a/sendUDP.c b/sendUDP.c index 4c29f23..e7aef24 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -81,6 +81,7 @@ static void* senderLoop(void* unused) pthread_mutex_unlock(&sendAvailableCondMutex); int iteration = 0; + printf("sender: number of items to send = %d\n", countMessages(list)); do { diff --git a/writeOutput.c b/writeOutput.c index fade927..130dd45 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -11,7 +11,7 @@ #include "writeOutput.h" // Max size of the message, using theoretical max length for a UDP packet -#define MAXBUFLEN 65506 +#define MAXBUFLEN 3 // 65506 static pthread_t writerThread; static pthread_mutex_t writeAvailableCondMutex = PTHREAD_MUTEX_INITIALIZER; @@ -32,6 +32,8 @@ static void* writeLoop(void* useless){ int iteration = 0; +printf("writer: number of items to write = %d\n", countMessages(list)); + do { iteration ++; From f2b8fcec1eb8b2d90500ab1f76dd608719d595f7 Mon Sep 17 00:00:00 2001 From: Darren Jennedy Date: Fri, 2 Jul 2021 23:00:38 -0700 Subject: [PATCH 56/56] added additional debugging prints --- sendUDP.c | 5 ++++- writeOutput.c | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sendUDP.c b/sendUDP.c index e7aef24..b2c7ffd 100644 --- a/sendUDP.c +++ b/sendUDP.c @@ -112,7 +112,10 @@ static void* senderLoop(void* unused) perror("sender: sendto error"); exit(-1); } - } while (countMessages(list)!=0); + } while (countMessages(list)!=0); + +printf("sender: number of items in list after send = %d\n", countMessages(list)); +printf("sender: number of items sent= %d\n", iteration); } return NULL; } diff --git a/writeOutput.c b/writeOutput.c index 130dd45..7759673 100644 --- a/writeOutput.c +++ b/writeOutput.c @@ -59,6 +59,9 @@ printf("writer: number of items to write = %d\n", countMessages(list)); free(message); message = NULL; } while (countMessages(list)!=0); + +printf("writer: number of items in list after write = %d\n", countMessages(list)); +printf("writer: number of items written = %d\n", iteration); } return NULL;