From: Nishi Date: Fri, 13 Sep 2024 11:28:43 +0000 (+0000) Subject: wip X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=76ba2cc93f998a38fa0f668a03a533414a7addba;p=tewi.git wip git-svn-id: file:///raid/svn-personal/tewi/trunk@9 8739d7e6-ffea-ec47-b151-bdff447c6205 --- diff --git a/Server/main.c b/Server/main.c index da854d7..eb13a48 100644 --- a/Server/main.c +++ b/Server/main.c @@ -49,4 +49,5 @@ int main(int argc, char** argv) { return 1; } cm_log("Daemon", "Ready"); + tw_server_loop(); } diff --git a/Server/server.c b/Server/server.c index af96368..49a8b1d 100644 --- a/Server/server.c +++ b/Server/server.c @@ -24,13 +24,14 @@ extern struct tw_config config; fd_set fdset; int sockcount = 0; -int sockets[MAX_PORTS]; #ifdef NO_IPV6 -struct sockaddr_in addresses[MAX_PORTS]; +#define SOCKADDR struct sockaddr_in #else -struct sockaddr_in6 addresses[MAX_PORTS]; +#define SOCKADDR struct sockaddr_in6 #endif +SOCKADDR addresses[MAX_PORTS]; +int sockets[MAX_PORTS]; void close_socket(int sock) { #ifdef __MINGW32__ @@ -104,7 +105,32 @@ int tw_server_init(void) { cm_log("Server", "Listen failure"); return 1; } + FD_SET(sock, &fdset); sockets[i] = sock; } return 0; } + +void tw_server_loop(void){ + struct timeval tv; + while(1){ + tv.tv_sec = 1; + tv.tv_usec = 0; + int ret = select(sockcount, &fdset, NULL, NULL, &tv); + if(ret == -1){ + break; + }else if(ret > 0){ + /* connection */ + printf("!\n"); + int i; + 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); + } + } + } + } +} diff --git a/Server/tw_server.h b/Server/tw_server.h index 12bde4c..3ab54d6 100644 --- a/Server/tw_server.h +++ b/Server/tw_server.h @@ -4,5 +4,6 @@ #define __TW_SERVER_H__ int tw_server_init(void); +void tw_server_loop(void); #endif