diff options
Diffstat (limited to 'server.c')
-rw-r--r-- | server.c | 37 |
1 files changed, 27 insertions, 10 deletions
@@ -99,7 +99,9 @@ void handle_setstation_command(int fd); uint16_t handle_handshake(int newfd); -int l = 1; +void cleanup_fds(); + +int l = 0; main(int argc, char *argv[]) { @@ -139,21 +141,25 @@ main(int argc, char *argv[]) memset(input, 0, LINE_MAX); char *tokens[LINE_MAX / 2]; - printf("snowcast> "); + printf("snowcast_server> "); fflush(stdout); while (read(STDIN_FILENO, input, LINE_MAX) > 0) { // init tokens memset(tokens, 0, (LINE_MAX / 2) * sizeof(char *)); // if 0, all whitespace - if (!parse(input, tokens)) + if (!parse(input, tokens)) { + printf("snowcast_server> "); + fflush(stdout); continue; + } char *command = tokens[0]; // if q, shutdown! if (!strcmp(command, "q")) { printf("Exiting.\n"); // TODO: exit better than break + cleanup_fds(); break; } @@ -189,12 +195,13 @@ main(int argc, char *argv[]) } else if (!strcmp(command, "log")) { l= !l; + printf("logging is now %s\n", l ? "on" : "off"); } else { - printf("unkown command.\n"); + printf("unknown command:\t%s\n", command); } - printf("snowcast> "); + printf("snowcast_server> "); fflush(stdout); } @@ -306,16 +313,14 @@ int setup_stations(int argc, char *argv[]) { } void write_int_to_fd(int fd, int n) { - int l = snprintf(NULL, 0, "%d", n); - char *num = malloc(l + 1); + int len = snprintf(NULL, 0, "%d", n); + char *num = malloc(len + 1); if (!num) { perror("malloc write to fd"); return; } - snprintf(num, l + 1, "%d", n); + snprintf(num, len + 1, "%d", n); if (write(fd, num, strlen(num)) == -1) { perror("write"); } - - free(num); } @@ -916,3 +921,15 @@ void handle_setstation_command(int sockfd) { update_user_station(sockfd, station_number); send_announce_reply(sockfd, station_number); } + +void cleanup_fds() { + // // close all the file descriptors + // for (int i = 0; i < num_stations; i++) { + // close(stations[i].readfd); + // } + // for (int i = 0; i < max_active_users; i++) { + // if (user_data[i].sockfd != -1) { + // close(user_data[i].sockfd); + // } + // } +} |