Revision: 41436
          http://brlcad.svn.sourceforge.net/brlcad/?rev=41436&view=rev
Author:   davidloman
Date:     2010-11-23 15:39:45 +0000 (Tue, 23 Nov 2010)

Log Message:
-----------
Fix a bug that had to deal with the selector loop in PortalManager occasionally 
missing a read.  Turns out there is an underlying select() call deep in libPkg 
that reads data from a socket and buffers it internal to libPkg.  That select() 
call is called on both high level read and write operations.  However, on the 
write op, the data that is read from the socket and NOT 'dispatched', thus the 
callback never gets called.  The quick fix for this is to make the 
PortalManager's select() call only block for a short period of time, AND to 
attempt a Portal->read() regardless of select()'s return status.  Its a polling 
type hack, but it works for now.

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

Modified: rt^3/trunk/src/libNet/PortalManager.cxx
===================================================================
--- rt^3/trunk/src/libNet/PortalManager.cxx     2010-11-23 15:36:46 UTC (rev 
41435)
+++ rt^3/trunk/src/libNet/PortalManager.cxx     2010-11-23 15:39:45 UTC (rev 
41436)
@@ -93,10 +93,15 @@
                this->masterFDSLock.unlock();
        }
 
+       bool isListener = false;
+       bool readyRead = false;
+       bool readyAccept = false;
+       bool readyException = false;
+
        while (this->runCmd) {
                //Set values EVERY loop since select() on *nix modifies this.
                timeout.tv_sec = 0;
-               timeout.tv_usec = 50 * 1000;
+               timeout.tv_usec = 50 * 1000 * 2;
 
                this->masterFDSLock.lock();
                readfds = masterfds;
@@ -104,37 +109,29 @@
                this->masterFDSLock.unlock();
 
                //Shelect!!
-               int retval = select(fdmax + 1, &readfds, NULL, &exceptionfds, 
&timeout);
-/*
+               int retVal = select(fdmax + 1, &readfds, NULL, &exceptionfds, 
&timeout);
+
+
+               if (retVal != 0) {
                QString out("Select returned: ");
-               out.append(QString::number(retval));
+               out.append(QString::number(retVal));
                out.append(". FD count: ");
                out.append(QString::number(this->fdPortalMap->keys().size()));
                out.append(". MAX FD: ");
                out.append(QString::number(fdmax));
                this->log->logINFO("PortalManager", out);
-*/
+               }
+
                //Save time on the loop:
-               if (retval == 0) {
+               if (retVal == 0) {
                        //continue;
                }
 
-               if (retval < 0) {
+               if (retVal < 0) {
                        //got a selector error
 
-                       /*      if(revtal == EABDF) {
-                        bu_log("Selector Error: EBADF: An invalid file 
descriptor was given in one of the sets. (Perhaps a file descriptor that was 
already closed, or one on which an error has occurred.)\n");
-                        } else if (retval == EINTR) {
-                        bu_log("Selector Error: EINTR: A signal was 
caught.\n");
-                        } else if (retval == EINVAL) {
-                        bu_log("Selector Error: EINVAL: nfds is negative or 
the value contained within timeout is invalid.\n");
-                        } else if (retval == ENOMEM) {
-                        bu_log("Selector Error: ENOMEM: unable to allocate 
memory for internal tables.\n");
-                        }*/
+                       this->log->logERROR("PortalManager", "Selector Error: " 
+ QString::number(errno));
 
-///                    this->log->logERROR("PortalManager", "Selector Error.");
-                       bu_log("Selector error: %d\n", errno);
-
                        break;
                }
 
@@ -147,29 +144,12 @@
                        }
 
                        //Simplify switching later with bools now
-                       bool isListener = (i == listener);
-                       bool readyRead = FD_ISSET(i, &readfds) && !isListener;
-                       bool readyAccept = FD_ISSET(i, &readfds) && isListener;
-                       bool readyException = FD_ISSET(i, &exceptionfds);
-/*
-                       QString s("FD:");
-                       s.append(QString::number(i));
+                       isListener = (i == listener);
+//                     readyRead = FD_ISSET(i, &readfds) && !isListener;
+                       readyRead = true; //Hotwire for now.
+                       readyAccept = FD_ISSET(i, &readfds) && isListener;
+                       readyException = FD_ISSET(i, &exceptionfds);
 
-                       if (isListener) {
-                               s.append(" is the listener and");
-                       }
-
-                       s.append(" is on the: masterFDS");
-
-                       if (readyRead) {
-                               s.append(", readFDS");
-                       }
-                       if (readyException) {
-                               s.append(", exceptionFDS");
-                       }
-
-                       log->logDEBUG("PortalManager", s);
-*/
                        //If nothing to do, then continue;
                        if (!readyRead && !readyAccept && !readyException) {
                                continue;
@@ -222,13 +202,7 @@
                                this->closeFD(i, s);
                                continue;
                        }
-                       /*
-                        const pkg_switch* table = 
p->pkgClient->getCallBackTable();
-                        pkg_switch sw = table[0];
-                        bu_log("PM(3.1): Route[0] type: %d\n", sw.pks_type);
-                        bu_log("PM(3.1): Route[0] callback: %d\n", 
sw.pks_handler);
-                        bu_log("PM(3.1): Route[0] user_data: %d\n", 
sw.pks_user_data);
-                        */
+
                        //read
                        if (readyRead) {
                                //this->log->logINFO("PortalManager", "Read");


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

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to