aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server.c29
-rwxr-xr-xsnowcast_controlbin22384 -> 35613 bytes
-rwxr-xr-xsnowcast_listenerbin19120 -> 34654 bytes
-rwxr-xr-xsnowcast_serverbin44576 -> 56428 bytes
-rw-r--r--snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_serverbin28763 -> 29417 bytes
5 files changed, 24 insertions, 5 deletions
diff --git a/server.c b/server.c
index ed92486..63edf36 100644
--- a/server.c
+++ b/server.c
@@ -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
index e8e8ad0..2ddfb3a 100755
--- a/snowcast_control
+++ b/snowcast_control
Binary files differ
diff --git a/snowcast_listener b/snowcast_listener
index 7accc61..ea9929a 100755
--- a/snowcast_listener
+++ b/snowcast_listener
Binary files differ
diff --git a/snowcast_server b/snowcast_server
index 2c41418..431fa68 100755
--- a/snowcast_server
+++ b/snowcast_server
Binary files differ
diff --git a/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server b/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server
index df5780d..0c8d053 100644
--- a/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server
+++ b/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server
Binary files differ