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

Server/server.c

index 49a8b1d0f90e12c83097c247c21a769c3aaed8f5..0c1407fb84de87e31a47a46d4099859df6dd2a59 100644 (file)
@@ -47,7 +47,6 @@ int tw_server_init(void) {
        WSADATA wsa;
        WSAStartup(MAKEWORD(2, 0), &wsa);
 #endif
-       FD_ZERO(&fdset);
        for(i = 0; config.ports[i] != -1; i++)
                ;
        sockcount = i;
@@ -105,7 +104,6 @@ int tw_server_init(void) {
                        cm_log("Server", "Listen failure");
                        return 1;
                }
-               FD_SET(sock, &fdset);
                sockets[i] = sock;
        }
        return 0;
@@ -114,14 +112,18 @@ int tw_server_init(void) {
 void tw_server_loop(void){
        struct timeval tv;
        while(1){
+               FD_ZERO(&fdset);
+               int i;
+               for(i = 0; i < sockcount; i++){
+                       FD_SET(sockets[i], &fdset);
+               }
                tv.tv_sec = 1;
                tv.tv_usec = 0;
-               int ret = select(sockcount, &fdset, NULL, NULL, &tv);
+               int ret = select(FD_SETSIZE, &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)){