aboutsummaryrefslogtreecommitdiff
path: root/snowcast_server_concurrent.c
diff options
context:
space:
mode:
Diffstat (limited to 'snowcast_server_concurrent.c')
-rw-r--r--snowcast_server_concurrent.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/snowcast_server_concurrent.c b/snowcast_server_concurrent.c
index 110792d..03d6414 100644
--- a/snowcast_server_concurrent.c
+++ b/snowcast_server_concurrent.c
@@ -59,6 +59,8 @@ void *update_user_station(int sockfd, int stationNum);
void *print_user_data(int sockfd);
void destroy_user(int sockfd);
+void send_announce_message(int fd, int station_num);
+
// void *load_file(void* arg);
@@ -379,24 +381,7 @@ void *select_thread(void *arg) {
// update station of user
update_user_station(i, ntohs(command.number));
- char* file_path = station_data[station_num].filePath;
- int len_file_path = strlen(file_path);
-
- char *send_buffer = malloc(len_file_path+2);
- send_buffer[0] = 3;
- send_buffer[1] = len_file_path;
-
- memcpy(send_buffer + 2, file_path, len_file_path);
-
- printf("buffer: %s\n", send_buffer);
-
- int bytessent;
- if ((bytessent = send(newfd, send_buffer, len_file_path + 2, 0)) == -1)
- perror("send");
- // print the number of bytes sent
- printf("sent %d bytes\n", bytessent);
-
- free(send_buffer);
+ send_announce_message(i, station_num);
}
else {
// send back in invalid command
@@ -486,4 +471,25 @@ void *get_in_addr(struct sockaddr *sa)
}
return &(((struct sockaddr_in6*)sa)->sin6_addr);
+}
+
+void send_announce_message(int fd, int station_num) {
+ char* file_path = station_data[station_num].filePath;
+ int len_file_path = strlen(file_path);
+
+ char *send_buffer = malloc(len_file_path+2);
+ send_buffer[0] = 3;
+ send_buffer[1] = len_file_path;
+
+ memcpy(send_buffer + 2, file_path, len_file_path);
+
+ printf("buffer: %s\n", send_buffer);
+
+ int bytessent;
+ if ((bytessent = send(fd, send_buffer, len_file_path + 2, 0)) == -1)
+ perror("send");
+ // print the number of bytes sent
+ printf("sent %d bytes\n", bytessent);
+
+ free(send_buffer);
} \ No newline at end of file