gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/rtmp r9681: new waitForNetData() method. S


From: rob
Subject: [Gnash-commit] /srv/bzr/gnash/rtmp r9681: new waitForNetData() method. Support for pselect or poll when waiting for multiple file descriptors.
Date: Sat, 01 Nov 2008 09:00:27 -0600
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9681
committer: address@hidden
branch nick: rtmp
timestamp: Sat 2008-11-01 09:00:27 -0600
message:
  new waitForNetData() method. Support for pselect or poll when waiting for 
multiple file descriptors.
modified:
  libnet/network.cpp
  libnet/network.h
=== modified file 'libnet/network.cpp'
--- a/libnet/network.cpp        2008-09-06 07:35:31 +0000
+++ b/libnet/network.cpp        2008-11-01 15:00:27 +0000
@@ -21,7 +21,8 @@
 #endif
 
 #include <boost/thread/mutex.hpp>
-
+#include <boost/shared_ptr.hpp>
+#include <vector>
 
 #include "utility.h"
 #include "log.h"
@@ -49,6 +50,13 @@
 # include <netdb.h>
 # include <sys/param.h>
 # include <sys/select.h>
+#ifdef HAVE_POLL
+# include <poll.h>
+#else 
+# ifdef HAVE_EPOLL
+#  include <epoll.h>
+# endif
+#endif
 #endif
 
 #include "buffer.h"
@@ -939,6 +947,91 @@
     return ret;
 }
 
+//boost::shared_ptr<vector<int> >
+boost::shared_ptr<std::vector<int> >
+Network::waitForNetData(int limit, struct pollfd *fds)
+{
+//    GNASH_REPORT_FUNCTION;
+    
+    boost::shared_ptr<vector<int> > hits(new vector<int>);
+
+    int ret = poll(fds, limit, _timeout);
+    
+    for (int i = 0; i<limit; i++) {
+       if (fds[i].revents == POLLIN) {
+           hits->push_back(i);
+           // If we got as many matches as were seen by poll(), then
+           // stop searching the rest of the items in the array.
+           if (hits->size() == ret) {
+               break;
+           }
+       }
+    }
+
+    return hits;
+}
+
+fd_set
+Network::waitForNetData(vector<int> &data)
+{
+//    GNASH_REPORT_FUNCTION;
+
+    fd_set fdset;
+    FD_ZERO(&fdset);
+    
+    for (size_t i = 0; i<data.size(); i++) {
+       FD_SET(data[i], &fdset);
+    }
+
+    return waitForNetData(data.size(), fdset);
+}
+
+fd_set
+//boost::shared_ptr<vector<int> >
+Network::waitForNetData(int limit, fd_set files)
+{
+//    GNASH_REPORT_FUNCTION;
+
+    // select modifies this the set of file descriptors, and we don't
+    // want to modify the one passed as an argument, so we make a copy.
+    fd_set fdset = files;
+    
+    // Reset the timeout value, since select modifies it on return
+    int timeout = _timeout;
+    if (timeout <= 0) {
+       timeout = 5;
+    }
+#if 0
+    struct timespec tval;
+    sigset_t sigmask;
+    sigprocmask(SIG_BLOCK, &sigmask, NULL);
+
+    tval.tv_sec = timeout;
+    tval.tv_nsec = 0;
+    int ret = pselect(limit+1, &fdset, NULL, NULL, &tval, &sigmask);
+#else
+    struct timeval        tval;
+    tval.tv_sec = timeout;
+    tval.tv_usec = 0;
+    int ret = select(limit+1, &fdset, NULL, NULL, &tval);
+#endif
+    // If interupted by a system call, try again
+    if (ret == -1 && errno == EINTR) {
+       log_error (_("Waiting for data for fdset %d was interupted by a system 
call"), reinterpret_cast<int>(fdset.fds_bits));
+    }
+    
+    if (ret == -1) {
+       log_error (_("Waiting for data for fdset  %d was never available for 
reading"), reinterpret_cast<int>(fdset.fds_bits));
+    }
+    
+    if (ret == 0) {
+       log_debug (_("Waiting for data for fdset  %d timed out waiting for 
data"), reinterpret_cast<int>(fdset.fds_bits));
+       FD_ZERO(&fdset);
+    }
+
+    return fdset;
+}
+
 void
 Network::toggleDebug(bool val)
 {
@@ -946,10 +1039,8 @@
     _debug = val;
 
     // Turn on debugging for the utility methods
-               // recursive on all control paths,
-               // function will cause runtime stack overflow
-
-               // toggleDebug(true);
+    // recursive on all control paths,
+    // toggleDebug(true);
 }
 
 

=== modified file 'libnet/network.h'
--- a/libnet/network.h  2008-08-28 01:22:41 +0000
+++ b/libnet/network.h  2008-11-01 15:00:27 +0000
@@ -26,6 +26,14 @@
 # include <sys/types.h>
 # include <netinet/in.h>
 # include <arpa/inet.h>
+# include <sys/select.h>
+#ifdef HAVE_POLL
+# include <poll.h>
+#else 
+# ifdef HAVE_EPOLL
+#  include <epoll.h>
+# endif
+#endif
 #else
 # include <winsock2.h>
 # include <windows.h>
@@ -35,10 +43,23 @@
 #endif
 
 #include "dsodefs.h" //For DSOEXPORT.
+#include <boost/shared_ptr.hpp>
 #include <boost/cstdint.hpp>
+#include <vector>
 #include <cassert>
 #include <string>
 
+// /// \struct pollfd
+// ///
+// /// We use the system call poll()s data structure for passing
+// #ifndef HAVE_POLL
+// struct pollfd {
+//     int fd;        // the relevant file descriptor
+//     short events;  // events we are interested in
+//     short revents; // events which occur will be marked here
+// };
+// #endif
+
 namespace amf {
 class Buffer;
 }
@@ -111,7 +132,13 @@
 //    int writeNet(int fd, const byte_t *buffer);
     int writeNet(int fd, const byte_t *buffer, int nbytes);
     int writeNet(int fd, const byte_t *buffer, int nbytes, int timeout);
-    
+
+#ifdef HAVE_POLL
+    boost::shared_ptr<std::vector<int> > waitForNetData(int limit, struct 
pollfd *fds);
+#endif
+    fd_set waitForNetData(int limit, fd_set data);
+    fd_set waitForNetData(std::vector<int> &data);
+       
     // Close the connection
     bool closeNet();
     bool closeNet(int fd);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]