]> Nishi Git Mirror - tewi.git/commitdiff
multi-client
authorNishi <nishi@nishi.boats>
Fri, 13 Sep 2024 12:47:34 +0000 (12:47 +0000)
committerNishi <nishi@nishi.boats>
Fri, 13 Sep 2024 12:47:34 +0000 (12:47 +0000)
git-svn-id: file:///raid/svn-personal/tewi/trunk@11 8739d7e6-ffea-ec47-b151-bdff447c6205

Server/Makefile
Server/server.c
Server/ssl.c [new file with mode: 0644]
Server/tw_ssl.h [new file with mode: 0644]

index efaea2db44e18e1dcb2b41e94cecd1cefbd85c3b..7156fa84fde4a4b89d3b5fc01fd9837a2bb3cac7 100644 (file)
@@ -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)
 
index 0c1407fb84de87e31a47a46d4099859df6dd2a59..32b06583bb4f7007195ccababb415abe17e774a7 100644 (file)
@@ -6,11 +6,13 @@
 
 #include <unistd.h>
 #include <string.h>
+#include <stdbool.h>
 
 #include <cm_log.h>
 
 #ifdef __MINGW32__
 #include <winsock2.h>
+#include <process.h>
 #define NO_IPV6
 #else
 #include <sys/select.h>
@@ -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 (file)
index 0000000..fc3ce95
--- /dev/null
@@ -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 (file)
index 0000000..ce1d2af
--- /dev/null
@@ -0,0 +1,6 @@
+/* $Id$ */
+
+#ifndef __TW_SSL_H__
+#define __TW_SSL_H__
+
+#endif