From: Nishi Date: Fri, 13 Sep 2024 12:47:34 +0000 (+0000) Subject: multi-client X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=f110e3e190648e13ad43e6d94b7984735293a178;p=tewi.git multi-client git-svn-id: file:///raid/svn-personal/tewi/trunk@11 8739d7e6-ffea-ec47-b151-bdff447c6205 --- diff --git a/Server/Makefile b/Server/Makefile index efaea2d..7156fa8 100644 --- a/Server/Makefile +++ b/Server/Makefile @@ -5,7 +5,7 @@ include $(PWD)/Platform/$(PLATFORM).mk .PHONY: all clean .SUFFIXES: .c .o -OBJS = version.o main.o config.o server.o +OBJS = version.o main.o config.o server.o ssl.o all: tewi$(EXEC) diff --git a/Server/server.c b/Server/server.c index 0c1407f..32b0658 100644 --- a/Server/server.c +++ b/Server/server.c @@ -6,11 +6,13 @@ #include #include +#include #include #ifdef __MINGW32__ #include +#include #define NO_IPV6 #else #include @@ -109,28 +111,60 @@ int tw_server_init(void) { return 0; } -void tw_server_loop(void){ +#ifdef __MINGW32__ +struct pass_entry { + int sock; + bool ssl; +}; + +unsigned int WINAPI tw_server_pass(void* ptr) { + int sock = ((struct pass_entry*)ptr)->sock; + bool ssl = ((struct pass_entry*)ptr)->ssl; +#else +void tw_server_pass(int sock, bool ssl) { +#endif + close_socket(sock); +#ifdef __MINGW32__ + _endthreadex(0); +#endif +} + +void tw_server_loop(void) { struct timeval tv; - while(1){ + while(1) { FD_ZERO(&fdset); int i; - for(i = 0; i < sockcount; i++){ + for(i = 0; i < sockcount; i++) { FD_SET(sockets[i], &fdset); } tv.tv_sec = 1; tv.tv_usec = 0; int ret = select(FD_SETSIZE, &fdset, NULL, NULL, &tv); - if(ret == -1){ + if(ret == -1) { break; - }else if(ret > 0){ + } else if(ret > 0) { /* connection */ int i; - for(i = 0; i < sockcount; i++){ - if(FD_ISSET(sockets[i], &fdset)){ + for(i = 0; i < sockcount; i++) { + if(FD_ISSET(sockets[i], &fdset)) { SOCKADDR claddr; int clen = sizeof(claddr); int sock = accept(sockets[i], (struct sockaddr*)&claddr, &clen); - close_socket(sock); +#ifdef __MINGW32__ + HANDLE thread; + struct pass_entry* e = malloc(sizeof(*e)); + e->sock = sock; + e->ssl = config.ports[i] & (1ULL << 32); + thread = (HANDLE)_beginthreadex(NULL, 0, tw_server_pass, e, 0, NULL); +#else + pid_t pid = fork(); + if(pid == 0) { + tw_server_pass(sock, config.ports[i] & (1ULL << 32)); + _exit(0); + } else { + close_socket(sock); + } +#endif } } } diff --git a/Server/ssl.c b/Server/ssl.c new file mode 100644 index 0000000..fc3ce95 --- /dev/null +++ b/Server/ssl.c @@ -0,0 +1,3 @@ +/* $Id$ */ + +#include "tw_ssl.h" diff --git a/Server/tw_ssl.h b/Server/tw_ssl.h new file mode 100644 index 0000000..ce1d2af --- /dev/null +++ b/Server/tw_ssl.h @@ -0,0 +1,6 @@ +/* $Id$ */ + +#ifndef __TW_SSL_H__ +#define __TW_SSL_H__ + +#endif