Fix problems from porting Qt3->Qt4, which were caused by introducing takeFirst()...
[vlp.git] / src / net / lognet.cpp
index 58e481380fc0e502142b6985a60bf1e5bb375e2c..4109c1dff066d38313819aa640d4ec132a9812f8 100644 (file)
@@ -377,16 +377,17 @@ void NETMOD::check_node(int n, int sc)
 
        m.msg_type = MSG_NET;
        m.param.pword[0] = NET_NODE_EXIST;
-
-       pomlink = Links.first();
        m.param.pword[1] = 0;
-       while (pomlink != NULL) {
+
+       QListIterator<NETlink*> linksIterator(Links);
+
+       while (linksIterator.hasNext()) {
+               pomlink = linksIterator.next();
                if (pomlink->node_number == n) {
                        m.param.pword[1] = 1;
                        strcpy(m.param.pstr, pomlink->addr);
                        break;
                }
-               pomlink = Links.takeFirst();
        }
        write(sc, &m, sizeof(MESSAGE));
 }
@@ -413,21 +414,22 @@ void NETMOD::get_internal()
        FD_SET(kernel_sock, &readset);
        nrset = kernel_sock;
 
-       pomlink = Interpreters.first();
-       while (pomlink != NULL) {
+       QListIterator<INTlink*> interpretersIterator(Interpreters);
+       while (interpretersIterator.hasNext()) {
+               pomlink = interpretersIterator.next();
                FD_SET(pomlink->sock, &readset);
                if (nrset < pomlink->sock) {
                        nrset = pomlink->sock;
                }
-               pomlink = Interpreters.takeFirst();
        }
 
        if (select(nrset + 1, &readset, &writeset, 0, (struct timeval *)&tout) >
                                                                        0) {
 
                /* Check request sockets */
-               pomlink = Interpreters.first();
-               while (pomlink != NULL) {
+               interpretersIterator.toFront();
+               while (interpretersIterator.hasNext()) {
+                       pomlink = interpretersIterator.next();
                        if (FD_ISSET(pomlink->sock, &readset)) {
                                nr = read(pomlink->sock, &msg, sizeof(MESSAGE));
                                if (nr > 0) {
@@ -451,7 +453,6 @@ void NETMOD::get_internal()
                                        }
                                }
                        } /* ISSET */
-                       pomlink=Interpreters.takeFirst();
                } // while
 
                /* Check internal socket */
@@ -645,24 +646,24 @@ void NETMOD::remote_messages()
        FD_ZERO(&wset);
        max = 0;
 
-       pomlink = Links.first();
-       while (pomlink != NULL) {
+       QListIterator<NETlink*> linksIterator(Links);
+       while (linksIterator.hasNext()) {
+               pomlink = linksIterator.next();
                if (pomlink->connected) {
                        FD_SET(pomlink->sock, &rset);
                        if (max < pomlink->sock){
                                max = pomlink->sock;
                        }
                }
-               pomlink=Links.takeFirst();
        }
 
        if (select(max + 1, &rset, &wset, 0, (struct timeval *)&tout) > 0) {
-               pomlink=Links.first();
-               while (pomlink!=NULL) {
+               linksIterator.toFront();
+               while (linksIterator.hasNext()) {
+                       pomlink = linksIterator.next();
                        if (FD_ISSET(pomlink->sock,&rset)) {
                                get_message(pomlink);
                        }
-                       pomlink=Links.takeFirst();
                }
        }
 }
@@ -685,23 +686,25 @@ void NETMOD::doitall() {
        if (max < kernel_sock) {
                max=kernel_sock;
        }
-       pomlink2 = Interpreters.first();
-       while (pomlink2 != NULL) {
+
+       QListIterator<INTlink*> interpretersIterator(Interpreters);
+       while (interpretersIterator.hasNext()) {
+               pomlink2 = interpretersIterator.next();
                FD_SET(pomlink2->sock, &rset);
                if (max < pomlink2->sock) {
-                       max=pomlink2->sock;
+                       max = pomlink2->sock;
                }
-               pomlink2 = Interpreters.takeFirst();
        }
-       pomlink = Links.first();
-       while (pomlink != NULL) {
+
+       QListIterator<NETlink*> linksIterator(Links);
+       while (linksIterator.hasNext()) {
+               pomlink = linksIterator.next();
                if (pomlink->connected) {
                        FD_SET(pomlink->sock, &rset);
                        if (max < pomlink->sock) {
                                max = pomlink->sock;
                        }
                }
-               pomlink=Links.takeFirst();
        }
 
        /* odczyt */
@@ -727,8 +730,9 @@ void NETMOD::doitall() {
 
                /* get internal message*/
                /* Check request sockets */
-               pomlink2 = Interpreters.first();
-               while (pomlink2 != NULL) {
+               interpretersIterator.toFront();
+               while (interpretersIterator.hasNext()) {
+                       pomlink2 = interpretersIterator.next();
                        if (FD_ISSET(pomlink2->sock,&rset)) {
                                nr = read(pomlink2->sock, &msg, sizeof(MESSAGE));
                                if (nr > 0) {
@@ -752,7 +756,6 @@ void NETMOD::doitall() {
                                        }
                                }
                        }/* ISSET */
-                       pomlink2 = Interpreters.takeFirst();
                }/* while */
 
                /* Check internal socket */
@@ -818,11 +821,11 @@ void NETMOD::doitall() {
 
                /* get remote message*/
 
-               pomlink=Links.first();
-               while (pomlink != NULL) {
+               linksIterator.toFront();
+               while (linksIterator.hasNext()) {
+                       pomlink = linksIterator.next();
                        if (FD_ISSET(pomlink->sock, &rset))
                                get_message(pomlink);
-                       pomlink=Links.takeFirst();
                }
        } // select 
 }
@@ -855,11 +858,11 @@ void NETMOD::connect_seq(char *a)
        struct sockaddr_in svr;
        int j, on;
 
-       pom = Links.first();
-       while (pom != NULL) {
+       QListIterator<NETlink*> linksIterator(Links);
+       while (linksIterator.hasNext()) {
+               pom = linksIterator.next();
                if (strcmp(pom->addr, a) == 0)
                        return;
-               pom = Links.takeFirst();
        }
        pom = new NETlink;
        strcpy(pom->addr, a);
@@ -889,11 +892,12 @@ void NETMOD::check_links()
        int j = 1;
        struct sockaddr_in svr;
        NETlink *pomlink;
+       QListIterator<NETlink*> linksIterator(Links);
 
        /* connect to all other nodes */
        if (!all_connected) {
-               pomlink = Links.first();
-               while (pomlink != NULL) {
+               while (linksIterator.hasNext()) {
+                       pomlink = linksIterator.next();
                        if (!(pomlink->connected)) {
                                bzero(&svr, sizeof(svr));
                                svr.sin_family = AF_INET;
@@ -913,17 +917,16 @@ void NETMOD::check_links()
                                        sock_reopen(pomlink);
                                }
                        } /* not connected */
-                       pomlink = Links.takeFirst();
                } /* while */
        } /* if */
        all_connected = TRUE;
-       pomlink = Links.first();
-       while(pomlink != NULL) {
+       linksIterator.toFront();
+       while(linksIterator.hasNext()) {
+               pomlink = linksIterator.next();
                if (pomlink->connected == FALSE) {
                        all_connected = FALSE;
                        break;
                }
-               pomlink = Links.takeFirst();
        }
 }
 
@@ -977,10 +980,11 @@ void NETMOD::send_code_ack(NETlink *lnk)
 void NETMOD::send_to_all(MESSAGE *msg)
 {
        NETlink *pomlink;
-       pomlink = Links.first();
-       while (pomlink != NULL) {
+
+       QListIterator<NETlink*> linksIterator(Links);
+       while (linksIterator.hasNext()) {
+               pomlink = linksIterator.next();
                write(pomlink->sock, msg, sizeof(MESSAGE));
-               pomlink = Links.takeFirst();
        }
 }
 
@@ -1004,10 +1008,11 @@ void NETMOD::exit_sequence()
        ::close(kernel_sock);
        ::close(listen_sock);
        unlink(kername);
-       pomlink = Links.first();
-       while (pomlink != NULL) {
+
+       QListIterator<NETlink*> linksIterator(Links);
+       while (linksIterator.hasNext()) {
+               pomlink = linksIterator.next();
                ::close(pomlink->sock);
-               pomlink = Links.takeFirst();
        }
        exit(0);
 }
@@ -1022,40 +1027,42 @@ void NETMOD::disconnect_seq()
        m.param.pword[0] = NET_DISCONNECT;
        m.param.pword[1] = MyNode;
 
-       p = Links.first();
-       while(p != NULL) {
+       QListIterator<NETlink*> linksIterator(Links);
+       while(linksIterator.hasNext()) {
+               p = linksIterator.next();
                send_to_node(p, &m);
-               p=Links.takeFirst();
        }
-       p = Links.first();
-       while(p != NULL) {
+
+       linksIterator.toFront();
+       while(linksIterator.hasNext()) {
+               p = linksIterator.next();
                ::close(p->sock);
-               p = Links.takeFirst();
        }
        Links.clear();
 }
 
 NETlink * NETMOD::findNETlink(int node)
 {
-       NETlink *pomlink;
-       pomlink = Links.first();
-       while(pomlink != NULL) {
+       NETlink *pomlink = NULL;
+       QListIterator<NETlink*> linksIterator(Links);
+
+       while(linksIterator.hasNext()) {
+               pomlink = linksIterator.next();
+
                if (pomlink->node_number == node)
                        return pomlink;
-
-               pomlink = Links.takeFirst();
-       } 
+       }
        return pomlink;
 }
 
 INTlink * NETMOD::findINTlink(int id)
 {
-       INTlink *pomlink;
-       pomlink = Interpreters.first();
-       while(pomlink != NULL) {
+       INTlink *pomlink = NULL;
+       QListIterator<INTlink*> interpretersIterator(Interpreters);
+       while(interpretersIterator.hasNext()) {
+               pomlink = interpretersIterator.next();
                if (pomlink->ID == id)
                        return pomlink;
-               pomlink = Interpreters.takeFirst();
        }
        return pomlink;
 }
@@ -1206,8 +1213,10 @@ void NETMOD::conn_info(int sk)
        m.msg_type = MSG_NET;
        m.param.pword[0] = NET_INFO;
        strcpy(m.param.pstr, "");
-       pom = Links.first();
-       while (pom != NULL) {
+
+       QListIterator<NETlink*> linksIterator(Links);
+       while (linksIterator.hasNext()) {
+               pom = linksIterator.next();
                sprintf(poms, "%d=%s;", pom->node_number, pom->addr);
                strcat(m.param.pstr, poms);
                k++;
@@ -1216,7 +1225,6 @@ void NETMOD::conn_info(int sk)
                        write(sk, &m, sizeof(MESSAGE));
                        k = 0;
                }
-               pom = Links.takeFirst();
        }
        if (k > 0) {
                m.param.pword[1] = k;