gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash/cygnal ChangeLog alloc.cpp buffer.cpp buf...


From: Rob Savoye
Subject: [Gnash-commit] gnash/cygnal ChangeLog alloc.cpp buffer.cpp buf...
Date: Tue, 18 Mar 2008 01:06:05 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Rob Savoye <rsavoye>    08/03/18 01:06:04

Modified files:
        cygnal         : ChangeLog alloc.cpp buffer.cpp buffer.h 
                         cque.cpp cque.h cygnal.cpp handler.cpp 
                         handler.h http.cpp http.h stream.cpp 
        cygnal/testsuite/cygnal.all: test_buffer.cpp test_cque.cpp 

Log message:
                * alloc.cpp: Don't use thrrad safe wrappers for now.
                * buffer.cpp: Move BUFFERSIZE to network.h. Use Network::byte_t
                instead of boost_uint8_t directly.
                * buffer.h: Use Network::byte_t instead of boost_uint8_t
                directly.
                * cque.{h,cpp}: Add remove and merge methods for manipuating
                buffers in the que. Add support for using boost condition
                variables as triggers for I/O in the que.
                * cygnal.cpp: Use new Handler and Buffer classes instead of the
                old threads. Move http_handler to http.cpp.
                * handler.{h,cpp}: Add output thread handler. Use 
Network::byte_t
                instead of boost_uint8_t directly.
                * http.cpp:  Use Network::byte_t instead of boost_uint8_t
                directly. Use const std::string & instead of const char *. Add
                http_handler from cygnal.cpp.
                * testsuite/cygnal.all/test_cque.cpp: Add tests for new remove 
and
                mege methods.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/ChangeLog?cvsroot=gnash&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/alloc.cpp?cvsroot=gnash&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/buffer.cpp?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/buffer.h?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/cque.cpp?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/cque.h?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/cygnal.cpp?cvsroot=gnash&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/handler.cpp?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/handler.h?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/http.cpp?cvsroot=gnash&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/http.h?cvsroot=gnash&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/stream.cpp?cvsroot=gnash&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/testsuite/cygnal.all/test_buffer.cpp?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/testsuite/cygnal.all/test_cque.cpp?cvsroot=gnash&r1=1.1&r2=1.2

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/cygnal/ChangeLog,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- ChangeLog   17 Mar 2008 00:15:07 -0000      1.6
+++ ChangeLog   18 Mar 2008 01:06:03 -0000      1.7
@@ -1,3 +1,23 @@
+2008-03-17  Rob Savoye  <address@hidden>
+
+       * alloc.cpp: Don't use thrrad safe wrappers for now.
+       * buffer.cpp: Move BUFFERSIZE to network.h. Use Network::byte_t
+       instead of boost_uint8_t directly.
+       * buffer.h: Use Network::byte_t instead of boost_uint8_t
+       directly.
+       * cque.{h,cpp}: Add remove and merge methods for manipuating
+       buffers in the que. Add support for using boost condition
+       variables as triggers for I/O in the que.
+       * cygnal.cpp: Use new Handler and Buffer classes instead of the
+       old threads. Move http_handler to http.cpp.
+       * handler.{h,cpp}: Add output thread handler. Use Network::byte_t
+       instead of boost_uint8_t directly.
+       * http.cpp:  Use Network::byte_t instead of boost_uint8_t
+       directly. Use const std::string & instead of const char *. Add
+       http_handler from cygnal.cpp.
+       * testsuite/cygnal.all/test_cque.cpp: Add tests for new remove and
+       mege methods.
+
 2008-03-16  Rob Savoye  <address@hidden>
 
        * handler.{h,cpp}: More queuing support to CQue.

Index: alloc.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/alloc.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- alloc.cpp   21 Jan 2008 20:56:06 -0000      1.6
+++ alloc.cpp   18 Mar 2008 01:06:03 -0000      1.7
@@ -26,6 +26,7 @@
 
 static boost::mutex mem_mutex;
 
+#if 0
 // Wrap new in a mutex, because it is not thread safe.
 void *
 operator new (std::size_t bytes) throw (std::bad_alloc) {
@@ -40,7 +41,7 @@
     boost::mutex::scoped_lock lock(mem_mutex);
     free (vptr);
 }
-
+#endif
 
 // local Variables:
 // mode: C++

Index: buffer.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/buffer.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- buffer.cpp  16 Mar 2008 01:26:17 -0000      1.1
+++ buffer.cpp  18 Mar 2008 01:06:03 -0000      1.2
@@ -19,21 +19,20 @@
 #include <boost/cstdint.hpp>
 #include "buffer.h"
 #include "log.h"
+#include "network.h"
 
 using namespace std;
