X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fio%2Ftest_HTTP.hxx;h=257ced064d932ef20e8c1096eb72284e16df395f;hb=e1c87b2fdc92a1196321079ea8576b1fa4b968a9;hp=9c75e134b3bd700dc5c9fe927aafe0dcba288d6e;hpb=a6d4aca990b1d0a32214d89c7bf8e7c9d17dcfd8;p=simgear.git diff --git a/simgear/io/test_HTTP.hxx b/simgear/io/test_HTTP.hxx index 9c75e134..257ced06 100644 --- a/simgear/io/test_HTTP.hxx +++ b/simgear/io/test_HTTP.hxx @@ -2,6 +2,7 @@ #define SIMGEAR_IO_TEST_HTTP_HXX #include +#include #include #include @@ -27,6 +28,11 @@ public: } + virtual ~TestServerChannel() + { + std::cerr << "dtor test server channel" << std::endl; + } + virtual void collectIncomingData(const char* s, int n) { buffer += std::string(s, n); @@ -160,6 +166,13 @@ public: } } + virtual void handleClose (void) + { + std::cerr << "channel close" << std::endl; + NetBufferChannel::handleClose(); + } + + State state; std::string buffer; std::string method; @@ -170,17 +183,25 @@ public: int requestContentLength; }; +class EraseIfClosed +{ +public: + bool operator()(simgear::NetChannel* chan) const + { + return chan->isClosed(); + } +}; + template class TestServer : public NetChannel { simgear::NetChannelPoller _poller; - int _connectCount; + std::vector _channels; public: TestServer() { Socket::initSockets(); - _connectCount = 0; open(); bind(NULL, 2000); // localhost, any port @@ -199,27 +220,43 @@ public: { 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::iterator it; + it = std::remove_if(_channels.begin(), _channels.end(), EraseIfClosed()); + + for (typename std::vector::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::iterator it; + for (it = _channels.begin(); it != _channels.end(); ++it) { + _poller.removeChannel(*it); + delete *it; + } + + _channels.clear(); } };