diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-09-25 13:43:14 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-09-25 13:43:14 -0400 |
commit | ec464a9e4733d84571a4639d1e3efcb41bf6ae57 (patch) | |
tree | 44c32471927e5f5d9ccf985b24e59accaa673de7 /server.c | |
parent | 150ff61c978b7ae381d1a71953c92bf4dd5c3571 (diff) |
fix udp connection pointers. may abstract into a memo type structure to reduce redunant calls
Diffstat (limited to 'server.c')
-rw-r--r-- | server.c | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -380,7 +380,7 @@ void *print_info_routine(void *arg) { return (NULL); } -int send_all_udp(int udp_sockfd, char *buf, int *len, struct addrinfo *thread_res) +int send_all_udp(int udp_sockfd, char *buf, int *len, struct sockaddr *addr, socklen_t addrlen) { int MAX_PACKET_SIZE = 512; int total = 0; // how many bytes we've sent @@ -388,8 +388,7 @@ int send_all_udp(int udp_sockfd, char *buf, int *len, struct addrinfo *thread_re int n; while(total < *len) { - n = sendto(udp_sockfd, buf+total, MAX_PACKET_SIZE, 0, thread_res->ai_addr, thread_res->ai_addrlen); - // thread_res->ai_addr, thread_res->ai_addrlen)) == -1; + n = sendto(udp_sockfd, buf+total, MAX_PACKET_SIZE, 0, addr, addrlen); if (n == -1) { break; } total += n; bytesleft -= n; @@ -406,7 +405,7 @@ void udp_port_cleanup_handler(void *arg) close(sockfd); } -int setup_udp_connection(int udp_port, int *udp_sockfd, struct addrinfo* res) { +int setup_udp_connection(int udp_port, int *udp_sockfd, socklen_t *addrlen, struct sockaddr* addr) { // setup hints to get udp_port struct addrinfo thread_hints, *thread_res, *thread_servinfo; memset(&thread_hints, 0, sizeof thread_hints); @@ -447,8 +446,9 @@ int setup_udp_connection(int udp_port, int *udp_sockfd, struct addrinfo* res) { *udp_sockfd = sock; // only these two properties of addrinfo are needed to send udp - *res->ai_addr = *thread_res->ai_addr; - res->ai_addrlen = thread_res->ai_addrlen; + // TODO: FIX, or reroute somewhere else + *addrlen = thread_res->ai_addrlen; + *addr = *thread_res->ai_addr; return 1; } @@ -470,8 +470,9 @@ void *send_udp_packet_routine(void *arg) { // setup udp socket for this thread/user int udp_port = user_data[user_index].udpPort; int udp_sockfd; - struct addrinfo *res; - if (setup_udp_connection(udp_port, &udp_sockfd, &res) == -1){ + struct sockaddr addr; + socklen_t addrlen; + if (setup_udp_connection(udp_port, &udp_sockfd, &addrlen, &addr) == -1){ fprintf(stderr, "failure in setup_udp_connection"); return (NULL); // error occured } @@ -493,7 +494,7 @@ void *send_udp_packet_routine(void *arg) { } // send the data! (no error check since udp) - send_all_udp(udp_sockfd, file_buffer, &buffer_size, &res); + send_all_udp(udp_sockfd, file_buffer, &buffer_size, &addr, addrlen); // cleanup close(udp_sockfd); |