diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-09-19 00:44:40 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-09-19 00:44:40 -0400 |
commit | c36846a96fd45e57f37ce73e49af8275a305d4b4 (patch) | |
tree | 90cb8a81f396d37a87ef45ed045c80531336ae88 | |
parent | 7db333857219362ba14dec132825debc0d940a6c (diff) |
fix file descriptor leak
-rwxr-xr-x | c | bin | 35294 -> 35294 bytes | |||
-rwxr-xr-x | l | bin | 34638 -> 34638 bytes | |||
-rw-r--r-- | l.dSYM/Contents/Resources/DWARF/l | bin | 11651 -> 11651 bytes | |||
-rw-r--r-- | listener.c | 1 | ||||
-rw-r--r-- | mp3/chipOffTheBlock.mp3 | bin | 0 -> 4477733 bytes | |||
-rwxr-xr-x | s | bin | 55198 -> 55198 bytes | |||
-rw-r--r-- | s.dSYM/Contents/Resources/DWARF/s | bin | 23594 -> 23649 bytes | |||
-rw-r--r-- | snowcast_server_concurrent.c | 25 |
8 files changed, 17 insertions, 9 deletions
Binary files differBinary files differ diff --git a/l.dSYM/Contents/Resources/DWARF/l b/l.dSYM/Contents/Resources/DWARF/l Binary files differindex c55216a..283ecc9 100644 --- a/l.dSYM/Contents/Resources/DWARF/l +++ b/l.dSYM/Contents/Resources/DWARF/l @@ -102,7 +102,6 @@ int main(int argc, char *argv[]) //printf("listener: packet contains \"%s\"\n", buf); // print the size - write(STDOUT_FILENO, buf, numbytes); memset(buf, 0, MAXBUFLEN); diff --git a/mp3/chipOffTheBlock.mp3 b/mp3/chipOffTheBlock.mp3 Binary files differBinary files differnew file mode 100644 index 0000000..c06c05f --- /dev/null +++ b/mp3/chipOffTheBlock.mp3 diff --git a/s.dSYM/Contents/Resources/DWARF/s b/s.dSYM/Contents/Resources/DWARF/s Binary files differindex 4db3832..489e060 100644 --- a/s.dSYM/Contents/Resources/DWARF/s +++ b/s.dSYM/Contents/Resources/DWARF/s diff --git a/snowcast_server_concurrent.c b/snowcast_server_concurrent.c index 3b71156..47b112a 100644 --- a/snowcast_server_concurrent.c +++ b/snowcast_server_concurrent.c @@ -240,8 +240,8 @@ void *send_udp_packet_routine(void *arg) { // get file path char* file_path = station_data[station_num].filePath; // get current seek chunk - int current_chunk = station_data[station_num].seekIndex; FILE* file_stream = fopen(file_path, "r"); + int current_chunk = station_data[station_num].seekIndex; if (fseek(file_stream, current_chunk, SEEK_SET) == -1) { perror("fseek"); return (NULL); @@ -253,6 +253,7 @@ void *send_udp_packet_routine(void *arg) { perror("fread"); return (NULL); } + fclose(file_stream); // printf("send data: thread %d \n", user_index); // int numbytes; // if ((numbytes = sendto(udp_sockfd, data, strlen(data), 0, @@ -273,7 +274,6 @@ void *send_udp_packet_routine(void *arg) { did_work = 1; - close(file_stream); usleep(400000); } @@ -507,16 +507,24 @@ void *init_user(int sockfd) { // this is to save memory space. // in general, the displacement of 4 is where a user "used to be" int user_index = max_active_users++; - if(user_data[(sockfd-4)/2].sockfd == -1) { - printf("reusing memory\n"); - user_index = (sockfd - 4)/2; - } else { - printf("making new memory\n"); - // have to make more memory + int running_index = 0; + while(running_index++ < max_active_users) + { + if (user_data[running_index].sockfd == -1) + { + user_index = running_index; + break; + } + // printf("reusing memory\n"); + } + // have to make more memory + if (user_index == max_active_users) { + ///printf("making new memory\n"); user_t *more_users = realloc(user_data, sizeof(user_t) * max_active_users); if (!more_users) { perror("realloc"); exit(1); } user_data = more_users; } + // map TCP sockfd to this user index user_data[user_index] = (user_t){-1, -1, sockfd, -1}; sockfd_to_user[sockfd] = user_index; @@ -585,4 +593,5 @@ void send_announce_message(int fd, int station_num) { printf("sent %d bytes\n", bytessent); free(send_buffer); + }
\ No newline at end of file |