diff options
Diffstat (limited to 'server.c')
-rw-r--r-- | server.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -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 :) |