Revision: 40650
          http://brlcad.svn.sourceforge.net/brlcad/?rev=40650&view=rev
Author:   davidloman
Date:     2010-09-22 18:49:45 +0000 (Wed, 22 Sep 2010)

Log Message:
-----------
eliminate redundant code surrounding closing of bad FileDescriptors

Modified Paths:
--------------
    rt^3/trunk/include/PortalManager.h
    rt^3/trunk/src/libNet/PortalManager.cxx

Modified: rt^3/trunk/include/PortalManager.h
===================================================================
--- rt^3/trunk/include/PortalManager.h  2010-09-22 18:35:47 UTC (rev 40649)
+++ rt^3/trunk/include/PortalManager.h  2010-09-22 18:49:45 UTC (rev 40650)
@@ -31,6 +31,7 @@
 #include "PkgTcpServer.h"
 #include <QtCore/QList>
 #include <QtCore/QMutex>
+#include <QtCore/QString>
 
 class Portal;
 
@@ -50,6 +51,8 @@
        QMutex* portalsLock;
        QMap<int, Portal*>* fdPortalMap;
 
+       void closeFD(int fd, QString logComment, fd_set* fdset = 0);
+
 };
 
 #endif

Modified: rt^3/trunk/src/libNet/PortalManager.cxx
===================================================================
--- rt^3/trunk/src/libNet/PortalManager.cxx     2010-09-22 18:35:47 UTC (rev 
40649)
+++ rt^3/trunk/src/libNet/PortalManager.cxx     2010-09-22 18:49:45 UTC (rev 
40650)
@@ -92,7 +92,7 @@
       for (int i = 0; i <= fdmax; ++i) {
                        if (FD_ISSET(i, &exceptionfds)) {
                                //TODO handle exceptions
-                               perror("Exception on FIleDescriptor");
+                               perror("Exception on FileDescriptor");
                        }
                        if (FD_ISSET(i, &readfds)) {
                                //If we are 'reading' on listener
@@ -118,25 +118,17 @@
                                                int readResult = 
this->fdPortalMap->value(i)->read();
                         this->portalsLock->unlock();
 
-                                               if (readResult == 0) {
-                                                       bu_log("Lost connection 
to remote host.\n");
-                                                       close(i);
-                                                       FD_CLR(i, &masterfds);
-                                                       continue;
+                        if (readResult == 0) {
+                                this->closeFD(i,"Lost connection to remote 
host.\n", &masterfds);
+                                continue;
+                        } else if (readResult < 0) {
+                                this->closeFD(i, "Error on read, dropping 
connection to remote host.\n", &masterfds);
+                                continue;
+                        }
 
-                                               } else if (readResult < 0) {
-                            bu_log("Error on read, dropping connection to 
remote host.\n");
-                                                       close(i);
-                                                       FD_CLR(i, &masterfds);
-                                                       continue;
-
-                                               }
-
                                        } else {
-                        bu_log("Attempting to read from FD not associated with 
a Portal, dropping connection to remote host.\n");
-                                               //Deal with unmapped file 
Descriptor
-                                               close(i);
-                                               FD_CLR(i, &masterfds);
+                        //Deal with unmapped file Descriptor
+                                               this->closeFD(i,"Attempting to 
read from FD not associated with a Portal, dropping connection to remote 
host.\n", &masterfds);
                                                continue;
                                        }
                                }
@@ -149,35 +141,36 @@
                                        this->portalsLock->unlock();
 
                                        if (readResult == 0) {
-                                               bu_log("Lost connection to 
remote host.\n");
-                                               close(i);
-                                               FD_CLR(i, &masterfds);
+                                               this->closeFD(i,"Lost 
connection to remote host.\n", &masterfds);
                                                continue;
-
                                        } else if (readResult < 0) {
-                                               bu_log(
-                                                               "Error on 
write, dropping connection to remote host.\n");
-                                               close(i);
-                                               FD_CLR(i, &masterfds);
+                                               this->closeFD(i, "Error on 
write, dropping connection to remote host.\n", &masterfds);
                                                continue;
-
                                        }
 
                                } else {
-                                       bu_log(
-                                                       "Attempting to write to 
FD not associated with a Portal, dropping connection to remote host.\n");
-                                       //Deal with unmapped file Descriptor
-                                       close(i);
-                                       FD_CLR(i, &masterfds);
+                    //Deal with unmapped file Descriptor
+                                       this->closeFD(i,"Attempting to write to 
FD not associated with a Portal, dropping connection to remote host.", 
&masterfds);
                                        continue;
                                }
                        }
                } //end FOR
-
-
     } //end while
 }//end fn
 
+void
+PortalManager::closeFD(int fd, QString logComment, fd_set* fdset)
+{
+       close(fd);
+       if (fdset != 0) {
+               FD_CLR(fd, fdset);
+       }
+
+       logComment.append("\n");
+       bu_log(logComment.toStdString().c_str());
+}
+
+
 // Local Variables:
 // tab-width: 8
 // mode: C++


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to