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

Server/main.c
Server/server.c
Server/tw_server.h

index da854d74e2059bff4cc57ff067e8ace5de73457e..eb13a489580af579fffbb17de8111e5be28a96d6 100644 (file)
@@ -49,4 +49,5 @@ int main(int argc, char** argv) {
                return 1;
        }
        cm_log("Daemon", "Ready");
+       tw_server_loop();
 }
index af963681ed8a8d4a155595fe38269cd7bfd1d732..49a8b1d0f90e12c83097c247c21a769c3aaed8f5 100644 (file)
@@ -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);
+                               }
+                       }
+               }
+       }
+}
index 12bde4cba79495c7ccb0dbfc5b06636b8565662f..3ab54d6db0a7a49c82b7dce6c0e1afba5a850fe2 100644 (file)
@@ -4,5 +4,6 @@
 #define __TW_SERVER_H__
 
 int tw_server_init(void);
+void tw_server_loop(void);
 
 #endif