diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-09-25 15:28:11 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-09-25 15:28:11 -0400 |
commit | 13929ac7a2f3d18f1a9d5717e76d0e7725c263c4 (patch) | |
tree | 6789c1c10c5994d553f49e5bc43103f12d5fc5fd | |
parent | ec464a9e4733d84571a4639d1e3efcb41bf6ae57 (diff) |
clean up stream thread function
-rw-r--r-- | server.c | 16 | ||||
-rwxr-xr-x | snowcast_control | bin | 35277 -> 18848 bytes | |||
-rwxr-xr-x | snowcast_listener | bin | 34270 -> 13656 bytes | |||
-rwxr-xr-x | snowcast_server | bin | 71916 -> 37800 bytes | |||
-rwxr-xr-x | st | 4 |
5 files changed, 6 insertions, 14 deletions
@@ -277,7 +277,7 @@ void *stream_routine(void *arg) { if (bytes_read == -1) { return (NULL); } // TODO: send buffer to children - char *send_buffer = malloc(2 + bytes_read); + int *send_buffer; for (int i = 0; i < max_active_users; i++) { if (!user_data[i].sockfd || user_data[i].sockfd == -1) @@ -285,7 +285,7 @@ void *stream_routine(void *arg) { if (user_data[i].stationNum == station_num) { // send the udp packet - int *send_buffer = malloc(2 + bytes_read); + send_buffer = malloc(2 + bytes_read); memset(send_buffer, 0, 2 + bytes_read); send_buffer[0] = i; send_buffer[1] = bytes_read; @@ -295,7 +295,6 @@ void *stream_routine(void *arg) { pthread_create(&t, NULL, send_udp_packet_routine, send_buffer); } } - free(send_buffer); usleep(1000000 / 2 - 5000); start_threads = 1; pthread_cond_broadcast(&cond); @@ -303,6 +302,7 @@ void *stream_routine(void *arg) { usleep(5000); start_threads = 0; + free(send_buffer); memset(buffer, 0, MAX_RATE_PER_SECOND); } @@ -455,13 +455,11 @@ int setup_udp_connection(int udp_port, int *udp_sockfd, socklen_t *addrlen, stru /* Make the manager routine */ void *send_udp_packet_routine(void *arg) { - // printf("send udp packet routine\n"); - int *buf = arg; // unpack args + int *buf = arg; int user_index = buf[0]; int buffer_size = buf[1]; - char *file_buffer = malloc(buffer_size); - memcpy(file_buffer, buf+2, buffer_size); + char *data_ptr = buf + 2; // add two will skip first ints, since int* buf // setup variables int did_work = 1; @@ -494,14 +492,12 @@ void *send_udp_packet_routine(void *arg) { } // send the data! (no error check since udp) - send_all_udp(udp_sockfd, file_buffer, &buffer_size, &addr, addrlen); + send_all_udp(udp_sockfd, data_ptr, &buffer_size, &addr, addrlen); // cleanup close(udp_sockfd); - free(file_buffer); pthread_mutex_unlock(&m); - pthread_cleanup_pop(1); return (NULL); diff --git a/snowcast_control b/snowcast_control Binary files differindex 6eaeee5..01f4d14 100755 --- a/snowcast_control +++ b/snowcast_control diff --git a/snowcast_listener b/snowcast_listener Binary files differindex d15c2ac..f27a5c1 100755 --- a/snowcast_listener +++ b/snowcast_listener diff --git a/snowcast_server b/snowcast_server Binary files differindex 86eb007..55a64fb 100755 --- a/snowcast_server +++ b/snowcast_server @@ -1,4 +0,0 @@ -0,mp3/Beethoven-SymphonyNo5.mp3 -1,mp3/FX-Impact193.mp3 -2,mp3/U2-StuckInAMoment.mp3 -3,mp3/VanillaIce-IceIceBaby.mp3 |