From c3637b881c8da8095b623afde9854cd24714e4f6 Mon Sep 17 00:00:00 2001 From: sotech117 Date: Sun, 24 Sep 2023 00:36:04 -0400 Subject: cleanup more server code --- server.c | 32 +++++++++++++++++++++++--------- snowcast_server | Bin 54572 -> 54716 bytes 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/server.c b/server.c index 84c332a..959b6e3 100644 --- a/server.c +++ b/server.c @@ -88,6 +88,7 @@ void *init_user(int sockfd); void *update_user_udpPort(int sockfd, int udpPort); void *update_user_station(int sockfd, int stationNum); void *print_user_data(int sockfd); +void *print_station_data(int station); void destroy_user(int sockfd); void send_announce_reply(int fd, int station_num); @@ -136,8 +137,10 @@ main(int argc, char *argv[]) // command line interface char input[LINE_MAX]; memset(input, 0, LINE_MAX); - char *tokens[LINE_MAX / 2]; + + printf("snowcast> "); + fflush(stdout); while (read(STDIN_FILENO, input, LINE_MAX) > 0) { // init tokens memset(tokens, 0, (LINE_MAX / 2) * sizeof(char *)); @@ -171,21 +174,28 @@ main(int argc, char *argv[]) print_fd = STDOUT_FILENO; } // printf("print_fd: %d\n", print_fd); - pthread_t print_info_thread; - pthread_create(&print_info_thread, NULL, print_info_routine, print_fd); + // pthread_t print_info_thread; + // pthread_create(&print_info_thread, NULL, print_info_routine, print_fd); + print_info_routine((void *)print_fd); // note - this file descriptor is closed in the thread } else if (!strcmp(command, "u")) { - // print all user data - for (int i = 0; i < max_active_users; i++) - { - print_user_data(i); - } + for (int i = 0; i < max_active_users; i++) print_user_data(i); + } + else if (!strcmp(command, "s")) + { + for (int i = 0; i < num_stations; i++) print_station_data(i); } else if (!strcmp(command, "log")) { l= !l; } + else { + printf("unkown command.\n"); + } + + printf("snowcast> "); + fflush(stdout); } return 0; @@ -687,9 +697,13 @@ void *update_user_station(int sockfd, int stationNum) { pthread_mutex_unlock(&mutex_user_data); } void *print_user_data(int index) { - printf("udpPort: %d, stationNum: %d, sockfd: %d\n", + printf("user: %d -> udpPort: %d, stationNum: %d, sockfd: %d\n", index, user_data[index].udpPort, user_data[index].stationNum, user_data[index].sockfd); } +void *print_station_data(int station) { + printf("station: %d -> filePath: %s, readfd: %d\n", + station, stations[station].filePath, stations[station].readfd); +} void destroy_user(int sockfd) { close(sockfd); // bye! diff --git a/snowcast_server b/snowcast_server index 76e7ac8..a253156 100755 Binary files a/snowcast_server and b/snowcast_server differ -- cgit v1.2.3-70-g09d2