+using namespace gnash;
 
 namespace cygnal
 {
 
-// Adjust for the constant size
-const size_t BUFFERSIZE = 128;
-
 void *
 Buffer::init(size_t nbytes)
 {
 //    GNASH_REPORT_FUNCTION;
     if (_ptr == 0) {
-        _ptr = new boost::uint8_t[nbytes];
+        _ptr = new Network::byte_t[nbytes];
         _nbytes = nbytes;
         // this could be a performance hit, but for debugging we leave it in 
so we get
         // easier to ready hex dumps in GDB,
@@ -47,8 +46,8 @@
 {
 //    GNASH_REPORT_FUNCTION;
     _ptr = 0;
-    _nbytes = BUFFERSIZE;
-    init(BUFFERSIZE);
+    _nbytes = gnash::NETBUFSIZE;
+    init(gnash::NETBUFSIZE);
 }
     
 // Create with a size other than the default
@@ -73,7 +72,7 @@
 
 // Put data into the buffer
 void
-Buffer::copy(boost::uint8_t *data, int nbytes)
+Buffer::copy(Network::byte_t *data, int nbytes)
 {    
 //    GNASH_REPORT_FUNCTION;
     std::copy(data, data + nbytes, _ptr);
@@ -110,6 +109,7 @@
 bool
 Buffer::operator==(Buffer *buf)
 {
+//    GNASH_REPORT_FUNCTION;
     if (buf->size() == _nbytes) {
         if (memcmp(buf->reference(), _ptr, _nbytes) == 0)  {
             return true;
@@ -121,6 +121,7 @@
 bool
 Buffer::operator==(Buffer &buf)
 {
+//    GNASH_REPORT_FUNCTION;
     if (buf.size() == _nbytes){
         if (memcmp(buf.reference(), _ptr, _nbytes) == 0)  {
             return true;
@@ -143,8 +144,9 @@
 void *
 Buffer::resize(size_t nbytes)
 {
+    GNASH_REPORT_FUNCTION;
     // Allocate a new memory block
-    boost::uint8_t *tmp = new boost::uint8_t[nbytes];
+    Network::byte_t *tmp = new Network::byte_t[nbytes];
     // And copy ourselves into it
     if (nbytes > _nbytes) {
         std::copy(_ptr, _ptr + _nbytes, tmp);
@@ -169,6 +171,7 @@
 Buffer::dump()
 {
     cerr << "Buffer is " << _nbytes << " bytes at " << (void *)_ptr << endl;
+    cerr << gnash::hexify((unsigned char *)_ptr, _nbytes, true) << endl;
 }
 
 } // end of cygnal namespace

Index: buffer.h
===================================================================
RCS file: /sources/gnash/gnash/cygnal/buffer.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- buffer.h    16 Mar 2008 01:26:17 -0000      1.1
+++ buffer.h    18 Mar 2008 01:06:03 -0000      1.2
@@ -20,6 +20,8 @@
 #define __BUFFER_H__ 1
 
 #include <boost/cstdint.hpp>
+#include <string>
+#include "network.h"
 
 // _definst_ is the default instance name
 namespace cygnal
@@ -40,10 +42,10 @@
     void *resize(size_t nbytes);
 
     // Put data into the buffer
-    void copy(boost::uint8_t *data, int nbytes);
+    void copy(gnash::Network::byte_t *data, int nbytes);
     
     // Accessors
-    boost::uint8_t *reference() { return _ptr; }
+    gnash::Network::byte_t *reference() { return _ptr; }
     size_t size() { return _nbytes; }
     void setSize(size_t nbytes) { _nbytes = nbytes; };
     
@@ -55,13 +57,13 @@
     bool operator==(Buffer *buf);
     bool operator==(Buffer &buf);
 
-    boost::uint8_t operator[](int x) { return _ptr[x]; };
+    gnash::Network::byte_t operator[](int x) { return _ptr[x]; };
     
     // debug stuff, not need for running Cygnal
     void dump();
 private:
     void *init(size_t nbytes);
-    boost::uint8_t *_ptr;
+    gnash::Network::byte_t *_ptr;
     int         _nbytes;
 };
 

Index: cque.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/cque.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- cque.cpp    17 Mar 2008 00:09:17 -0000      1.1
+++ cque.cpp    18 Mar 2008 01:06:03 -0000      1.2
@@ -21,6 +21,7 @@
 #endif
 
 #include <string>
+#include <vector>
 #include <deque>
 
 #include "log.h"
@@ -53,10 +54,29 @@
 #endif
 }
 
+// Wait for a condition variable to trigger
+void
+CQue::wait()
+{
+    GNASH_REPORT_FUNCTION;
+    boost::mutex::scoped_lock lk(_cond_mutex);
+    _cond.wait(lk);
+    log_debug("wait mutex released");
+}
+
+// Notify a condition variable to trigger
+void
+CQue::notify()
+{
+    GNASH_REPORT_FUNCTION;
+    _cond.notify_one();
+    log_debug("wait mutex triggered");
+}
+
 size_t
 CQue::size()
 {
-//    GNASH_REPORT_FUNCTION;
+    GNASH_REPORT_FUNCTION;
     boost::mutex::scoped_lock lock(_mutex);
     return _que.size();
 }
@@ -64,7 +84,7 @@
 bool
 CQue::push(Buffer *data)
 {
-//    GNASH_REPORT_FUNCTION;
+    GNASH_REPORT_FUNCTION;
     boost::mutex::scoped_lock lock(_mutex);
     _que.push_back(data);
     return true;
@@ -72,9 +92,9 @@
 
 // Push bytes on the outgoing FIFO
 bool
-CQue::push(uint8_t *data, int nbytes)
+CQue::push(gnash::Network::byte_t *data, int nbytes)
 {
-//    GNASH_REPORT_FUNCTION;
+    GNASH_REPORT_FUNCTION;
     Buffer *buf = new Buffer;
     std::copy(data, data + nbytes, buf->reference());
 }
@@ -84,7 +104,7 @@
 Buffer *
 CQue::pop()
 {
-//    GNASH_REPORT_FUNCTION;
+    GNASH_REPORT_FUNCTION;
     Buffer *buf;
     boost::mutex::scoped_lock lock(_mutex);
     if (_que.size()) {
@@ -98,7 +118,7 @@
 Buffer *
 CQue::peek()
 {
-//    GNASH_REPORT_FUNCTION;
+    GNASH_REPORT_FUNCTION;
     boost::mutex::scoped_lock lock(_mutex);
     if (_que.size()) {
         return _que.front();
@@ -115,6 +135,85 @@
     _que.clear();
 }
     
+// Remove a range of elements
+void
+CQue::remove(Buffer *begin, Buffer *end)
+{
+    GNASH_REPORT_FUNCTION;
+    deque<Buffer *>::iterator it;
+    deque<Buffer *>::iterator start;
+    deque<Buffer *>::iterator stop;
+    boost::mutex::scoped_lock lock(_mutex);
+    Buffer *ptr;
+    for (it = _que.begin(); it != _que.end(); it++) {
+       ptr = *(it);
+       if (ptr->reference() == begin->reference()) {
+           start = it;
+       }
+       if (ptr->reference() == end->reference()) {
+           stop = it;
+           break;
+       }
+    }
+    _que.erase(start, stop);
+}
+
+// Remove an element
+void
+CQue::remove(Buffer *element)
+{
+    GNASH_REPORT_FUNCTION;
+    deque<Buffer *>::iterator it;
+    boost::mutex::scoped_lock lock(_mutex);
+    for (it = _que.begin(); it != _que.end(); it++) {
+       Buffer *ptr = *(it);
+       if (ptr->reference() == element->reference()) {
+           _que.erase(it);
+       }
+    }
+}
+
+// Merge sucessive buffers into one single larger buffer. This is for some
+// protocols, than have very long headers.
+Buffer *
+CQue::merge(Buffer *begin)
+{
+    GNASH_REPORT_FUNCTION;
+    int totalsize = 0;
+    deque<Buffer *>::iterator it;
+    vector<deque<Buffer *>::iterator> elements;
+    vector<deque<Buffer *>::iterator>::iterator eit;
+    boost::mutex::scoped_lock lock(_mutex);
+    for (it = _que.begin(); it != _que.end(); it++) {
+       Buffer *ptr = *(it);
+       if (totalsize > 0) {
+           totalsize += ptr->size();
+           elements.push_back(it);
+           if (ptr->size() < gnash::NETBUFSIZE) {
+               Buffer *newbuf = new Buffer(totalsize);
+               Network::byte_t *tmp = newbuf->reference();
+               Buffer *buf;
+//             _que.insert(elements.begin(), newbuf);
+               for (eit = elements.begin(); eit != elements.end(); eit++) {
+                   deque<Buffer *>::iterator ita = *(eit);
+                   buf = *(ita);
+                   std::copy(buf->reference(), buf->reference() + buf->size(), 
tmp);
+                   tmp += buf->size();
+                   _que.erase(ita);
+               }
+               _que.push_back(newbuf);
+               return newbuf;
+           }
+           continue;
+       }
+       if (ptr->reference() == begin->reference()) {
+           totalsize = ptr->size();
+           elements.push_back(it);
+       }
+    }
+    return 0;
+}
+
 // Dump internal data.
 void
 CQue::dump()
@@ -122,7 +221,7 @@
 //    GNASH_REPORT_FUNCTION;
     deque<Buffer *>::iterator it;
     boost::mutex::scoped_lock lock(_mutex);
-    cerr << endl << "Outgoing queue has "<< _que.size() << " buffers." << endl;
+    cerr << endl << "CQue has "<< _que.size() << " buffers." << endl;
     for (it = _que.begin(); it != _que.end(); it++) {
        Buffer *ptr = *(it);
         ptr->dump();

Index: cque.h
===================================================================
RCS file: /sources/gnash/gnash/cygnal/cque.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- cque.h      17 Mar 2008 00:09:17 -0000      1.1
+++ cque.h      18 Mar 2008 01:06:04 -0000      1.2
@@ -25,6 +25,7 @@
 #include <deque>
 
 #include "buffer.h"
+#include "network.h"
 
 // _definst_ is the default instance name
 namespace cygnal
@@ -35,7 +36,7 @@
     CQue();
     ~CQue();
     // Push data onto the que
-    bool push(boost::uint8_t *data, int nbytes);
+    bool push(gnash::Network::byte_t *data, int nbytes);
     bool push(Buffer *data);
     // Pop the first date element off the que
     Buffer *pop();
@@ -49,6 +50,14 @@
     void notify();
     // Empty the que of all data. 
     void clear();
+    // Remove a range of elements
+    void remove(Buffer *begin, Buffer *end);
+//     // Remove an element
+//    void remove(Buffer *it);
+    void remove(Buffer *it);
+    // Merge sucessive buffers into one single larger buffer. This is for some
+    // protocols, than have very long headers.
+    Buffer *merge(Buffer *begin);
     // Dump the data to the terminal
     void dump();
 private:

Index: cygnal.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/cygnal.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- cygnal.cpp  29 Feb 2008 22:20:08 -0000      1.23
+++ cygnal.cpp  18 Mar 2008 01:06:04 -0000      1.24
@@ -22,11 +22,16 @@
 #include "gnashconfig.h"
 #endif
 
+#include <list>
 #include <iostream>
 #include <signal.h>
 #include <vector>
 #include <sys/mman.h>
 #include <cerrno>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <gettext.h>
 
 extern "C"{
 # include <unistd.h>
@@ -39,6 +44,7 @@
 #endif
 }
 
+// classes internal to Gnash
 #include "network.h"
 #include "log.h"
 #include "crc.h"
@@ -48,11 +54,11 @@
 #include "netstats.h"
 #include "statistics.h"
 #include "stream.h"
+#include "gmemory.h"
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include "gettext.h"
+// classes internal to Cygnal
+#include "buffer.h"
+#include "handler.h"
 
 #ifdef ENABLE_NLS
 #include <locale.h>
@@ -85,13 +91,6 @@
 LogFile& dbglogfile = LogFile::getDefaultInstance();
 CRcInitFile& crcfile = CRcInitFile::getDefaultInstance();
 
-struct thread_params {
-    int netfd;
-    int port;
-    char filespec[256];
-    Statistics *statistics;
-};
-
 static struct sigaction  act;
 
 // The next few global variables have to be global because Boost
@@ -110,8 +109,10 @@
 // conflict with apache on the same machine.
 static int port_offset = 0;
 
-// end of globals
+// Keep a list of all active network connections
+static map<std::string, Handler *> _handlers;
 
+// end of globals
 
 int
 main(int argc, char *argv[])
@@ -180,6 +181,7 @@
         }
     }
     
+    dbglogfile.setLogFilename("cygnal-dbg.log");
 
     // get the file name from the command line
     while (optind < argc) {
@@ -190,13 +192,21 @@
     act.sa_handler = cntrlc_handler;
     sigaction (SIGINT, &act, NULL);
 
-    struct thread_params rtmp_data;
-    struct thread_params http_data;
-    struct thread_params ssl_data;
-    rtmp_data.port = port_offset + 1935;
+    Handler::thread_params_t http_data;
+//     struct thread_params rtmp_data;
+//     struct thread_params ssl_data;
+//     rtmp_data.port = port_offset + 1935;
 //    boost::thread rtmp_port(boost::bind(&rtmp_thread, &rtmp_data));
 
+    Handler hand;
+    http_data.netfd = 0;
     http_data.port = port_offset + 80;
+    http_data.handle = &hand;
+    http_data.filespec = docroot;
+    hand.start(&http_data);
+    
+//    boost::thread http_port(boost::bind(&nethandler, &http_data));
+#if 0
     Statistics st;
     http_data.statistics = &st;
     boost::thread http_port(boost::bind(&http_thread, &http_data));
@@ -207,10 +217,11 @@
 //    boost::thread rtmp_port(&rtmp_thread);
 //    boost::thread http_port(&http_thread);
 //    boost::thread ssl_port(&ssl_thread);
+#endif
 
     // wait for the thread to finish
 //    rtmp_port.join();
-    http_port.join();
+//    http_port.join();
 //    ssl_port.join();
 
     log_debug (_("All done I think..."));
@@ -218,66 +229,6 @@
     return(0);
 }
 
-static void
-http_thread(struct thread_params *conndata)
-{
-    GNASH_REPORT_FUNCTION;
-    int retries = 0;
-    HTTP www;
-//    struct thread_params thread_data;
-    string url, filespec, parameters;
-    string::size_type pos;
-    int port = RTMPT + port_offset;
-
-    www.toggleDebug(true);
-    
-    www.createServer(port);
-    while (retries++ < thread_retries) {
-       log_debug(_("%s: Thread for port %d looping..."), __PRETTY_FUNCTION__, 
port);
-       www.newConnection(true);
-
-       conndata->statistics->setFileType(NetStats::RTMPT);
-       conndata->statistics->startClock();
-       conndata->netfd = www.getFileFd();
-       url = docroot;
-       url += www.waitForGetRequest();
-       pos = url.find("?");
-       filespec = url.substr(0, pos);
-       parameters = url.substr(pos + 1, url.size());
-       // Get the file size for the HTTP header
-       
-       if (www.getFileStats(filespec) == HTTP::ERROR) {
-           www.formatErrorResponse(HTTP::NOT_FOUND);
-       }
-       www.sendGetReply(HTTP::LIFE_IS_GOOD);
-//     strcpy(thread_data.filespec, filespec.c_str());
-//     thread_data.statistics = conndata->statistics;
-       
-       // Keep track of the network statistics
-       conndata->statistics->stopClock();
-//     log_debug (_("Bytes read: %d"), www.getBytesIn());
-//     log_debug (_("Bytes written: %d"), www.getBytesOut());
-//     st.setBytes(www.getBytesIn() + www.getBytesOut());
-       conndata->statistics->addStats();
-//     www.resetBytesIn();
-//     www.resetBytesOut();
-       
-       if (url != docroot) {
-           log_debug (_("File to load is: %s"), filespec.c_str());
-           log_debug (_("Parameters are: %s"), parameters.c_str());
-           memset(conndata->filespec, 0, 256);
-           memcpy(conndata->filespec, filespec.c_str(), filespec.size());
-           boost::thread sendthr(boost::bind(&stream_thread, conndata));
-           sendthr.join();
-       }
-       // See if this is a persistant connection
-//     if (!www.keepAlive()) {
-//         www.closeConnection();
-//     }
-       conndata->statistics->dump();
-    }
-}
-
 #if 0
 static void
 rtmp_thread(struct thread_params *conndata)
@@ -341,6 +292,7 @@
 }
 #endif
 
+#if 0
 static void
 stream_thread(struct  thread_params *params)
 {
@@ -352,11 +304,11 @@
     log_debug ("%s: %s", __PRETTY_FUNCTION__, params->filespec);
     
     Stream str;
-    str.open(params->filespec, params->netfd, params->statistics);
+    str.open(params->filespec, params->netfd);
     str.play();
 //    ::close(params->netfd);
 }
-
+#endif
 
 // Trap Control-C so we can cleanly exit
 static void

Index: handler.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/handler.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- handler.cpp 17 Mar 2008 00:15:07 -0000      1.2
+++ handler.cpp 18 Mar 2008 01:06:04 -0000      1.3
@@ -68,7 +68,7 @@
 
 // Push bytes on the outgoing FIFO
 bool
-Handler::push(uint8_t *data, int nbytes, fifo_e direction)
+Handler::push(gnash::Network::byte_t *data, int nbytes, fifo_e direction)
 {
 //    GNASH_REPORT_FUNCTION;
     Buffer *ptr = new Buffer;
@@ -194,28 +194,35 @@
     int retries = 3;
     while (retries-- >  0) {
        Buffer *buf = new Buffer;
-       int ret = hand->readNet(args->netfd, buf->reference(), buf->size());
-       if (ret) {
+       int ret = hand->readNet(buf->reference(), buf->size());
+       if (ret > 0) {
            if (ret != buf->size()) {
                buf->resize(ret);
            }
            hand->push(buf);
-           string str = (const char *)buf->reference();
-           cerr << str << endl;
-//         _incond.notify_one();
+//         string str = (const char *)buf->reference();
+//         cerr << str << endl;
+           hand->notify();
        } else {
            break;
        }
     }
-    hand->dump();
+//    hand->dump();
 }
 void
 netout_handler(Handler::thread_params_t *args)
 {
     GNASH_REPORT_FUNCTION;
     int retries = 10;
+    int ret;
+    
+    do {
+       Handler *hand = reinterpret_cast<Handler *>(args->handle);
+       hand->wait();
+       Buffer *buf = hand->popout();
+       ret = hand->writeNet(buf);
+    } while (ret > 0);
 
-//    _outcond.wait();
 }
 
 } // end of extern C

Index: handler.h
===================================================================
RCS file: /sources/gnash/gnash/cygnal/handler.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- handler.h   17 Mar 2008 00:15:07 -0000      1.2
+++ handler.h   18 Mar 2008 01:06:04 -0000      1.3
@@ -28,6 +28,7 @@
 #include "network.h"
 #include "buffer.h"
 #include "cque.h"
+#include "network.h"
 
 // _definst_ is the default instance name
 namespace cygnal
@@ -55,16 +56,16 @@
     bool push(Buffer *data)
        { 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)
+    bool push(gnash::Network::byte_t *data, int nbytes, fifo_e direction);
+    bool push(gnash::Network::byte_t *data, int nbytes)
        { return _incoming.push(data, nbytes); };
-    bool pushin(boost::uint8_t *data, int nbytes)
+    bool pushin(gnash::Network::byte_t *data, int nbytes)
        { return _incoming.push(data, nbytes); };
     bool pushin(Buffer *data)
        { return _incoming.push(data); };
     
     // Push bytes on the incoming FIFO, which must be specified
-    bool pushout(boost::uint8_t *data, int nbytes)
+    bool pushout(gnash::Network::byte_t *data, int nbytes)
        { return _outgoing.push(data, nbytes); };
     bool pushout(Buffer *data)
        { return _outgoing.push(data); };
@@ -76,7 +77,7 @@
        { return _incoming.pop(); };
     // Pop the first date element off the outgoing FIFO
     Buffer *popout()
-       { return _incoming.pop(); };
+       { return _outgoing.pop(); };
     
     // Peek at the first data element without removing it
     Buffer *peek() { return _incoming.peek(); };
@@ -100,9 +101,26 @@
     size_t insize() { return _incoming.size(); };
     size_t outsize() { return _outgoing.size(); };
 
+    // Notify the other thread a message is in the que
+    void notify() { _incoming.notify(); };
+    void notifyin() { _incoming.notify(); };
+    void notifyout() { _outgoing.notify(); };
+
+    // Wait for a message from the other thread
+    void wait() { _incoming.wait(); };
+    void waitin() { _incoming.wait(); };
+    void waitout() { _outgoing.wait(); };
+
     // start the two thread handlers for the queues
     bool start(thread_params_t *args);
     
+    // Take a buffer and write it to the network
+    int writeNet(int fd, Buffer *buf)
+       { Network::writeNet(fd, buf->reference(), buf->size()); };
+    
+    int writeNet(Buffer *buf)
+       { Network::writeNet(buf->reference(), buf->size()); };
+    
     // Dump internal data.
     void dump();
 private:

Index: http.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/http.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- http.cpp    29 Feb 2008 22:20:08 -0000      1.17
+++ http.cpp    18 Mar 2008 01:06:04 -0000      1.18
@@ -34,6 +34,8 @@
 #include "http.h"
 #include "log.h"
 
+#include "handler.h"
+
 using namespace gnash;
 using namespace std;
 
@@ -95,7 +97,8 @@
 {
     GNASH_REPORT_FUNCTION;
 
-    char buffer[readsize+1];
+    byte_t buffer[readsize+1];
+    const char *ptr = reinterpret_cast<const char *>(buffer);
     memset(buffer, 0, readsize+1);
     if (readNet(buffer, readsize) > 0) {
         log_debug (_("Read initial GET Request"));
@@ -104,20 +107,20 @@
     }
 
     clearHeader();
-    extractAccept(buffer);
-    extractMethod(buffer);
-    extractReferer(buffer);
-    extractHost(buffer);
-    extractAgent(buffer);
-    extractLanguage(buffer);
-    extractCharset(buffer);
-    extractConnection(buffer);
-    extractEncoding(buffer);
-    extractTE(buffer);
+    extractAccept(ptr);
+    extractMethod(ptr);
+    extractReferer(ptr);
+    extractHost(ptr);
+    extractAgent(ptr);
+    extractLanguage(ptr);
+    extractCharset(ptr);
+    extractConnection(ptr);
+    extractEncoding(ptr);
+    extractTE(ptr);
     dump();
 
     // See if we got a legit GET request
-    if (strncmp(buffer, "GET ", 4) == 0) {
+    if (strncmp(ptr, "GET ", 4) == 0) {
         log_debug (_("Got legit GET request"));
     } else {
         log_error (_("Got bogus GET request"));
@@ -220,7 +223,7 @@
 }
 
 bool
-HTTP::formatServer(const char *data)
+HTTP::formatServer(const string &data)
 {
     GNASH_REPORT_FUNCTION;
     _header << "Server: " << data << endl;
@@ -228,7 +231,7 @@
 }
 
 bool
-HTTP::formatMethod(const char *data)
+HTTP::formatMethod(const string &data)
 {
     GNASH_REPORT_FUNCTION;
     _header << "Method: " << data << endl;
@@ -236,7 +239,7 @@
 }
 
 bool
-HTTP::formatReferer(const char *refer)
+HTTP::formatReferer(const string &refer)
 {
     GNASH_REPORT_FUNCTION;
     _header << "Referer: " << refer << endl;
@@ -244,7 +247,7 @@
 }
 
 bool
-HTTP::formatConnection(const char *options)
+HTTP::formatConnection(const string &options)
 {
     GNASH_REPORT_FUNCTION;
     _header << "Connection: " << options << endl;
@@ -299,7 +302,7 @@
 }
 
 bool
-HTTP::formatHost(const char *host)
+HTTP::formatHost(const string &host)
 {
 //    GNASH_REPORT_FUNCTION;
     _header << "Host: " << host << endl;
@@ -307,7 +310,7 @@
 }
 
 bool
-HTTP::formatAgent(const char *agent)
+HTTP::formatAgent(const string &agent)
 {
 //    GNASH_REPORT_FUNCTION;
     _header << "User-Agent: " << agent << endl;
@@ -315,7 +318,7 @@
 }
 
 bool
-HTTP::formatLanguage(const char *lang)
+HTTP::formatLanguage(const string &lang)
 {
 //    GNASH_REPORT_FUNCTION;
 
@@ -325,7 +328,7 @@
 }
 
 bool
-HTTP::formatCharset(const char *set)
+HTTP::formatCharset(const string &set)
 {
     GNASH_REPORT_FUNCTION;
     // For some browsers this appears to also be Content-Charset
@@ -334,7 +337,7 @@
 }
 
 bool
-HTTP::formatEncoding(const char *code)
+HTTP::formatEncoding(const string &code)
 {
     GNASH_REPORT_FUNCTION;
     _header << "Accept-Encoding: " << code << endl;
@@ -342,7 +345,7 @@
 }
 
 bool
-HTTP::formatTE(const char *te)
+HTTP::formatTE(const string &te)
 {
     GNASH_REPORT_FUNCTION;
     _header << "TE: " << te << endl;
@@ -355,9 +358,9 @@
     GNASH_REPORT_FUNCTION;
     
     formatHeader(_filesize, HTML);
-    int ret = writeNet(_header.str().c_str(), _header.str().size());
+    int ret = Network::writeNet(_header.str());
     if ( _body.str().size() > 0) {
-       ret += writeNet(_body.str().c_str(), _body.str().size());
+       ret += Network::writeNet(_body.str());
     }
 
     if (ret >= 0) {
@@ -373,7 +376,7 @@
 }
 
 bool
-HTTP::formatRequest(const char *url, http_method_e req)
+HTTP::formatRequest(const string &url, http_method_e req)
 {
     GNASH_REPORT_FUNCTION;
 
@@ -858,6 +861,69 @@
     log_debug (_("==== ==== ===="));
 }
 
+extern "C" {
+void
+httphandler(Handler::thread_params_t *args)
+{
+    GNASH_REPORT_FUNCTION;
+    int retries = 10;
+    HTTP www;
+//    struct thread_params thread_data;
+    string url, filespec, parameters;
+    string::size_type pos;
+    Handler *hand = reinterpret_cast<Handler *>(args->handle);
+//    hand->_outcond.wait();
+
+//     www.toggleDebug(true);
+    
+//     www.createServer(args->port);
+//     while (retries-- > 0) {
+//     log_debug(_("%s: Thread for port %d looping..."), __PRETTY_FUNCTION__, 
args->port);
+//     www.newConnection(true);
+
+       string docroot = args->filespec;
+       
+//     conndata->statistics->setFileType(NetStats::RTMPT);
+//     conndata->statistics->startClock();
+       args->netfd = www.getFileFd();
+       url = docroot;
+       url += www.waitForGetRequest();
+       pos = url.find("?");
+       filespec = url.substr(0, pos);
+       parameters = url.substr(pos + 1, url.size());
+       // Get the file size for the HTTP header
+       
+       if (www.getFileStats(filespec) == HTTP::ERROR) {
+           www.formatErrorResponse(HTTP::NOT_FOUND);
+       }
+       www.sendGetReply(HTTP::LIFE_IS_GOOD);
+//     strcpy(thread_data.filespec, filespec.c_str());
+//     thread_data.statistics = conndata->statistics;
+       
+       // Keep track of the network statistics
+//     conndata->statistics->stopClock();
+//     log_debug (_("Bytes read: %d"), www.getBytesIn());
+//     log_debug (_("Bytes written: %d"), www.getBytesOut());
+//     st.setBytes(www.getBytesIn() + www.getBytesOut());
+//     conndata->statistics->addStats();
+       
+       if (url != docroot) {
+           log_debug (_("File to load is: %s"), filespec.c_str());
+           log_debug (_("Parameters are: %s"), parameters.c_str());
+//         memset(args->filespec, 0, 256);
+//         memcpy(->filespec, filespec.c_str(), filespec.size());
+//         boost::thread sendthr(boost::bind(&stream_thread, args));
+//         sendthr.join();
+       }
+       // See if this is a persistant connection
+//     if (!www.keepAlive()) {
+//         www.closeConnection();
+//     }
+//     conndata->statistics->dump();
+//    }
+}
+} // end of extern C
+
 } // end of cygnal namespace
 
 

Index: http.h
===================================================================
RCS file: /sources/gnash/gnash/cygnal/http.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- http.h      29 Feb 2008 22:20:08 -0000      1.13
+++ http.h      18 Mar 2008 01:06:04 -0000      1.14
@@ -1,5 +1,5 @@
 // 
-//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+//   Copyright (C) 2007, 2008 Free Software Foundation, Inc.
 // 
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -23,15 +23,17 @@
 #include "gnashconfig.h"
 #endif
 
-#include "network.h"
 #include <string>
 #include <map>
 #include <vector>
 
+#include "handler.h"
+#include "network.h"
+
 namespace cygnal
 {
     
-class HTTP : public gnash::Network
+class HTTP : public Handler
 {
 public:
 // as defined by the W3: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
@@ -113,7 +115,7 @@
     HTTP();
     ~HTTP();
     std::string waitForGetRequest();
-    std::string waitForGetRequest(Network &net);
+    std::string waitForGetRequest(gnash::Network &net);
     
     // Handle the GET request response
     bool sendGetReply(http_status_e code);
@@ -142,23 +144,23 @@
     bool clearHeader();
     bool formatHeader(int filesize, const short type);
     bool formatHeader(const short type);
-    bool formatRequest(const char *url, http_method_e req);
-    bool formatMethod(const char *data);
+    bool formatRequest(const std::string &url, http_method_e req);
+    bool formatMethod(const std::string &data);
     bool formatDate();
     bool formatServer();
-    bool formatServer(const char *data);
-    bool formatReferer(const char *data);
-    bool formatConnection(const char *data);
+    bool formatServer(const std::string &data);
+    bool formatReferer(const std::string &data);
+    bool formatConnection(const std::string &data);
     bool formatContentLength();
     bool formatContentLength(int filesize);
     bool formatContentType();
     bool formatContentType(filetype_e type);
-    bool formatHost(const char *data);
-    bool formatAgent(const char *data);
-    bool formatLanguage(const char *data);
-    bool formatCharset(const char *data);
-    bool formatEncoding(const char *data);
-    bool formatTE(const char *data);
+    bool formatHost(const std::string &data);
+    bool formatAgent(const std::string &data);
+    bool formatLanguage(const std::string &data);
+    bool formatCharset(const std::string &data);
+    bool formatEncoding(const std::string &data);
+    bool formatTE(const std::string &data);
 
     bool formatErrorResponse(http_status_e err);
     
@@ -222,6 +224,13 @@
 //    bool     _te;
 };  
     
+// This is the thread for all incoming HTTP connections, which
+// has to be in C.
+extern "C" {
+    void httphandler(Handler::thread_params_t *args);
+}
+
+
 } // end of cygnal namespace
 
 // end of _HTTP_H_

Index: stream.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/stream.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- stream.cpp  19 Feb 2008 19:20:48 -0000      1.10
+++ stream.cpp  18 Mar 2008 01:06:04 -0000      1.11
@@ -258,7 +258,7 @@
     int nbytes = 0;
     Network net;
 //    while ((_seekptr - _dataptr) >= 0) {
-    nbytes = net.writeNet(_netfd, (char *)_seekptr, _filesize);
+////    nbytes = net.writeNet(_netfd, (char *)_seekptr, _filesize);
 //    if (nbytes <= 0) {
 //        break;
 //    }

Index: testsuite/cygnal.all/test_buffer.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/testsuite/cygnal.all/test_buffer.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- testsuite/cygnal.all/test_buffer.cpp        16 Mar 2008 01:26:17 -0000      
1.1
+++ testsuite/cygnal.all/test_buffer.cpp        18 Mar 2008 01:06:04 -0000      
1.2
@@ -36,6 +36,7 @@
 #endif
 
 #include "log.h"
+#include "network.h"
 #include "gmemory.h"
 #include "buffer.h"
 
@@ -47,9 +48,6 @@
 TestState runtest;
 LogFile& dbglogfile = LogFile::getDefaultInstance();
 
-// This must match the value in buffer.h
-const size_t BUFFERSIZE = 128;
-
 int
 main (int /*argc*/, char** /*argv*/) {
     gnash::LogFile& dbglogfile = gnash::LogFile::getDefaultInstance();
@@ -63,7 +61,7 @@
     Buffer buf;
     mem.addStats(__LINE__);             // take a sample
     
-    if (buf.size() == BUFFERSIZE) {
+    if (buf.size() == gnash::NETBUFSIZE) {
          runtest.pass ("Buffer::size()");
      } else {
          runtest.fail ("Buffer::size()");

Index: testsuite/cygnal.all/test_cque.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/testsuite/cygnal.all/test_cque.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- testsuite/cygnal.all/test_cque.cpp  17 Mar 2008 00:09:17 -0000      1.1
+++ testsuite/cygnal.all/test_cque.cpp  18 Mar 2008 01:06:04 -0000      1.2
@@ -45,6 +45,7 @@
 #endif
 
 #include "log.h"
+#include "network.h"
 #include "cque.h"
 
 using namespace std;
@@ -63,6 +64,12 @@
     CQue que;
 
     Buffer buf;
+    // populate the buffer
+    boost::uint8_t *ptr = buf.reference();
+    for (size_t i=1; i< buf.size(); i++) {
+        ptr[i] = i+' ';
+    }
+
     boost::uint8_t *test = new uint8_t[6];
     memcpy(test, "hell", 4);
 
@@ -94,11 +101,6 @@
         runtest.fail ("CQue::clearall()");
     }
 
-    // populate the buffer
-    boost::uint8_t *ptr = buf.reference();
-    for (size_t i=1; i< buf.size(); i++) {
-        ptr[i] = i;
-    }
 
     que.push(&buf);
     Buffer *buf2 = que.peek();
@@ -115,6 +117,46 @@
          runtest.fail ("CQue::pop()");
      }
      
+     que.push(&buf1);
+     que.push(&buf1);
+     size_t firstsize = que.size();
+     que.remove(&buf);
+     if (que.size() == firstsize - 1) {
+         runtest.pass ("CQue::remove()");
+     } else {
+         runtest.fail ("CQue::remove()");
+     }
+
+     // Make some test buffers
+     Buffer merge1, merge2, merge3;
+     size_t i;
+     ptr = merge1.reference();
+     for (i=0; i< gnash::NETBUFSIZE; i++) {
+         ptr[i] = i*'A';
+     }
+     que.push(&merge1);
+     
+     ptr = merge2.reference();
+     for (i=0; i<gnash::NETBUFSIZE; i++) {
+         ptr[i] = i+'a';
+     }
+     que.push(&merge2);
+
+     merge3.resize(96);
+     ptr = merge3.reference();
+     for (i=0; i<96; i++) {
+         ptr[i] = i+' ';
+     }
+     que.push(&merge3);
+
+     // A merge gives us one big buffer where there were several buffers
+     Buffer *foo = que.merge(&merge1);
+     if (foo->size() == (gnash::NETBUFSIZE * 2) + 96) {
+         runtest.pass ("CQue::merge()");
+     } else {
+         runtest.fail ("CQue::merge()");
+     }
+
 //     que.dump();
 }
 




reply via email to

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