gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash/cygnal handler.h handler.cpp ChangeLog


From: Rob Savoye
Subject: [Gnash-commit] gnash/cygnal handler.h handler.cpp ChangeLog
Date: Mon, 17 Mar 2008 00:15:07 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Rob Savoye <rsavoye>    08/03/17 00:15:07

Modified files:
        cygnal         : handler.h handler.cpp ChangeLog 

Log message:
                * handler.{h,cpp}: More queuing support to CQue.
                * testsuite/cygnal.all/test_handler.cpp: Fix test case for new
                queuing style.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/handler.h?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/handler.cpp?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/ChangeLog?cvsroot=gnash&r1=1.5&r2=1.6

Patches:
Index: handler.h
===================================================================
RCS file: /sources/gnash/gnash/cygnal/handler.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- handler.h   16 Mar 2008 01:26:17 -0000      1.1
+++ handler.h   17 Mar 2008 00:15:07 -0000      1.2
@@ -25,13 +25,16 @@
 #include <deque>
 
 #include "log.h"
+#include "network.h"
 #include "buffer.h"
+#include "cque.h"
 
 // _definst_ is the default instance name
 namespace cygnal
 {
 
-class Handler 
+
+class Handler : public gnash::Network
 {
 public:
     Handler();
@@ -41,6 +44,7 @@
     typedef struct {
        int netfd;
        int port;
+       void *handle;
        std::string filespec;
     } thread_params_t ;
     
@@ -48,42 +52,40 @@
     typedef enum { INCOMING, OUTGOING } fifo_e;
     
     // Push bytes on the incoming FIFO, which is the default
-    bool push(boost::uint8_t *data, int nbytes, fifo_e direction);
-    bool push(Buffer *data, fifo_e direction);
     bool push(Buffer *data)
-       { return push(data, INCOMING); };
+       { return _incoming.push(data); };
+    bool push(Buffer *data, fifo_e direction);
+    bool push(uint8_t *data, int nbytes, fifo_e direction);
     bool push(boost::uint8_t *data, int nbytes)
-       { return push(data, nbytes, INCOMING); };
+       { return _incoming.push(data, nbytes); };
     bool pushin(boost::uint8_t *data, int nbytes)
-       { return push(data, nbytes, INCOMING); };
+       { return _incoming.push(data, nbytes); };
     bool pushin(Buffer *data)
-       { return push(data, INCOMING); };
+       { return _incoming.push(data); };
     
     // Push bytes on the incoming FIFO, which must be specified
     bool pushout(boost::uint8_t *data, int nbytes)
-       { return push(data, nbytes, OUTGOING); };
+       { return _outgoing.push(data, nbytes); };
     bool pushout(Buffer *data)
-       { return push(data, OUTGOING); };
+       { return _outgoing.push(data); };
     
     // Pop the first date element off the incoming FIFO
+    Buffer *pop() { return _incoming.pop(); };
     Buffer *pop(fifo_e direction);
-    Buffer *pop()
-       { return pop(INCOMING); };
     Buffer *popin()
-       { return pop(INCOMING); };
+       { return _incoming.pop(); };
     // Pop the first date element off the outgoing FIFO
     Buffer *popout()
-       { return pop(OUTGOING); };
+       { return _incoming.pop(); };
     
     // Peek at the first data element without removing it
+    Buffer *peek() { return _incoming.peek(); };
     Buffer *peek(fifo_e direction);
-    Buffer *peek()
-       { return peek(INCOMING); };
     Buffer *peekin()
-       { return peek(INCOMING); };
+       { return _incoming.peek(); };
     // Pop the first date element off the outgoing FIFO
     Buffer *peekout()
-       { return peek(OUTGOING); };    
+       { return _outgoing.peek(); };    
 
     // Removes all the buffers from the queues
     void clear() { _incoming.clear(); };
@@ -94,25 +96,26 @@
     
     // Return the size of the queues, default to the incoming queue
     size_t size(fifo_e direction);
-    size_t size() { return size(INCOMING); };
+    size_t size() { return _incoming.size(); };
     size_t insize() { return _incoming.size(); };
     size_t outsize() { return _outgoing.size(); };
     
+    // start the two thread handlers for the queues
+    bool start(thread_params_t *args);
+    
     // Dump internal data.
     void dump();
 private:
     int _netfd;
-    boost::condition _inmutex;
-    std::deque<Buffer *> _incoming;
-    
-    std::deque<Buffer *> _outgoing;
-    boost::condition _outmutex;
+    CQue _incoming;
+    CQue _outgoing;
 };
 
 // This is the thread for all incoming network connections, which
 // has to be in C.
 extern "C" {
-    void nethandler(Handler::thread_params_t *args);
+    void netin_handler(Handler::thread_params_t *args);
+    void netout_handler(Handler::thread_params_t *args);
 }
 
 } // end of cygnal namespace

Index: handler.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/handler.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- handler.cpp 16 Mar 2008 01:26:17 -0000      1.1
+++ handler.cpp 17 Mar 2008 00:15:07 -0000      1.2
@@ -20,18 +20,19 @@
 #include "gnashconfig.h"
 #endif
 
+#include <boost/thread/thread.hpp>
 #include <boost/thread/mutex.hpp>
-#include <boost/date_time/gregorian/gregorian.hpp>
-//#include <boost/date_time/local_time/local_time.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-//#include <boost/date_time/time_zone_base.hpp>
+#include <boost/bind.hpp>
 #include <string>
 #include <deque>
 
 #include "log.h"
