Changeset 65 in Main for trunk/Server
- Timestamp:
- Sep 19, 2024, 6:28:33 AM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Server/server.c
r64 r65 705 705 #endif 706 706 707 #ifdef __MINGW32__ 708 struct thread_entry { 709 HANDLE handle; 710 bool used; 711 }; 712 #endif 713 707 714 void tw_server_loop(void) { 708 715 struct timeval tv; 716 #ifdef __MINGW32__ 717 struct thread_entry threads[2048]; 718 int i; 719 for(i = 0; i < sizeof(threads) / sizeof(threads[0]); i++){ 720 threads[i].used = false; 721 } 722 #endif 709 723 while(1) { 710 724 FD_ZERO(&fdset); 711 int i;712 725 for(i = 0; i < sockcount; i++) { 713 726 FD_SET(sockets[i], &fdset); … … 719 732 break; 720 733 }else if(ret == 0){ 734 for(i = 0; i < sizeof(threads) / sizeof(threads[0]); i++){ 735 if(threads[i].used){ 736 DWORD ex; 737 GetExitCodeThread(threads[i].handle, &ex); 738 if(ex != STILL_ACTIVE){ 739 CloseHandle(threads[i].handle); 740 threads[i].used = false; 741 } 742 } 743 } 721 744 #ifdef SERVICE 722 745 if(status.dwCurrentState == SERVICE_STOP_PENDING){ … … 734 757 cm_log("Server", "New connection accepted"); 735 758 #ifdef __MINGW32__ 736 HANDLE thread;737 759 struct pass_entry* e = malloc(sizeof(*e)); 738 760 e->sock = sock; … … 740 762 e->port = config.ports[i]; 741 763 e->addr = claddr; 742 thread = (HANDLE)_beginthreadex(NULL, 0, tw_server_pass, e, 0, NULL); 764 int j; 765 for(j = 0; j < sizeof(threads) / sizeof(threads[0]); j++){ 766 if(threads[j].used){ 767 DWORD ex; 768 GetExitCodeThread(threads[j].handle, &ex); 769 if(ex != STILL_ACTIVE){ 770 CloseHandle(threads[j].handle); 771 threads[j].used = false; 772 } 773 } 774 } 775 for(j = 0; j < sizeof(threads) / sizeof(threads[0]); j++){ 776 if(!threads[j].used){ 777 threads[j].handle = (HANDLE)_beginthreadex(NULL, 0, tw_server_pass, e, 0, NULL); 778 threads[j].used = true; 779 break; 780 } 781 } 743 782 #else 744 783 pid_t pid = fork();
Note:
See TracChangeset
for help on using the changeset viewer.