From 9625efcaf8e7d7f57c8d2678b4d68b85dae91980 Mon Sep 17 00:00:00 2001 From: sotech117 Date: Sat, 23 Sep 2023 23:13:35 -0400 Subject: cleanup --- client.c | 11 ++++------- server.c | 15 +++++++-------- snowcast_control | Bin 35069 -> 35069 bytes snowcast_server | Bin 54332 -> 54332 bytes 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/client.c b/client.c index 63f7ef2..288b50c 100644 --- a/client.c +++ b/client.c @@ -138,16 +138,14 @@ int main(int argc, char *argv[]) } - printf("reply_type: %d\n", reply_type); - - if (reply_type == 2) { // we have a welcome message + if (reply_type == 2) { // we have a second welcome message close(sockfd); exit(1); } if (reply_type == 3) { // we have an announce message if (!station_is_set) { - fprintf(stderr, "ANNOUNCE received whem station not set."); + fprintf(stderr, "ANNOUNCE received before SETSTATION command."); close(sockfd); exit(1); } @@ -167,7 +165,6 @@ int main(int argc, char *argv[]) exit(1); } remove_timeout(sockfd); - // remove_timeout(sockfd); fflush(stdout); printf("New song announced: %s\n", song_name); fflush(stdout); @@ -208,7 +205,7 @@ int main(int argc, char *argv[]) perror("recv_all"); exit(1); } - // remove_timeout(sockfd); + remove_timeout(sockfd); fflush(stdout); printf("Station Information:\n%s\n", info); fflush(stdout); @@ -246,7 +243,7 @@ void *command_line_routine(void* args) { exit(0); } else if (strncmp("l\n", input, LINE_MAX) == 0) { // send the command to list stations - // apply_timeout(sockfd); + apply_timeout(sockfd); int list_station_reply_type = 5; if (send(sockfd, &list_station_reply_type, 1, 0) == -1) { perror("send"); diff --git a/server.c b/server.c index d782bc0..3d23394 100644 --- a/server.c +++ b/server.c @@ -92,7 +92,7 @@ void destroy_user(int sockfd); void send_announce_reply(int fd, int station_num); void send_invalid_command_reply(int fd, size_t message_size, char* message); -void send_stations_info_reply(int fd); +void *send_stations_info_reply(void *arg); // void *load_file(void* arg); @@ -713,7 +713,8 @@ void *select_routine(void *arg) { send_announce_reply(i, station_number); } else if (command_type == 5) { // we got a ListStations command - send_stations_info_reply(i); + pthread_t t; + pthread_create(&t, NULL, send_stations_info_reply, i); } else { // send back in invalid command @@ -852,9 +853,8 @@ void send_invalid_command_reply(int fd, size_t message_size, char* message) { free(send_buffer); } -void send_stations_info_reply(int fd) { - printf("sending stations info reply\n"); - // get the size of the reply +void *send_stations_info_reply(void * arg) { + int fd = (int) arg; uint8_t reply_size = 0; for (int i = 0; i < num_stations; i++) reply_size += snprintf(NULL, 0, "%d,%s\n", i, stations[i].filePath); @@ -865,7 +865,6 @@ void send_stations_info_reply(int fd) { if (send(fd, &reply_num, 1, 0) == -1) perror("send in send stations info"); // send payload size - printf("reply_size (server): %d\n", reply_size); if (send(fd, &reply_size, 1, 0) == -1) perror("send in send stations info"); @@ -874,11 +873,11 @@ void send_stations_info_reply(int fd) { for (int i = 0; i < num_stations; i++) ptr += sprintf(send_buffer + ptr, (i == num_stations - 1) ? "%d,%s" : "%d,%s\n", i, stations[i].filePath); - printf("buffer: \n%s\n", send_buffer); - int bytes_to_send = reply_size; // don't want final \n if (send_all(fd, &send_buffer, &bytes_to_send) == -1) perror("send_all"); + + return (NULL); } // Parses a buffer into tokens, from cs33 :) diff --git a/snowcast_control b/snowcast_control index a466c54..aa5a38e 100755 Binary files a/snowcast_control and b/snowcast_control differ diff --git a/snowcast_server b/snowcast_server index 3bab54f..2587920 100755 Binary files a/snowcast_server and b/snowcast_server differ -- cgit v1.2.3-70-g09d2