diff options
-rw-r--r-- | server.c | 29 | ||||
-rwxr-xr-x | snowcast_control | bin | 22384 -> 35613 bytes | |||
-rwxr-xr-x | snowcast_listener | bin | 19120 -> 34654 bytes | |||
-rwxr-xr-x | snowcast_server | bin | 44576 -> 56428 bytes | |||
-rw-r--r-- | snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server | bin | 28763 -> 29417 bytes |
5 files changed, 24 insertions, 5 deletions
@@ -44,11 +44,12 @@ int num_stations; int start_threads = 0; int max_active_users = 0; +int max_sockfd = 0; pthread_mutex_t mutex_user_data = PTHREAD_MUTEX_INITIALIZER; // array from index to user_data user_t *user_data; -int sockfd_to_user[MAX_USERS]; +int *sockfd_to_user; // stations array pointer station_t *station_data; @@ -114,6 +115,8 @@ main(int argc, char *argv[]) // make array of user data user_data = malloc(sizeof(user_t) * max_active_users); if (!user_data) { perror("malloc userdata"); return 1; } + sockfd_to_user = malloc(sizeof(int) * max_active_users); + if (!sockfd_to_user) { perror("malloc sockfd to user"); return 1; } // make and start "select" thread that manages: // 1) new connections, 2) requests from current connections, 3)cloing connections @@ -245,6 +248,12 @@ int send_all_udp(int udp_sockfd, char *buf, int *len, struct addrinfo *thread_re return n==-1?-1:0; // return -1 on failure, 0 on success } +void udp_port_cleanup_handler(void *arg) +{ + int sockfd = (int) arg; + printf("Called clean-up handler, closing socket %d\n", sockfd); + close(sockfd); +} /* Make the manager routine */ void *send_udp_packet_routine(void *arg) { @@ -303,9 +312,10 @@ void *send_udp_packet_routine(void *arg) { // bind(udp_sockfd, thread_res->ai_addr, thread_res->ai_addrlen); - // freeaddrinfo(thread_servinfo); - - while (1) { + // freeaddrinfo(thread_servinfo) + pthread_cleanup_push(udp_port_cleanup_handler, (void *)udp_sockfd); + while (1) + { // wait for pthread_mutex_lock(&m); did_work = 0; @@ -374,6 +384,8 @@ void *send_udp_packet_routine(void *arg) { usleep(100000); } + + pthread_cleanup_pop(1); return NULL; } @@ -741,6 +753,14 @@ void *init_user(int sockfd) { // } // // printf("reusing memory\n"); // } + if(sockfd > max_sockfd) { + max_sockfd = sockfd; + int * more_sockfd_to_user = realloc(sockfd_to_user, sizeof(int) * (max_sockfd + 1)); + if (!more_sockfd_to_user) { perror("realloc"); exit(1); } + sockfd_to_user = more_sockfd_to_user; + } + + int running_index = 0; while(running_index < max_active_users) { if (user_data[running_index].sockfd == -1) { @@ -752,7 +772,6 @@ void *init_user(int sockfd) { // printf("reached max active users\n"); // printf("making new memory\n"); max_active_users++; - // TODO: FIX SO THAT IT USES CURRENT USERS, NOT MAX_ACTIVE_USERS FOT THE RESIZE user_t *more_users = realloc(user_data, sizeof(user_t) * max_active_users); if (!more_users) { perror("realloc"); exit(1); } user_data = more_users; diff --git a/snowcast_control b/snowcast_control Binary files differindex e8e8ad0..2ddfb3a 100755 --- a/snowcast_control +++ b/snowcast_control diff --git a/snowcast_listener b/snowcast_listener Binary files differindex 7accc61..ea9929a 100755 --- a/snowcast_listener +++ b/snowcast_listener diff --git a/snowcast_server b/snowcast_server Binary files differindex 2c41418..431fa68 100755 --- a/snowcast_server +++ b/snowcast_server diff --git a/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server b/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server Binary files differindex df5780d..0c8d053 100644 --- a/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server +++ b/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server |