cout << "testing HTTP 1.1 pipelining" << endl;
{
- testServer.resetConnectCount();
+ testServer.disconnectAll();
cl.clearAllConnections();
cl.setProxy("", 80);
// test cancel
{
cout << "cancel request" << endl;
- testServer.resetConnectCount();
+ testServer.disconnectAll();
cl.clearAllConnections();
cl.setProxy("", 80);
// test cancel
{
cout << "cancel middle request" << endl;
- testServer.resetConnectCount();
+ testServer.disconnectAll();
cl.clearAllConnections();
cl.setProxy("", 80);
#define SIMGEAR_IO_TEST_HTTP_HXX
#include <sstream>
+#include <vector>
#include <simgear/io/sg_netChat.hxx>
#include <simgear/misc/strutils.hxx>
}
+ virtual ~TestServerChannel()
+ {
+ std::cerr << "dtor test server channel" << std::endl;
+ }
+
virtual void collectIncomingData(const char* s, int n)
{
buffer += std::string(s, n);
}
}
+ virtual void handleClose (void)
+ {
+ std::cerr << "channel close" << std::endl;
+ NetBufferChannel::handleClose();
+ }
+
+
State state;
std::string buffer;
std::string method;
int requestContentLength;
};
+class EraseIfClosed
+{
+public:
+ bool operator()(simgear::NetChannel* chan) const
+ {
+ return chan->isClosed();
+ }
+};
+
template <class T>
class TestServer : public NetChannel
{
simgear::NetChannelPoller _poller;
- int _connectCount;
+ std::vector<T*> _channels;
public:
TestServer()
{
Socket::initSockets();
- _connectCount = 0;
open();
bind(NULL, 2000); // localhost, any port
{
simgear::IPAddress addr ;
int handle = accept ( &addr ) ;
- TestServerChannel* chan = new T();
+ T* chan = new T();
chan->setHandle(handle);
+ _channels.push_back(chan);
_poller.addChannel(chan);
-
- _connectCount++;
}
void poll()
{
_poller.poll();
+
+ typename std::vector<T*>::iterator it;
+ it = std::remove_if(_channels.begin(), _channels.end(), EraseIfClosed());
+
+ for (typename std::vector<T*>::iterator it2 = it; it2 != _channels.end(); ++it2) {
+ _poller.removeChannel(*it2);
+ delete *it2;
+ }
+
+ _channels.erase(it, _channels.end());
+
}
- void resetConnectCount()
+ int connectCount()
{
- _connectCount = 0;
+ return _channels.size();
}
- int connectCount()
+ void disconnectAll()
{
- return _connectCount;
+ typename std::vector<T*>::iterator it;
+ for (it = _channels.begin(); it != _channels.end(); ++it) {
+ _poller.removeChannel(*it);
+ delete *it;
+ }
+
+ _channels.clear();
}
};