+#include "network.h"
 #include "buffer.h"
 #include "handler.h"
 
+#include "http.h"
+
 using namespace gnash;
 using namespace std;
 using namespace boost;
@@ -47,17 +48,6 @@
 Handler::~Handler()
 {
 //    GNASH_REPORT_FUNCTION;
-#if 0
-    deque<Buffer *>::iterator it;
-    for (it = _incoming.begin(); it != _incoming.end(); it++) {
-       Buffer *ptr = *(it);
-//     delete ptr;
-    }
-    for (it = _outgoing.begin(); it != _outgoing.end(); it++) {
-       Buffer *ptr = *(it);
-       delete ptr;
-    }
-#endif
 }
 
 bool
@@ -65,11 +55,11 @@
 {
 //    GNASH_REPORT_FUNCTION;
     if (direction == Handler::OUTGOING) {
-       _outgoing.push_back(data);
+       _outgoing.push(data);
        return true;
     }
     if (direction == Handler::INCOMING) {
-       _incoming.push_back(data);
+       _incoming.push(data);
        return true;
     }
     
@@ -94,14 +84,14 @@
     
     if (direction == Handler::OUTGOING) {
        if (_outgoing.size()) {
-           buf = _outgoing.front();
-           _outgoing.pop_front();
+           buf = _outgoing.pop();
+           return buf; 
        }
     }
     if (direction == Handler::INCOMING) {
        if (_incoming.size()) {
-           buf = _incoming.front();
-           _incoming.pop_front();
+           buf = _incoming.pop();
+           return buf; 
        }
     }
 
@@ -115,14 +105,15 @@
 //    GNASH_REPORT_FUNCTION;
     if (direction == Handler::OUTGOING) {
        if (_outgoing.size()) {
-           return _outgoing.front();
+           return _outgoing.peek();
        }
     }
     if (direction == Handler::INCOMING) {
        if (_incoming.size()) {
-           return _incoming.front();
+           return _incoming.peek();
        }
     }    
+    return 0;
 }
 
 // Return the size of the queues
@@ -153,23 +144,81 @@
     }    
 }
 
+// start the two thread handlers for the queues
+bool
+Handler::start(thread_params_t *args)
+{
+//    GNASH_REPORT_FUNCTION;
+    int retries = 10;
+
+    toggleDebug(true);         // FIXME:
+    createServer(args->port);
+    while (retries-- > 0) {
+       log_debug(_("%s: Starting Handlers for port %d"), __PRETTY_FUNCTION__, 
args->port);
+       newConnection(true);
+       args->netfd = getFileFd();
+       args->handle = this;
+
+       log_debug("Starting thread 1");
+       boost::thread inport(boost::bind(&netin_handler, args));
+       
+       log_debug("Starting thread 2");
+       boost::thread outport(boost::bind(&netout_handler, args));
+
+       log_debug("Starting thread 3");
+       boost::thread handler(boost::bind(&httphandler, args));
+
+       inport.join();    
+//     outport.join();
+       handler.join();
+    }
+}
+    
 // Dump internal data.
 void
 Handler::dump()
 {
 //    GNASH_REPORT_FUNCTION;
-    deque<Buffer *>::iterator it;
-    cerr << "Incoming queue has "<< _incoming.size() << " buffers." << endl;
-    for (it = _incoming.begin(); it != _incoming.end(); it++) {
-       Buffer *ptr = *(it);
-        ptr->dump();
-    }
-    cerr << endl << "Outgoing queue has "<< _outgoing.size() << " buffers." << 
endl;
-    for (it = _outgoing.begin(); it != _outgoing.end(); it++) {
-       Buffer *ptr = *(it);
-        ptr->dump();
+    _incoming.dump();
+    _outgoing.dump();    
+}
+
+extern "C" {
+void
+netin_handler(Handler::thread_params_t *args)
+{
+    GNASH_REPORT_FUNCTION;
+
+    Handler *hand = reinterpret_cast<Handler *>(args->handle);
+
+    int retries = 3;
+    while (retries-- >  0) {
+       Buffer *buf = new Buffer;
+       int ret = hand->readNet(args->netfd, buf->reference(), buf->size());
+       if (ret) {
+           if (ret != buf->size()) {
+               buf->resize(ret);
+           }
+           hand->push(buf);
+           string str = (const char *)buf->reference();
+           cerr << str << endl;
+//         _incond.notify_one();
+       } else {
+           break;
     }
+    }
+    hand->dump();
 }
+void
+netout_handler(Handler::thread_params_t *args)
+{
+    GNASH_REPORT_FUNCTION;
+    int retries = 10;
+
+//    _outcond.wait();
+}
+
+} // end of extern C
 
 } // end of cygnal namespace
 
@@ -178,3 +227,4 @@
 // mode: C++
 // indent-tabs-mode: t
 // End:
+

Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/cygnal/ChangeLog,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- ChangeLog   17 Mar 2008 00:09:17 -0000      1.5
+++ ChangeLog   17 Mar 2008 00:15:07 -0000      1.6
@@ -1,5 +1,8 @@
 2008-03-16  Rob Savoye  <address@hidden>
 
+       * handler.{h,cpp}: More queuing support to CQue.
+       * testsuite/cygnal.all/test_handler.cpp: Fix test case for new
+       queuing style.
        * cque.{h,cpp}: New files for base queuing class, moved out of
        Handler when I noticed there was code duplication for the queues.
        * testsuite/cygnal.all/test_cque.cpp: New test case for CQue base




reply via email to

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