[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash/cygnal ChangeLog buffer.cpp buffer.h cque...
From: |
Rob Savoye |
Subject: |
[Gnash-commit] gnash/cygnal ChangeLog buffer.cpp buffer.h cque... |
Date: |
Wed, 26 Mar 2008 00:02:03 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Rob Savoye <rsavoye> 08/03/26 00:02:03
Modified files:
cygnal : ChangeLog buffer.cpp buffer.h cque.cpp cque.h
crc.cpp cygnal.cpp handler.cpp handler.h
http.cpp http.h netstats.cpp netstats.h
statistics.cpp statistics.h
cygnal/testsuite/cygnal.all: test_cque.cpp
Log message:
* buffer.{h,cpp}: Use more fime grained ifdef for statistics
collecting.
* cque.{h,cpp}: Collect que statistics.
* cygnal.cpp: Use a map instead of a list for the list of
handlers. Add admin thread for port 1111. Add connection manager
thread, one for each port.
* handler.cpp: Tweak how connections get closed. Make sure all
threads die in the proper order.
* handler.h: Add enum for admin commands.
* http.cpp: Return a bool instead of a string from
waitForGetRequest(). CLeanup after ourselves and die when the
I/O
threads go away.
* netstats.h: Add comment on statistics API. Rename ifdefs of
swf
versions.
* statistics.cpp: Add more codecs to the enum.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/ChangeLog?cvsroot=gnash&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/buffer.cpp?cvsroot=gnash&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/buffer.h?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/cque.cpp?cvsroot=gnash&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/cque.h?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/crc.cpp?cvsroot=gnash&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/cygnal.cpp?cvsroot=gnash&r1=1.28&r2=1.29
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/handler.cpp?cvsroot=gnash&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/handler.h?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/http.cpp?cvsroot=gnash&r1=1.25&r2=1.26
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/http.h?cvsroot=gnash&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/netstats.cpp?cvsroot=gnash&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/netstats.h?cvsroot=gnash&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/statistics.cpp?cvsroot=gnash&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/statistics.h?cvsroot=gnash&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/testsuite/cygnal.all/test_cque.cpp?cvsroot=gnash&r1=1.2&r2=1.3
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/cygnal/ChangeLog,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- ChangeLog 22 Mar 2008 04:05:56 -0000 1.14
+++ ChangeLog 26 Mar 2008 00:02:02 -0000 1.15
@@ -1,3 +1,21 @@
+2008-03-25 Rob Savoye <address@hidden>
+
+ * buffer.{h,cpp}: Use more fime grained ifdef for statistics
+ collecting.
+ * cque.{h,cpp}: Collect que statistics.
+ * cygnal.cpp: Use a map instead of a list for the list of
+ handlers. Add admin thread for port 1111. Add connection manager
+ thread, one for each port.
+ * handler.cpp: Tweak how connections get closed. Make sure all
+ threads die in the proper order.
+ * handler.h: Add enum for admin commands.
+ * http.cpp: Return a bool instead of a string from
+ waitForGetRequest(). CLeanup after ourselves and die when the I/O
+ threads go away.
+ * netstats.h: Add comment on statistics API. Rename ifdefs of swf
+ versions.
+ * statistics.cpp: Add more codecs to the enum.
+
2008-03-21 Rob Savoye <address@hidden>
* testsuite/cygnal.all/test_http.cpp: Fix so it compiles
Index: buffer.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/buffer.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- buffer.cpp 20 Mar 2008 18:14:56 -0000 1.6
+++ buffer.cpp 26 Mar 2008 00:02:02 -0000 1.7
@@ -39,7 +39,7 @@
empty();
}
-#ifdef USE_STATISTICS
+#ifdef USE_STATS_BUFFERS
clock_gettime (CLOCK_REALTIME, &_stamp);
#endif
return _ptr;
@@ -67,7 +67,7 @@
{
// GNASH_REPORT_FUNCTION;
if (_ptr) {
-#ifdef USE_STATISTICS
+#ifdef USE_STATS_BUFFERS
struct timespec now;
clock_gettime (CLOCK_REALTIME, &now);
log_debug("Buffer %x (%d) stayed in queue for %f seconds",
Index: buffer.h
===================================================================
RCS file: /sources/gnash/gnash/cygnal/buffer.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- buffer.h 20 Mar 2008 02:25:57 -0000 1.4
+++ buffer.h 26 Mar 2008 00:02:02 -0000 1.5
@@ -69,7 +69,7 @@
void *init(size_t nbytes);
gnash::Network::byte_t *_ptr;
int _nbytes;
-#if USE_STATISTICS
+#ifdef USE_STATS_BUFFERS
struct timespec _stamp; // used for timing how long data stays in the
queue.
#endif
};
Index: cque.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/cque.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- cque.cpp 20 Mar 2008 02:25:57 -0000 1.5
+++ cque.cpp 26 Mar 2008 00:02:02 -0000 1.6
@@ -23,6 +23,7 @@
#include <string>
#include <vector>
#include <deque>
+#include <time.h>
#include "log.h"
#include "gmemory.h"
@@ -40,6 +41,10 @@
CQue::CQue()
{
// GNASH_REPORT_FUNCTION;
+ _stats.totalbytes = 0;
+ _stats.totalin = 0;
+ _stats.totalout = 0;
+ clock_gettime (CLOCK_REALTIME, &_stats.start);
_name = "default";
}
@@ -90,16 +95,21 @@
// GNASH_REPORT_FUNCTION;
boost::mutex::scoped_lock lock(_mutex);
_que.push_back(data);
+#ifdef USE_STATS_QUEUE
+ _stats.totalbytes += data->size();
+ _stats.totalin++;
+#endif
return true;
}
-// Push bytes on the outgoing FIFO
+// Push data
bool
CQue::push(gnash::Network::byte_t *data, int nbytes)
{
// GNASH_REPORT_FUNCTION;
Buffer *buf = new Buffer;
std::copy(data, data + nbytes, buf->reference());
+ return push(buf);
}
@@ -113,6 +123,9 @@
if (_que.size()) {
buf = _que.front();
_que.pop_front();
+#ifdef USE_STATS_QUEUE
+ _stats.totalout++;
+#endif
}
return buf;
}
@@ -229,6 +242,15 @@
Buffer *ptr = *(it);
ptr->dump();
}
+#ifdef USE_STATS_QUEUE
+ struct timespec now;
+ clock_gettime (CLOCK_REALTIME, &now);
+ cerr << "Que lifespan is " <<
+ (float)((now.tv_sec - _stats.start.tv_sec) + ((now.tv_nsec -
_stats.start.tv_nsec)/1e9)) << " seconds" << endl;
+ cerr << "Total number of bytes is " << _stats.totalbytes << " bytes" <<
endl;
+ cerr << "Total number of packets pushed to queue is: " << _stats.totalin
<< endl;
+ cerr << "Total number of packets popped from queue is: " <<
_stats.totalout << endl;
+#endif
}
} // end of cygnal namespace
Index: cque.h
===================================================================
RCS file: /sources/gnash/gnash/cygnal/cque.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- cque.h 18 Mar 2008 22:04:28 -0000 1.3
+++ cque.h 26 Mar 2008 00:02:02 -0000 1.4
@@ -23,6 +23,7 @@
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
#include <deque>
+#include <time.h>
#include "buffer.h"
#include "network.h"
@@ -33,6 +34,14 @@
class CQue {
public:
+#ifdef USE_STATS_QUEUE
+ typedef struct {
+ struct timespec start;
+ int totalbytes;
+ int totalin;
+ int totalout;
+ } que_stats_t;
+#endif
CQue();
CQue(const std::string &str) { _name = str; };
~CQue();
@@ -59,8 +68,10 @@
// 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();
+ que_stats_t *stats() { return &_stats; };
void setName(const std::string &str) { _name = str; }
private:
// an optional name for the queue, only used for debugging messages to
make them unique
@@ -74,6 +85,9 @@
boost::mutex _cond_mutex;
// This is the mutex that control access to the que.
boost::mutex _mutex;
+#ifdef USE_STATS_QUEUE
+ que_stats_t _stats;
+#endif
};
} // end of cygnal namespace
Index: crc.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/crc.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- crc.cpp 5 Mar 2008 17:00:37 -0000 1.5
+++ crc.cpp 26 Mar 2008 00:02:02 -0000 1.6
@@ -104,7 +104,7 @@
bool
CRcInitFile::parseFile(const std::string& filespec)
{
-// GNASH_REPORT_FUNCTION;
+ GNASH_REPORT_FUNCTION;
struct stat stats;
string action;
string variable;
Index: cygnal.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/cygnal.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- cygnal.cpp 20 Mar 2008 02:25:57 -0000 1.28
+++ cygnal.cpp 26 Mar 2008 00:02:02 -0000 1.29
@@ -23,7 +23,9 @@
#endif
#include <list>
+#include <map>
#include <iostream>
+#include <sstream>
#include <signal.h>
#include <vector>
#include <sys/mman.h>
@@ -82,12 +84,8 @@
static void version_and_copyright();
static void cntrlc_handler(int sig);
-//static void start_thread();
-//static void rtmp_thread(struct thread_params *conndata);
-static void http_thread(struct thread_params *conndata);
-//static void ssl_thread(struct thread_params *conndata);
-static void stream_thread(struct thread_params *sendfile);
-//static void dispatch_thread(struct thread_params *params);
+void connection_handler(Handler::thread_params_t *args);
+void admin_handler(Handler::thread_params_t *args);
LogFile& dbglogfile = LogFile::getDefaultInstance();
@@ -113,7 +111,12 @@
static int port_offset = 0;
// Keep a list of all active network connections
-static map<std::string, Handler *> _handlers;
+namespace cygnal {
+ map<int, Handler *> handlers;
+}
+
+// Admin commands are small
+const int ADMINPKTSIZE = 80;
// end of globals
@@ -143,9 +146,11 @@
exit(EXIT_FAILURE);
}
+// crcfile.loadFiles();
+
// Set the log file name before trying to write to
// it, or we might get two.
- dbglogfile.setLogFilename("cygnal-dbg.log");
+ dbglogfile.setLogFilename(crcfile.getDebugLog());
if (crcfile.verbosityLevel() > 0) {
dbglogfile.setVerbosity(crcfile.verbosityLevel());
@@ -156,16 +161,14 @@
log_debug (_("Document Root for media files is: %s"),
docroot);
} else {
- docroot = "/var/www/html/software/gnash/tests/";
+ docroot = "/var/www/html/software/tests/";
}
// Handle command line arguments
- for( int i = 0; i < parser.arguments(); ++i )
- {
+ for( int i = 0; i < parser.arguments(); ++i ) {
const int code = parser.code(i);
- switch( code )
- {
+ switch( code ) {
case 'h':
version_and_copyright();
usage();
@@ -199,38 +202,45 @@
// rtmp_data.port = port_offset + 1935;
// boost::thread rtmp_port(boost::bind(&rtmp_thread, &rtmp_data));
+#if 1
+ // Admin handler
+ Handler::thread_params_t admin_data;
+ admin_data.port = gnash::ADMIN;
+ boost::thread adminhandler(boost::bind(&admin_handler, &admin_data));
+#endif
+
+#if 1
+ // Incomming connection handler
+ Handler::thread_params_t conn_data;
+ conn_data.port = port_offset + gnash::RTMPT;
+ conn_data.filespec = docroot;
+// conn_data.handle = &handlers;
+ boost::thread conn_handler(boost::bind(&connection_handler, &conn_data));
+#endif
+
+#if 0
int retries = 10;
// Run forever
while (retries > 0) {
Handler::thread_params_t http_data;
http_data.netfd = 0;
- http_data.port = port_offset + 80;
+ http_data.port = port_offset + gnash::RTMPT;
http_data.filespec = docroot;
Handler *hand = new Handler;
http_data.handle = &hand;
+ cerr << "Adding handler: " << (void *)hand << endl;
+ handlers.push_back(hand);
+ hand->createServer(http_data.port);
hand->start(&http_data);
+ cerr << "Removing handler: " << (void *)hand << endl;
+ handlers.remove(hand);
delete hand;
}
-
-// 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));
-
- ssl_data.port = port_offset + 443;
-// boost::thread ssl_port(boost::bind(&ssl_thread, &ssl_data));
-
-// 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();
-// ssl_port.join();
-
+// adminhandler.join();
+ conn_handler.join();
log_debug (_("All done I think..."));
return(0);
@@ -338,6 +348,7 @@
<< endl;
}
+
static void
usage()
{
@@ -351,6 +362,150 @@
<< endl;
}
+// FIXME: this function could be tweaked for better performance
+void
+admin_handler(Handler::thread_params_t *args)
+{
+ GNASH_REPORT_FUNCTION;
+ int retries = 10;
+ int ret;
+
+ map<int, Handler *>::iterator hit;
+ stringstream response;
+ int index = 0;
+
+ Network net;
+ Handler::admin_cmd_e cmd = Handler::POLL;
+ net.createServer(args->port);
+ while (retries > 0) {
+ log_debug(_("Starting Admin Handler for port %d"), args->port);
+ net.newConnection(true);
+ log_debug(_("Got an incoming Admin request"));
+ do {
+ Network::byte_t data[ADMINPKTSIZE+1];
+ memset(data, 0, ADMINPKTSIZE+1);
+ const char *ptr = reinterpret_cast<const char *>(data);
+ ret = net.readNet(data, ADMINPKTSIZE, 3);
+ // force the case to make comparisons easier. Only compare enough
characters to
+ // till each command is unique.
+ std::transform(ptr, ptr + ret, data, (int(*)(int)) toupper);
+ if (ret == 0) {
+ net.writeNet("no more admin data, exiting...\n");
+ if ((ret == 0) && cmd != Handler::POLL) {
+// retries = 0;
+ ret = -1;
+ break;
+ }
+ } else {
+ if (strncmp(ptr, "QUIT", 4) == 0) {
+ cmd = Handler::QUIT;
+ } else if (strncmp(ptr, "STATUS", 5) == 0) {
+ cmd = Handler::STATUS;
+ } else if (strncmp(ptr, "HELP", 2) == 0) {
+ cmd = Handler::HELP;
+ net.writeNet("commands: help, status, poll, interval,
statistics, quit.\n");
+ } else if (strncmp(ptr, "POLL", 2) == 0) {
+ cmd = Handler::POLL;
+ } else if (strncmp(ptr, "INTERVAL", 2) == 0) {
+ cmd = Handler::INTERVAL;
+ }
+ }
+ switch (cmd) {
+ // close this connection
+ case Handler::QUIT:
+ ret = -1;
+ break;
+ case Handler::STATUS:
+ response << handlers.size() << " handlers are currently
active.";
+ for (hit = handlers.begin(); hit != handlers.end(); hit++) {
+ int fd = hit->first;
+ Handler *hand = hit->second;
+ response << fd << ","
+ << hand->insize()
+ << "," << hand->outsize()
+ << "\r\n";
+ net.writeNet(response.str());
+ index++;
+ }
+ index = 0;
+ break;
+ case Handler::POLL:
+#ifdef USE_STATS_QUEUE
+ index = 0;
+ response << handlers.size() << " handlers are currently
active." << "\r\n";
+ for (hit = handlers.begin(); hit != handlers.end(); hit++) {
+ int fd = hit->first;
+ Handler *hand = hit->second;
+ struct timespec now;
+ clock_gettime (CLOCK_REALTIME, &now);
+ // Incoming que stats
+ CQue::que_stats_t *stats = hand->statsin();
+ float diff = (float)((now.tv_sec - stats->start.tv_sec) +
((now.tv_nsec - stats->start.tv_nsec)/1e9));
+ response << fd
+ << "," << stats->totalbytes
+ << "," << diff
+ << "," << stats->totalin
+ << "," << stats->totalout;
+ // Outgoing que stats
+ stats = hand->statsout();
+ response << "," <<stats->totalbytes
+ << "," << stats->totalin
+ << "," << stats->totalout
+ << "\r\n";
+ net.writeNet(response.str());
+ index++;
+ }
+ index = 0;
+#endif
+ break;
+ case Handler::INTERVAL:
+ net.writeNet("set interval\n");
+ break;
+ default:
+ break;
+ };
+ } while (ret >= 0);
+ net.writeNet("admin_handler: Done...!\n");
+ net.closeNet(); // this shuts down this socket connection
+ }
+ net.closeConnection(); // this shuts down the server on this
connection
+}
+
+void
+connection_handler(Handler::thread_params_t *args)
+{
+ GNASH_REPORT_FUNCTION;
+ int fd = 0;
+// list<Handler *> *handlers = reinterpret_cast<list<Handler *>
*>(args->handle);
+
+ Network net;
+// net.toggleDebug(true);
+ fd = net.createServer(args->port);
+ // Run forever
+ do {
+ Handler *hand = new Handler;
+ hand->toggleDebug(true); // FIXME: too verbose
+ args->netfd = hand->newConnection(true, fd);
+ args->handle = hand;
+ log_debug("Adding handler: %x for fd #%d",
+ (void *)hand, args->netfd);
+#if 0
+ map<int, Handler *>::iterator hit = handlers.find(args->netfd);
+ if ((*hit).second) {
+ log_debug("Removing handle %x for fd #%d: ",
+ (void *)hand), args->netfd;
+ handlers.erase(args->netfd);
+ }
+#endif
+ handlers[args->netfd] = hand;
+ hand->start(args);
+
+// handlers.remove(hand);
+// delete hand;
+ log_debug("Restarting loop...");
+ } while(1);
+} // end of connection_handler
+
//} // end of cygnal namespace
// local Variables:
Index: handler.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/handler.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- handler.cpp 20 Mar 2008 18:14:56 -0000 1.7
+++ handler.cpp 26 Mar 2008 00:02:03 -0000 1.8
@@ -23,13 +23,15 @@
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/bind.hpp>
+#include <algorithm>
#include <string>
#include <deque>
+#include <list>
+#include <map>
#include "log.h"
#include "network.h"
#include "buffer.h"
-#include "handler.h"
#include "http.h"
@@ -40,6 +42,8 @@
namespace cygnal
{
+extern map<int, Handler *> handlers;
+
Handler::Handler()
: _die(false), _netfd(0)
{
@@ -77,6 +81,7 @@
{
// GNASH_REPORT_FUNCTION;
Buffer *ptr = new Buffer;
+ ptr->copy(data, nbytes);
return push(ptr, direction);
}
@@ -149,101 +154,114 @@
}
}
+// Dump internal data.
+void
+Handler::dump()
+{
+// GNASH_REPORT_FUNCTION;
+ _incoming.dump();
+ _outgoing.dump();
+}
+
// start the two thread handlers for the queues
bool
Handler::start(thread_params_t *args)
{
-// GNASH_REPORT_FUNCTION;
- int retries = 10;
+ GNASH_REPORT_FUNCTION;
+// Handler *hand = reinterpret_cast<Handler *>(args->handle);
_incoming.setName("Incoming");
_outgoing.setName("Outgoing");
-// toggleDebug(true); // FIXME:
- closeNet();
- 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;
- boost::thread handler(boost::bind(&httphandler, args));
+ log_debug(_("Starting Handlers for port %d, pid %d"),
+ args->port, getpid());
+// newConnection(true);
+ boost::thread handler(boost::bind(&httphandler, args));
boost::thread outport(boost::bind(&netout_handler, args));
-
boost::thread inport(boost::bind(&netin_handler, args));
- inport.join();
- outport.join();
- handler.join();
- if (_die) {
- log_debug("Handler done...");
- break;
- }
- }
-}
-
-// Dump internal data.
-void
-Handler::dump()
-{
-// GNASH_REPORT_FUNCTION;
- _incoming.dump();
- _outgoing.dump();
+// We don't want to wait for the threads to complete, we
+// want to return to the main program so it can spawn another
+// thread for the next incoming connection.
+// inport.join();
+// outport.join();
+// handler.join();
+// if (_die) {
+// log_debug("Handler done...");
+// }
+ return true;
}
extern "C" {
void
netin_handler(Handler::thread_params_t *args)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
Handler *hand = reinterpret_cast<Handler *>(args->handle);
do {
Buffer *buf = new Buffer;
- int ret = hand->readNet(buf->reference(), buf->size(), 15);
- if (ret > 0) {
+ size_t ret = hand->readNet(args->netfd, buf->reference(), buf->size(),
1);
+ if ((ret > 0) && (ret != string::npos)) {
if (ret != buf->size()) {
buf->resize(ret);
}
hand->push(buf);
-// string str = (const char *)buf->reference();
-// cerr << str << endl;
hand->notify();
} else {
- log_debug("no more data, exiting...");
+ log_debug("no more data for fd #%d, exiting...", args->netfd);
hand->die();
break;
}
} while (!hand->timetodie());
- log_debug("Net In handler done...");
+ log_debug("Net In handler done for fd #%d...", args->netfd);
hand->notify();
+ hand->closeNet(args->netfd);
hand->clearall();
+// cerr << "Removing handler: " << (void *)hand << endl;
+// handlers.remove(hand);
+// delete hand;
// hand->dump();
}
+
void
netout_handler(Handler::thread_params_t *args)
{
- GNASH_REPORT_FUNCTION;
- int retries = 10;
+// GNASH_REPORT_FUNCTION;
int ret;
Handler *hand = reinterpret_cast<Handler *>(args->handle);
do {
+ // Don't look for any more packets in the que cause we're done
+ if (hand->timetodie()) {
+ break;
+ }
hand->waitout();
while (hand->outsize()) {
Buffer *buf = hand->popout();
// log_debug("FIXME: got data in Outgoing que");
// buf->dump();
// ret = hand->writeNet(buf->reference(), buf->size(), 15);
- ret = hand->writeNet(buf);
+// if (buf->size() != gnash::NETBUFSIZE) {
+// log_debug("Got smaller packet, size %d", buf->size());
+// }
+ ret = hand->writeNet(args->netfd, buf);
delete buf;
}
- if (hand->timetodie()) {
- log_debug("Net Out handler done...");
- break;
- }
} while (ret > 0);
- hand->closeConnection();
+ hand->die();
+ log_debug("Net Out handler done for fd #%d...", args->netfd);
+ hand->notifyin();
+ hand->closeNet(args->netfd);
+#if 0
+ map<int, Handler *>::iterator hit = handlers.find(args->netfd);
+ if ((*hit).second) {
+ log_debug("Removing handle %x for fd #%d: ",
+ (void *)hand), args->netfd;
+ handlers.erase(args->netfd);
+ }
+#endif
+ delete hand;
}
} // end of extern C
Index: handler.h
===================================================================
RCS file: /sources/gnash/gnash/cygnal/handler.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- handler.h 19 Mar 2008 17:47:08 -0000 1.4
+++ handler.h 26 Mar 2008 00:02:03 -0000 1.5
@@ -20,7 +20,7 @@
#define __HANDLER_H__ 1
#include <boost/cstdint.hpp>
-#include <boost/thread/condition.hpp>
+//#include <boost/thread/condition.hpp>
#include <string>
#include <deque>
@@ -41,6 +41,14 @@
Handler();
~Handler();
+ typedef enum {
+ UNKNOWN,
+ STATUS,
+ POLL,
+ HELP,
+ INTERVAL,
+ QUIT,
+ } admin_cmd_e;
// This is used to pass parameters to a thread using boost::bind
typedef struct {
int netfd;
@@ -116,14 +124,17 @@
// Take a buffer and write it to the network
int writeNet(int fd, Buffer *buf)
- { Network::writeNet(fd, buf->reference(), buf->size()); };
+ { return Network::writeNet(fd, buf->reference(), buf->size()); };
int writeNet(Buffer *buf)
- { Network::writeNet(buf->reference(), buf->size()); };
+ { return Network::writeNet(buf->reference(), buf->size()); };
// Dump internal data.
void dump();
-
+#ifdef USE_STATS_QUEUE
+ CQue::que_stats_t *statsin() { return _incoming.stats(); };
+ CQue::que_stats_t *statsout() { return _outgoing.stats(); };
+#endif
void die() { _die = true; _outgoing.notify(); };
bool timetodie() { return _die; };
@@ -139,6 +150,7 @@
extern "C" {
void netin_handler(Handler::thread_params_t *args);
void netout_handler(Handler::thread_params_t *args);
+ void start_handler(Handler::thread_params_t *args);
}
} // end of cygnal namespace
Index: http.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/http.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- http.cpp 22 Mar 2008 04:05:56 -0000 1.25
+++ http.cpp 26 Mar 2008 00:02:03 -0000 1.26
@@ -49,6 +49,8 @@
namespace cygnal
{
+extern map<int, Handler *> handlers;
+
// FIXME, this seems too small to me. --gnu
static const int readsize = 1024;
@@ -104,14 +106,14 @@
return *this;
}
-string
+bool
HTTP::waitForGetRequest(Network& /*net*/)
{
GNASH_REPORT_FUNCTION;
- return ""; // TODO: FIXME !
+ return false; // FIXME: this should be finished
}
-string
+bool
HTTP::waitForGetRequest()
{
GNASH_REPORT_FUNCTION;
@@ -125,7 +127,7 @@
if (buf == 0) {
log_debug("Que empty, net connection dropped");
- return "";
+ return false;
}
clearHeader();
@@ -144,7 +146,10 @@
// dump();
_filespec = _url;
- return _url;
+ if (!_url.empty()) {
+ return true;
+ }
+ return false;
}
bool
@@ -637,7 +642,7 @@
HTTP::http_method_e
HTTP::extractCommand(gnash::Network::byte_t *data)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
string body = reinterpret_cast<const char *>(data);
HTTP::http_method_e cmd;
@@ -1075,7 +1080,7 @@
HTTP::filetype_e
HTTP::getFileStats(std::string &filespec)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
bool try_again = true;
string actual_filespec = filespec;
struct stat st;
@@ -1131,7 +1136,7 @@
void
HTTP::dump() {
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
boost::mutex::scoped_lock lock(stl_mutex);
vector<string>::iterator it;
@@ -1186,8 +1191,27 @@
string docroot = args->filespec;
while (!hand->timetodie()) {
- log_debug(_("Waiting for GET request..."));
+ log_debug(_("Waiting for GET request on fd #%d..."), args->netfd);
hand->wait();
+ // This thread is the last to wake up when the browser
+ // closes the network connection. When browsers do this
+ // varies, elinks and lynx are very forgiving to a more
+ // flexible HTTP protocol, which Firefox/Mozilla & Opera
+ // are much pickier, and will hang or fail to load if
+ // you aren't careful.
+ if (hand->timetodie()) {
+ log_debug("Not waiting no more, no more for fd #%d...",
args->netfd);
+#if 1
+ map<int, Handler *>::iterator hit = handlers.find(args->netfd);
+ if ((*hit).second) {
+ log_debug("Removing handle %x for fd #%d",
+ (void *)hand), args->netfd;
+ handlers.erase(args->netfd);
+ }
+#endif
+
+ return;
+ }
#ifdef USE_STATISTICS
struct timespec start;
clock_gettime (CLOCK_REALTIME, &start);
@@ -1196,14 +1220,17 @@
// conndata->statistics->setFileType(NetStats::RTMPT);
// conndata->statistics->startClock();
// args->netfd = www.getFileFd();
- url = docroot;
- string str = www.waitForGetRequest();
- if (str.size() == 0) {
+ if (!www.waitForGetRequest()) {
hand->die();
-// log_debug("Net HTTP done...");
+ hand->notifyin();
+ hand->clearout();
+ hand->notifyout();
+ log_debug("Net HTTP done for fd #%d...", args->netfd);
+// hand->closeNet(args->netfd);
return;
}
- url += str;
+ url = docroot;
+ url += www.getURL();
pos = url.find("?");
filespec = url.substr(0, pos);
parameters = url.substr(pos + 1, url.size());
@@ -1237,8 +1264,8 @@
#endif
if (stat(filespec.c_str(), &st) == 0) {
filefd = ::open(filespec.c_str(), O_RDONLY);
- log_debug (_("File \"%s\" is %lld bytes in size."), filespec,
- st.st_size);
+ log_debug (_("File \"%s\" is %lld bytes in size, disk fd #%d"),
filespec,
+ st.st_size, filefd);
do {
Buffer *buf = new Buffer;
ret = read(filefd, buf->reference(), buf->size());
@@ -1248,6 +1275,7 @@
}
if (ret != buf->size()) {
buf->resize(ret);
+// log_debug("Got last data block from disk file, size
%d", buf->size());
}
// log_debug("Read %d bytes from %s.", ret, filespec);
#if 1
@@ -1261,11 +1289,14 @@
delete buf;
#endif
} while(ret > 0);
+ log_debug("Done transferring %s to net fd #%d",
+ filespec, args->netfd);
+ ::close(filefd); // close the disk file
// See if this is a persistant connection
- if (!www.keepAlive()) {
- log_debug("Keep-Alive is off", www.keepAlive());
-// hand->closeConnection();
- }
+// if (!www.keepAlive()) {
+// log_debug("Keep-Alive is off", www.keepAlive());
+// // hand->closeConnection();
+// }
#ifdef USE_STATISTICS
struct timespec end;
clock_gettime (CLOCK_REALTIME, &end);
@@ -1274,6 +1305,7 @@
(float)((end.tv_sec - start.tv_sec) + ((end.tv_nsec -
start.tv_nsec)/1e9)));
#endif
}
+
// memset(args->filespec, 0, 256);
// memcpy(->filespec, filespec.c_str(), filespec.size());
// boost::thread sendthr(boost::bind(&stream_thread, args));
@@ -1289,7 +1321,7 @@
// }
} // end of while retries
- log_debug("Net HTTP done...");
+ log_debug("httphandler all done now finally...");
} // end of httphandler
Index: http.h
===================================================================
RCS file: /sources/gnash/gnash/cygnal/http.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- http.h 22 Mar 2008 04:05:55 -0000 1.19
+++ http.h 26 Mar 2008 00:02:03 -0000 1.20
@@ -86,6 +86,7 @@
SERVICE_UNAVAILABLE = 503,
GATEWAY_TIMEOUT = 504,
HTTP_VERSION_NOT_SUPPORTED = 505,
+ // Gnash/Cygnal extensions for internal use
LIFE_IS_GOOD = 1234,
CLOSEPIPE = 1235
} http_status_e;
@@ -123,8 +124,8 @@
HTTP();
HTTP(Handler *hand);
~HTTP();
- std::string waitForGetRequest();
- std::string waitForGetRequest(gnash::Network &net);
+ bool waitForGetRequest();
+ bool waitForGetRequest(gnash::Network &net);
// Handle the GET request response
bool sendGetReply(http_status_e code);
Index: netstats.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/netstats.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- netstats.cpp 5 Mar 2008 03:55:49 -0000 1.10
+++ netstats.cpp 26 Mar 2008 00:02:03 -0000 1.11
@@ -63,7 +63,6 @@
_starttime = stats.getStartTime();
_stoptime = stats.getStopTime();
_bytes = stats.getBytes();
- _codec = stats.getCodec();
_type = stats.getFileType();
return *this;
}
Index: netstats.h
===================================================================
RCS file: /sources/gnash/gnash/cygnal/netstats.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- netstats.h 21 Jan 2008 20:56:06 -0000 1.6
+++ netstats.h 26 Mar 2008 00:02:03 -0000 1.7
@@ -25,6 +25,33 @@
//include all types plus i/o
#include <boost/date_time/posix_time/posix_time.hpp>
+#include <string>
+
+// This is what the ActionScript 'Client' class returns:
+//
+// bytes_in Total number of bytes received.
+// bytes_out Total number of bytes sent.
+// msg_in Total number of RTMP messages received.
+// msg_out Total number of RTMP messages sent.
+// msg_dropped Total number of dropped RTMP messages.
+// ping_rtt Length of time the client takes to respond to a ping
message.
+// audio_queue_msgs Current number of audio messages in the queue waiting
to be delivered to the client.
+// video_queue_msgs Current number of video messages in the queue waiting
to be delivered to the client.
+// so_queue_msgs Current number of shared object messages in the queue
waiting to be delivered to the client.
+// data_queue_msgs Current number of data messages in the queue waiting to
be delivered to the client.
+// dropped_audio_msgs Number of audio messages that were dropped.
+// dropped_video_msgs Number of video messages that were dropped.
+// audio_queue_bytes Total size of all audio messages (in bytes) in the
queue waiting to be delivered to the client.
+// video_queue_bytes Total size of all video messages (in bytes) in the
queue waiting to be delivered to the client.
+// so_queue_bytes Total size of all shared object messages (in bytes) in
the queue waiting to be delivered to the client.
+// data_queue_bytes Total size of all data messages (in bytes) in the queue
waiting to be delivered to the client.
+// dropped_audio_bytes Total size of all audio messages (in bytes) that were
dropped.
+// dropped_video_bytes Total size of all video messages (in bytes) that were
dropped.
+// bw_out Current upstream (client to server) bandwidth for this
client.
+// bw_in Current downstream (server to client) bandwidth for
this client.
+// client_id A unique ID issued by the server for this client.
+//
+// samples are taken every 3 seconds, or the interval supplied in
Client::setInterval()
namespace cygnal
{
@@ -37,21 +64,27 @@
NO_CODEC,
OGG,
THEORA,
+ DIRAC,
+ SNOW,
MP3,
MPEG4,
+ H264,
+ H263,
FLV,
VP6,
VP7
} codec_e;
typedef enum {
NO_FILETYPE,
+ HTTP,
RTMP,
RTMPT,
RTMPTS,
- FLASH6,
- FLASH7,
- FLASH8,
- FLASH9,
+ SWF,
+ SWF6,
+ SWF7,
+ SWF8,
+ SWF9,
AUDIO,
VIDEO
} filetypes_e;
@@ -64,14 +97,12 @@
void setStartTime(boost::posix_time::ptime x) { _starttime = x; };
void setStopTime(boost::posix_time::ptime x) { _stoptime = x; };
void setBytes(int x) { _bytes = x; };
- void setCodec(codec_e x) { _codec = x; };
void setFileType(filetypes_e x) { _type = x; };
// Accumulate the byts transferred
int addBytes(int x) { _bytes += x; return _bytes; };
// Accessors to get to the private data
int getBytes() { return _bytes; };
- codec_e getCodec() { return _codec; };
filetypes_e getFileType() { return _type; };
boost::posix_time::ptime getStartTime() { return _starttime; };
boost::posix_time::ptime getStopTime() { return _stoptime; };
@@ -81,7 +112,6 @@
boost::posix_time::ptime _starttime;
boost::posix_time::ptime _stoptime;
int _bytes;
- codec_e _codec;
filetypes_e _type;
};
Index: statistics.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/statistics.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- statistics.cpp 5 Mar 2008 03:55:49 -0000 1.7
+++ statistics.cpp 26 Mar 2008 00:02:03 -0000 1.8
@@ -43,8 +43,12 @@
"NO_CODEC",
"Ogg",
"Theora",
+ "Dirac",
+ "Snow",
"MP3",
"MPEG4",
+ "H264",
+ "H263",
"FLV",
"VP6",
"VP7"
@@ -55,14 +59,16 @@
// representation here or you'll get the wrong output.
const char *filetype_names[] = {
"NO_FILETYPE",
+ "HTTP",
"RTMP",
"RTMPT",
"RTMPTS",
- "FLASH5",
- "FLASH6",
- "FLASH7",
- "FLASH8",
- "FLASH9",
+ "SWF",
+ "SWF5",
+ "SWF6",
+ "SWF7",
+ "SWF8",
+ "SWF9",
"AUDIO",
"VIDEO"
};
@@ -95,7 +101,6 @@
st->setStartTime(getStartTime());
st->setStopTime(getStopTime());
st->setBytes(getBytes());
- st->setCodec(getCodec());
st->setFileType(getFileType());
boost::mutex::scoped_lock lock(io_mutex);
@@ -114,10 +119,10 @@
if (stats->getFileType() <= VIDEO) {
log_debug (_("Stream type is: %s"),
filetype_names[stats->getFileType()]);
}
- if (((stats->getFileType() == VIDEO) || (stats->getFileType() ==
AUDIO)) &&
- stats->getCodec() <= VP7) {
- log_debug (_("Stream codec is: %s"),
codec_names[stats->getCodec()]);
- }
+// if (((stats->getFileType() == VIDEO) || (stats->getFileType() ==
AUDIO)) &&
+// stats->getCodec() <= VP7) {
+// log_debug (_("Stream codec is: %s"),
codec_names[stats->getCodec()]);
+// }
log_debug (_("%d bytes were transfered in %s seconds"),
stats->getBytes(),
to_simple_string(stats->getTimeSpan()).c_str());
Index: statistics.h
===================================================================
RCS file: /sources/gnash/gnash/cygnal/statistics.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- statistics.h 21 Jan 2008 20:56:06 -0000 1.7
+++ statistics.h 26 Mar 2008 00:02:03 -0000 1.8
@@ -1,5 +1,5 @@
//
-// Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+// Copyright (C) 2006, 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
@@ -55,24 +55,36 @@
WIN32,
SOLARIS
} ostype_e;
- void setIPaddr(in_addr_t x) { _ipaddr = x; };
- void setBrowser(browser_e x) { _browser = x; } ;
+
+ // Add a sample
int addStats();
+
// these make calculations on the collected network data.
float getFPS();
int getBitRate();
+
+ // Accessors
+ void setIPaddr(in_addr_t x) { _ipaddr = x; };
+ void setBrowser(browser_e x) { _browser = x; } ;
+ void setOS(ostype_e x) { _os = x; } ;
+ in_addr_t getIPaddr() { return _ipaddr; };
+ browser_e getBrowser() { return _browser; };
+ ostype_e getOS() { return _os; };
+
+// void setFilespec(std::string &x) { _filespec = x; } ;
+// std::string &getFilespec() { return _filespec; };
// Dump the collected network statistics in a human readable form.
void dump();
void clear();
private:
in_addr_t _ipaddr;
- const char *_filespec;
browser_e _browser;
ostype_e _os;
std::list<NetStats *> _netstats;
+ boost::uint32_t _msg_count;
+ std::vector<std::string> _filespec;
};
-
} // end of cygnal namespace
#endif // __STATISTICS_H__
Index: testsuite/cygnal.all/test_cque.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/testsuite/cygnal.all/test_cque.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- testsuite/cygnal.all/test_cque.cpp 18 Mar 2008 01:06:04 -0000 1.2
+++ testsuite/cygnal.all/test_cque.cpp 26 Mar 2008 00:02:03 -0000 1.3
@@ -157,6 +157,8 @@
runtest.fail ("CQue::merge()");
}
-// que.dump();
+ que.pop();
+
+ que.dump();
}
- [Gnash-commit] gnash/cygnal ChangeLog buffer.cpp buffer.h cque..., Rob Savoye, 2008/03/18
- [Gnash-commit] gnash/cygnal ChangeLog buffer.cpp buffer.h cque...,
Rob Savoye <=
- Message not available
- Re: [Gnash-commit] gnash/cygnal ChangeLog buffer.cpp buffer.h cque..., Rob Savoye, 2008/03/26
- Re: [Gnash-commit] gnash/cygnal ChangeLog buffer.cpp buffer.h cque..., Dossy Shiobara, 2008/03/26
- Re: [Gnash-commit] gnash/cygnal ChangeLog buffer.cpp buffer.h cque..., strk, 2008/03/26
- Re: [Gnash-commit] gnash/cygnal ChangeLog buffer.cpp buffer.h cque..., Dossy Shiobara, 2008/03/26
- Re: [Gnash-commit] gnash/cygnal ChangeLog buffer.cpp buffer.h cque..., Rob Savoye, 2008/03/26