Changeset 11 in Main
- Timestamp:
- Sep 13, 2024, 9:47:34 PM (2 months ago)
- Location:
- trunk/Server
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Server/Makefile
r8 r11 6 6 .SUFFIXES: .c .o 7 7 8 OBJS = version.o main.o config.o server.o 8 OBJS = version.o main.o config.o server.o ssl.o 9 9 10 10 all: tewi$(EXEC) -
trunk/Server/server.c
r10 r11 7 7 #include <unistd.h> 8 8 #include <string.h> 9 #include <stdbool.h> 9 10 10 11 #include <cm_log.h> … … 12 13 #ifdef __MINGW32__ 13 14 #include <winsock2.h> 15 #include <process.h> 14 16 #define NO_IPV6 15 17 #else … … 110 112 } 111 113 112 void tw_server_loop(void){ 114 #ifdef __MINGW32__ 115 struct pass_entry { 116 int sock; 117 bool ssl; 118 }; 119 120 unsigned int WINAPI tw_server_pass(void* ptr) { 121 int sock = ((struct pass_entry*)ptr)->sock; 122 bool ssl = ((struct pass_entry*)ptr)->ssl; 123 #else 124 void tw_server_pass(int sock, bool ssl) { 125 #endif 126 close_socket(sock); 127 #ifdef __MINGW32__ 128 _endthreadex(0); 129 #endif 130 } 131 132 void tw_server_loop(void) { 113 133 struct timeval tv; 114 while(1) {134 while(1) { 115 135 FD_ZERO(&fdset); 116 136 int i; 117 for(i = 0; i < sockcount; i++) {137 for(i = 0; i < sockcount; i++) { 118 138 FD_SET(sockets[i], &fdset); 119 139 } … … 121 141 tv.tv_usec = 0; 122 142 int ret = select(FD_SETSIZE, &fdset, NULL, NULL, &tv); 123 if(ret == -1) {143 if(ret == -1) { 124 144 break; 125 } else if(ret > 0){145 } else if(ret > 0) { 126 146 /* connection */ 127 147 int i; 128 for(i = 0; i < sockcount; i++) {129 if(FD_ISSET(sockets[i], &fdset)) {148 for(i = 0; i < sockcount; i++) { 149 if(FD_ISSET(sockets[i], &fdset)) { 130 150 SOCKADDR claddr; 131 151 int clen = sizeof(claddr); 132 152 int sock = accept(sockets[i], (struct sockaddr*)&claddr, &clen); 133 close_socket(sock); 153 #ifdef __MINGW32__ 154 HANDLE thread; 155 struct pass_entry* e = malloc(sizeof(*e)); 156 e->sock = sock; 157 e->ssl = config.ports[i] & (1ULL << 32); 158 thread = (HANDLE)_beginthreadex(NULL, 0, tw_server_pass, e, 0, NULL); 159 #else 160 pid_t pid = fork(); 161 if(pid == 0) { 162 tw_server_pass(sock, config.ports[i] & (1ULL << 32)); 163 _exit(0); 164 } else { 165 close_socket(sock); 166 } 167 #endif 134 168 } 135 169 }
Note:
See TracChangeset
for help on using the changeset viewer.