summaryrefslogtreecommitdiff
path: root/test/basicserver/testbasicserver.cpp
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-03-01 10:42:48 +0000
committerChris Wilson <chris+github@qwirx.com>2014-03-01 10:42:48 +0000
commit2b6ac135fa7071290289741c9e35747bb9f1012f (patch)
tree037507c43ac097fb2cd5850bbd57f25a553e20e8 /test/basicserver/testbasicserver.cpp
parent2ef0a9aa8cd3cd4dcfa0cd9d2014051832c52e8a (diff)
Make Protocol take control of the socket object passed in.
We pass a std::auto_ptr<SocketStream> to every Protocol subclass when we construct it, and it takes control of this object. This reduces the risk of: * accidentally reusing the same SocketStream for multiple Protocols (it happened to me in testbackupstore); * holding onto a reference to the SocketStream; * allowing a locally-scoped SocketStream to go out of scope and be released while still being referenced by a live Protocol.
Diffstat (limited to 'test/basicserver/testbasicserver.cpp')
-rw-r--r--test/basicserver/testbasicserver.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/test/basicserver/testbasicserver.cpp b/test/basicserver/testbasicserver.cpp
index 5a13cb45..fe06e8c2 100644
--- a/test/basicserver/testbasicserver.cpp
+++ b/test/basicserver/testbasicserver.cpp
@@ -170,7 +170,7 @@ public:
testserver() {}
~testserver() {}
- void Connection(SocketStream &rStream);
+ void Connection(std::auto_ptr<SocketStream> apStream);
virtual const char *DaemonName() const
{
@@ -210,9 +210,9 @@ const ConfigurationVerify *testserver::GetConfigVerify() const
return &verify;
}
-void testserver::Connection(SocketStream &rStream)
+void testserver::Connection(std::auto_ptr<SocketStream> apStream)
{
- testservers_connection(rStream);
+ testservers_connection(*apStream);
}
class testProtocolServer : public testserver
@@ -221,7 +221,7 @@ public:
testProtocolServer() {}
~testProtocolServer() {}
- void Connection(SocketStream &rStream);
+ void Connection(std::auto_ptr<SocketStream> apStream);
virtual const char *DaemonName() const
{
@@ -229,9 +229,9 @@ public:
}
};
-void testProtocolServer::Connection(SocketStream &rStream)
+void testProtocolServer::Connection(std::auto_ptr<SocketStream> apStream)
{
- TestProtocolServer server(rStream);
+ TestProtocolServer server(apStream);
TestContext context;
server.DoServer(context);
}
@@ -243,7 +243,7 @@ public:
testTLSserver() {}
~testTLSserver() {}
- void Connection(SocketStreamTLS &rStream);
+ void Connection(std::auto_ptr<SocketStreamTLS> apStream);
virtual const char *DaemonName() const
{
@@ -283,9 +283,9 @@ const ConfigurationVerify *testTLSserver::GetConfigVerify() const
return &verify;
}
-void testTLSserver::Connection(SocketStreamTLS &rStream)
+void testTLSserver::Connection(std::auto_ptr<SocketStreamTLS> apStream)
{
- testservers_connection(rStream);
+ testservers_connection(*apStream);
}
@@ -691,15 +691,15 @@ int test(int argc, const char *argv[])
TEST_THAT(ServerIsAlive(pid));
// Open a connection to it
- SocketStream conn;
+ std::auto_ptr<SocketStream> apConn(new SocketStream);
#ifdef WIN32
- conn.Open(Socket::TypeINET, "localhost", 2003);
+ apConn->Open(Socket::TypeINET, "localhost", 2003);
#else
- conn.Open(Socket::TypeUNIX, "testfiles/srv4.sock");
+ apConn->Open(Socket::TypeUNIX, "testfiles/srv4.sock");
#endif
// Create a protocol
- TestProtocolClient protocol(conn);
+ TestProtocolClient protocol(apConn);
// Simple query
{