diff options
Diffstat (limited to 'server.c')
-rw-r--r-- | server.c | 32 |
1 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! |