diff options
Diffstat (limited to 'server.c')
-rw-r--r-- | server.c | 16 |
1 files changed, 6 insertions, 10 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); |