multi-client
git-svn-id: file:///raid/svn-personal/tewi/trunk@11 8739d7e6-ffea-ec47-b151-bdff447c6205
This commit is contained in:
parent
7c613bd56f
commit
f110e3e190
|
@ -5,7 +5,7 @@ include $(PWD)/Platform/$(PLATFORM).mk
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
.SUFFIXES: .c .o
|
.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)
|
all: tewi$(EXEC)
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,13 @@
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include <cm_log.h>
|
#include <cm_log.h>
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
#include <process.h>
|
||||||
#define NO_IPV6
|
#define NO_IPV6
|
||||||
#else
|
#else
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
@ -109,28 +111,60 @@ int tw_server_init(void) {
|
||||||
return 0;
|
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;
|
struct timeval tv;
|
||||||
while(1){
|
while(1) {
|
||||||
FD_ZERO(&fdset);
|
FD_ZERO(&fdset);
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < sockcount; i++){
|
for(i = 0; i < sockcount; i++) {
|
||||||
FD_SET(sockets[i], &fdset);
|
FD_SET(sockets[i], &fdset);
|
||||||
}
|
}
|
||||||
tv.tv_sec = 1;
|
tv.tv_sec = 1;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
int ret = select(FD_SETSIZE, &fdset, NULL, NULL, &tv);
|
int ret = select(FD_SETSIZE, &fdset, NULL, NULL, &tv);
|
||||||
if(ret == -1){
|
if(ret == -1) {
|
||||||
break;
|
break;
|
||||||
}else if(ret > 0){
|
} else if(ret > 0) {
|
||||||
/* connection */
|
/* connection */
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < sockcount; i++){
|
for(i = 0; i < sockcount; i++) {
|
||||||
if(FD_ISSET(sockets[i], &fdset)){
|
if(FD_ISSET(sockets[i], &fdset)) {
|
||||||
SOCKADDR claddr;
|
SOCKADDR claddr;
|
||||||
int clen = sizeof(claddr);
|
int clen = sizeof(claddr);
|
||||||
int sock = accept(sockets[i], (struct sockaddr*)&claddr, &clen);
|
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
3
Server/ssl.c
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
#include "tw_ssl.h"
|
6
Server/tw_ssl.h
Normal file
6
Server/tw_ssl.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
#ifndef __TW_SSL_H__
|
||||||
|
#define __TW_SSL_H__
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user