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.c27
1 files changed, 9 insertions, 18 deletions
diff --git a/snowcast_server_concurrent.c b/snowcast_server_concurrent.c
index 4387407..110792d 100644
--- a/snowcast_server_concurrent.c
+++ b/snowcast_server_concurrent.c
@@ -379,33 +379,24 @@ void *select_thread(void *arg) {
// update station of user
update_user_station(i, ntohs(command.number));
- const char* song_name = station_data[station_num].filePath;
- size_t song_name_size = strlen(song_name); // don't add 1, don't want to include the null terminator
- struct Announce *announce = malloc(sizeof *announce + song_name_size);
+ char* file_path = station_data[station_num].filePath;
+ int len_file_path = strlen(file_path);
- printf("song_name: %s\n", song_name);
+ char *send_buffer = malloc(len_file_path+2);
+ send_buffer[0] = 3;
+ send_buffer[1] = len_file_path;
- announce->replyType = 3;
- announce->songnameSize = song_name_size;
+ memcpy(send_buffer + 2, file_path, len_file_path);
- announce->songname = malloc(song_name_size);
- memcpy(announce->songname, song_name, song_name_size);
-
- // print out all fields on announce on one line
- printf("announce: %d %d %s\n", announce->replyType, announce->songnameSize, announce->songname);
-
- char* send_buffer[sizeof(struct Announce) + song_name_size];
- memcpy(send_buffer, announce, sizeof(struct Announce));
- memcpy(send_buffer+sizeof(struct Announce), song_name, song_name_size);
+ printf("buffer: %s\n", send_buffer);
int bytessent;
- if ((bytessent = send(newfd, send_buffer, sizeof(struct Announce) + song_name_size, 0)) == -1)
+ 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(announce->songname);
- free(announce);
+ free(send_buffer);
}
else {
// send back in invalid command