diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-09-24 00:36:04 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-09-24 00:36:04 -0400 |
commit | c3637b881c8da8095b623afde9854cd24714e4f6 (patch) | |
tree | 5581bbc9868789195774b25c1207c15749a26529 | |
parent | b578b114fd919d72948b051c036b34cb60976389 (diff) |
cleanup more server code
-rw-r--r-- | server.c | 32 | ||||
-rwxr-xr-x | snowcast_server | bin | 54572 -> 54716 bytes |
2 files changed, 23 insertions, 9 deletions
@@ -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 Binary files differindex 76e7ac8..a253156 100755 --- a/snowcast_server +++ b/snowcast_server |