From 95c6effbb2f1a5b5d6e9974996a1646074093546 Mon Sep 17 00:00:00 2001
From: "Ion-Dorinel FILIP (25005)" <dorinel.filip@upb.ro>
Date: Tue, 25 Mar 2025 00:28:19 +0000
Subject: [PATCH] [lab6]: Use the same syntax for all the comments

---
 lab6/client.c       | 51 +++++++++++++++++++++++----------------------
 lab6/include/list.h | 10 ++++-----
 lab6/lib/list.c     | 12 +++++------
 lab6/server.c       | 39 ++++++++++++++++------------------
 4 files changed, 55 insertions(+), 57 deletions(-)

diff --git a/lab6/client.c b/lab6/client.c
index 7635050..d5c1ee4 100644
--- a/lab6/client.c
+++ b/lab6/client.c
@@ -16,7 +16,7 @@
 #include "list.h"
 #include "utils.h"
 
-/* Max size of the datagrams that we will be sending */
+// Max size of the datagrams that we will be sending
 #define CHUNKSIZE MAX_SIZE;
 #define SENT_FILENAME "file.bin"
 #define SERVER_IP "172.16.0.100"
@@ -51,10 +51,10 @@ void send_file_start_stop(int sockfd, struct sockaddr_in server_address,
     d.seq = seq;
     seq++;
 
-    /* TODO 1.1: Send the datagram. */
+    // TODO 1.1: Send the datagram.
 
-    /* TODO 1.2: Wait for ACK before moving to the next datagram to send.
-    If timeout or wrong seq number, resend the datagram. */
+    // TODO 1.2: Wait for ACK before moving to the next datagram to send.
+    // If timeout or wrong seq number, resend the datagram.
 
     if (n == 0) // end of file
       break;
@@ -68,13 +68,13 @@ void send_file_go_back_n(int sockfd, struct sockaddr_in server_address,
   DIE(fd < 0, "open");
   int rc;
 
-  /* TODO 2.1: Increase window size to a value that optimally uses the link */
+  // TODO 2.1: Increase window size to a value that optimally uses the link
   int window_size = 5;
   window->max_seq = 5;
-
+  
+  // Read the entire file in chunks and add them into a list of seq_udp (window)
   int seq = 1;
   while (1) {
-    /* Read the entire file in chunks and add them into a list of seq_udp (window) */
     struct seq_udp *d = malloc(sizeof(struct seq_udp));
     DIE(d == NULL, "malloc");
 
@@ -90,14 +90,14 @@ void send_file_go_back_n(int sockfd, struct sockaddr_in server_address,
       break;
   }
 
-  /* TODO 2.2: Send window_size  packets to the server to saturate the link */
+  // TODO 2.2: Send window_size  packets to the server to saturate the link
 
-  /* In a loop, untill the list of packets is empty */
+  // In a loop, untill the list of packets is empty
 
-  /* TODO 2.2: On ACK remove from the list all the segments that have been ACKed
-          and send the next new segments added to the window */
+  // TODO 2.2: On ACK remove from the list all the segments that have been ACKed
+  //           and send the next new segments added to the window
 
-  /* TODO 2.3: On timeout on recv resend all the segments from the window */
+  // TODO 2.3: On timeout on recv resend all the segments from the window
 }
 
 void send_a_message(int sockfd, struct sockaddr_in server_address) {
@@ -105,38 +105,38 @@ void send_a_message(int sockfd, struct sockaddr_in server_address) {
   strcpy(d.payload, "Hello world!");
   d.len = strlen("Hello world!");
 
-  /* Send a UDP datagram. Sendto is implemented in the kernel (network stack of
-   * it), it basically creates a UDP datagram, sets the payload to the data we
-   * specified in the buffer, and the completes the IP header and UDP header
-   * using the sever_address info.*/
+  // Send a UDP datagram. Sendto is implemented in the kernel (network stack of
+  // it), it basically creates a UDP datagram, sets the payload to the data we
+  // specified in the buffer, and the completes the IP header and UDP header
+  // using the sever_address info.
   int rc = sendto(sockfd, &d, sizeof(struct seq_udp), 0,
                   (struct sockaddr *)&server_address, sizeof(server_address));
 
   DIE(rc < 0, "send");
 
-  /* Receive the ACK. recvfrom is blocking with the current parameters */
+  // Receive the ACK. recvfrom is blocking with the current parameters 
   int ack;
   rc = recvfrom(sockfd, &ack, sizeof(ack), 0, NULL, NULL);
 }
 
 int main(void) {
 
-  /* We use this structure to store the server info. IP address and Port.
-   * This will be written by the UDP implementation into the header */
+  // We use this structure to store the server info. IP address and Port.
+  // This will be written by the UDP implementation on recvfrom().
   struct sockaddr_in servaddr;
   int sockfd, rc;
 
   // for benchmarking
   TICK(TIME_A);
 
-  /* Our transmission window*/
+  // Our transmission window
   window = create_list();
 
   // Creating socket file descriptor. SOCK_DGRAM for UDP
   sockfd = socket(AF_INET, SOCK_DGRAM, 0);
   DIE(sockfd < 0, "socket");
 
-  /* Set the timeout on the socket */
+  // Set the timeout on the socket
   struct timeval timeout;
   timeout.tv_sec = 0;
   timeout.tv_usec = 250000; // 250ms
@@ -151,9 +151,10 @@ int main(void) {
   servaddr.sin_port = htons(PORT);
   inet_aton(SERVER_IP, &servaddr.sin_addr);
 
-  /* TODO: Read the demo function.
-  Implement and test (one at a time) each of the proposed versions for sending a
-  file. */
+  // TODO: Read the demo function.
+  // Implement and test (one at a time) each of the proposed versions for sending a
+  // file.
+
   send_a_message(sockfd, servaddr);
   // send_file_start_stop(sockfd, servaddr, SENT_FILENAME);
   // send_file_go_back_n(sockfd, servaddr, SENT_FILENAME);
@@ -162,7 +163,7 @@ int main(void) {
 
   free(window);
 
-  /* Print the runtime of the program */
+  // Print the runtime of the program
   TOCK(TIME_A);
 
   return 0;
diff --git a/lab6/include/list.h b/lab6/include/list.h
index 0d3b4f2..deb6371 100644
--- a/lab6/include/list.h
+++ b/lab6/include/list.h
@@ -1,7 +1,7 @@
 #ifndef _LIST_H_
 #define _LIST_H_
 
-/* List entry */
+// List entry
 struct cel {
   void *info;
   int info_len;
@@ -12,16 +12,16 @@ struct cel {
 
 typedef struct cel list_entry;
 
-/* Window as a list */
+// Window as a list
 typedef struct {
   int size;
   int max_seq;
   list_entry *head;
 } list;
 
-/* Creates a list */
+// Creates a list
 list *create_list();
-/* Adds a segment to the window */
+// Adds a segment to the window
 void add_list_elem(list *window, void *segment, int segment_size, int seq);
 
-#endif /* _LIST_H_ */
+#endif // _LIST_H_
diff --git a/lab6/lib/list.c b/lab6/lib/list.c
index 085f588..aa802e5 100644
--- a/lab6/lib/list.c
+++ b/lab6/lib/list.c
@@ -9,7 +9,7 @@ list *create_list() {
   return l;
 }
 
-/* append order by seq */
+// append order by seq
 void add_list_elem(list *list, void *info, int info_len, int seq) {
 
   /* first check for duplicates seq */
@@ -21,11 +21,11 @@ void add_list_elem(list *list, void *info, int info_len, int seq) {
     l_check = l_check->next;
   }
 
-  /* create list entry and set seq and type */
+  // create list entry and set seq and type
   list_entry *l = (list_entry *)calloc(1, sizeof(list_entry));
   l->seq = seq;
 
-  /* buffer info */
+  // buffer info
   if (info_len > 0) {
     l->info = calloc(info_len, sizeof(char));
     memcpy(l->info, info, info_len);
@@ -34,13 +34,13 @@ void add_list_elem(list *list, void *info, int info_len, int seq) {
     l->info = NULL;
   }
 
-  /* first elem */
+  // first elem
   if (list->head == NULL) {
     list->head = l;
   } else {
     list_entry *_l = list->head;
 
-    /* first elem */
+    // first elem
     if (_l->seq > seq) {
       l->next = _l;
       list->head = l;
@@ -48,7 +48,7 @@ void add_list_elem(list *list, void *info, int info_len, int seq) {
       return;
     }
 
-    /* find elem place */
+    // find elem place
     while (_l->next && _l->next->seq < seq) {
       _l = _l->next;
     }
diff --git a/lab6/server.c b/lab6/server.c
index 8527382..00076c5 100644
--- a/lab6/server.c
+++ b/lab6/server.c
@@ -21,19 +21,18 @@ int recv_seq_udp(int sockfd, struct seq_udp *seq_packet, int expected_seq) {
   struct sockaddr_in client_addr;
   socklen_t clen = sizeof(client_addr);
 
-  /* Receive a segment with seq_number seq_packet->seq */
+  // Receive a segment with seq_number seq_packet->seq
   int rc = recvfrom(sockfd, seq_packet, sizeof(struct seq_udp), 0,
                     (struct sockaddr *)&client_addr, &clen);
 
-  /* TODO: Check if the sequence number is the expected one. */
+  // TODO: Check if the sequence number is the expected one.
 
-  /* TODO: If we got the expected packet (by seq) send ACK for the seq.packet
-     and return the number of bytes read. 
-     
-     We will increase expected_seq in the calling function (recv_a_file(...)) */
+  // TODO: If we got the expected packet (by seq) send ACK for the seq.packet
+  // and return the number of bytes read. 
+  // We will increase expected_seq in the calling function (recv_a_file(...))
 
-  /* TODO: If segment is not with the expected number, send ACK
-     for the last well received packet (expected_seq - 1) and return -1  */
+  // TODO: If segment is not with the expected number, send ACK
+  // for the last well received packet (expected_seq - 1) and return -1
 }
 
 void recv_a_file(int sockfd, char *filename) {
@@ -44,21 +43,19 @@ void recv_a_file(int sockfd, char *filename) {
   int rc;
 
   while (1) {
-    /* Receive a chunk */
+    // Receive a chunk
     rc = recv_seq_udp(sockfd, &p, expected_seq);
 
-    /* TODO: If rc == -1 => we didn't receive the expected segment. We continue
-     */
+    // TODO: If rc == -1 => we didn't receive the expected segment. We continue (retry to receive the same chunk).
 
-    /* TODO: If rc >=0 => we receive the expected segment. We increase
-     * expected_seq */
+    // TODO: If rc >=0 => we receive the expected segment. We increase expected_seq
 
-    /* An empty payload means the file ended.
-    Break if file ended */
+    // An empty payload means the file ended.
     if (p.len == 0)
+      // Break if file ended
       break;
 
-    /* Write the chunk to the file */
+    // Write the chunk to the file
     write(fd, p.payload, p.len);
   }
 
@@ -66,15 +63,15 @@ void recv_a_file(int sockfd, char *filename) {
 }
 
 void recv_a_message(int sockfd) {
-  /* Receive a datagram and send an ACK */
-  /* The info of the who sent the datagram (PORT and IP) */
+  // Receive a datagram and send an ACK
+  // The info of the who sent the datagram (PORT and IP)
   struct sockaddr_in client_addr;
   struct seq_udp p;
   socklen_t clen = sizeof(client_addr);
   int rc = recvfrom(sockfd, &p, sizeof(struct seq_udp), 0,
                     (struct sockaddr *)&client_addr, &clen);
 
-  /* We know it's a string so we print it*/
+  // We know it's a string so we print it
   printf("[Server] Received: %s\n", p.payload);
 
   int ack = 0;
@@ -94,7 +91,7 @@ int main(void) {
     exit(EXIT_FAILURE);
   }
 
-  /* Make ports reusable, in case we run this really fast two times in a row */
+  // Make ports reusable, in case we run this really fast two times in a row
   int enable = 1;
   if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0)
     perror("setsockopt(SO_REUSEADDR) failed");
@@ -103,7 +100,7 @@ int main(void) {
   // datagrams have to be sent to our process.
   memset(&servaddr, 0, sizeof(servaddr));
   servaddr.sin_family = AF_INET; // IPv4
-  /* 0.0.0.0, basically match any IP */
+  // 0.0.0.0, basically match any IP
   servaddr.sin_addr.s_addr = INADDR_ANY;
   servaddr.sin_port = htons(PORT);
 
-- 
GitLab