aboutsummaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-09-23 23:13:35 -0400
committersotech117 <michael_foiani@brown.edu>2023-09-23 23:13:35 -0400
commit9625efcaf8e7d7f57c8d2678b4d68b85dae91980 (patch)
treed9bf39096228491775edb69fdd0c20e7a6361f8e /server.c
parentc055294629f1c3bb8843c65ce5ebff15efc94b7b (diff)
cleanup
Diffstat (limited to 'server.c')
-rw-r--r--server.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/server.c b/server.c
index d782bc0..3d23394 100644
--- a/server.c
+++ b/server.c
@@ -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 :)