Correct use of remove_if in the test-server

Should fix erratic crashes of some tests.
This commit is contained in:
James Turner
2018-01-07 16:10:50 +00:00
parent a88b9181b6
commit da099d4312
+9 -17
View File
@@ -183,15 +183,6 @@ public:
int requestContentLength; int requestContentLength;
}; };
class EraseIfClosed
{
public:
bool operator()(simgear::NetChannel* chan) const
{
return chan->isClosed();
}
};
template <class T> template <class T>
class TestServer : public NetChannel class TestServer : public NetChannel
{ {
@@ -202,7 +193,6 @@ public:
{ {
Socket::initSockets(); Socket::initSockets();
open(); open();
bind(NULL, 2000); // localhost, any port bind(NULL, 2000); // localhost, any port
listen(16); listen(16);
@@ -212,6 +202,7 @@ public:
virtual ~TestServer() virtual ~TestServer()
{ {
_poller.removeChannel(this);
} }
virtual bool writable (void) { return false ; } virtual bool writable (void) { return false ; }
@@ -231,15 +222,16 @@ public:
{ {
_poller.poll(); _poller.poll();
typename std::vector<T*>::iterator it; auto it = std::remove_if(_channels.begin(), _channels.end(), [&](T* channel) {
it = std::remove_if(_channels.begin(), _channels.end(), EraseIfClosed()); if (channel->isClosed()) {
_poller.removeChannel(channel);
for (typename std::vector<T*>::iterator it2 = it; it2 != _channels.end(); ++it2) { delete channel;
delete *it2; return true;
} }
return false;
});
_channels.erase(it, _channels.end()); _channels.erase(it, _channels.end());
} }
int connectCount() int connectCount()