multi-client

git-svn-id: file:///raid/svn-personal/tewi/trunk@11 8739d7e6-ffea-ec47-b151-bdff447c6205
This commit is contained in:
Nishi 2024-09-13 12:47:34 +00:00
parent 7c613bd56f
commit f110e3e190
4 changed files with 52 additions and 9 deletions

View 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)

View 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
}
}
}

3
Server/ssl.c Normal file
View File

@ -0,0 +1,3 @@
/* $Id$ */
#include "tw_ssl.h"

6
Server/tw_ssl.h Normal file
View File

@ -0,0 +1,6 @@
/* $Id$ */
#ifndef __TW_SSL_H__
#define __TW_SSL_H__
#endif