summaryrefslogtreecommitdiff
path: root/lib/backupstore
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 /lib/backupstore
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 'lib/backupstore')
-rw-r--r--lib/backupstore/StoreTestUtils.cpp16
-rw-r--r--lib/backupstore/StoreTestUtils.h6
2 files changed, 10 insertions, 12 deletions
diff --git a/lib/backupstore/StoreTestUtils.cpp b/lib/backupstore/StoreTestUtils.cpp
index 99ebb9df..e5b05e9c 100644
--- a/lib/backupstore/StoreTestUtils.cpp
+++ b/lib/backupstore/StoreTestUtils.cpp
@@ -132,24 +132,22 @@ void init_context(TLSContext& rContext)
"testfiles/clientTrustedCAs.pem");
}
-std::auto_ptr<SocketStreamTLS> open_conn(const char *hostname,
+std::auto_ptr<SocketStream> open_conn(const char *hostname,
TLSContext& rContext)
{
init_context(rContext);
std::auto_ptr<SocketStreamTLS> conn(new SocketStreamTLS);
conn->Open(rContext, Socket::TypeINET, hostname,
BOX_PORT_BBSTORED_TEST);
- return conn;
+ return static_cast<std::auto_ptr<SocketStream> >(conn);
}
-std::auto_ptr<BackupProtocolClient> test_server_login(const char *hostname,
- TLSContext& rContext, std::auto_ptr<SocketStreamTLS>& rapConn)
+std::auto_ptr<BackupProtocolCallable> test_server_login(const char *hostname,
+ TLSContext& rContext, int flags)
{
- rapConn = open_conn(hostname, rContext);
-
// Make a protocol
- std::auto_ptr<BackupProtocolClient> protocol(new
- BackupProtocolClient(*rapConn));
+ std::auto_ptr<BackupProtocolCallable> protocol(new
+ BackupProtocolClient(open_conn(hostname, rContext)));
// Check the version
std::auto_ptr<BackupProtocolVersion> serverVersion(
@@ -158,7 +156,7 @@ std::auto_ptr<BackupProtocolClient> test_server_login(const char *hostname,
// Login
std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(
- protocol->QueryLogin(0x01234567, 0));
+ protocol->QueryLogin(0x01234567, flags));
return protocol;
}
diff --git a/lib/backupstore/StoreTestUtils.h b/lib/backupstore/StoreTestUtils.h
index d15404fa..3365a7f4 100644
--- a/lib/backupstore/StoreTestUtils.h
+++ b/lib/backupstore/StoreTestUtils.h
@@ -37,12 +37,12 @@ void set_refcount(int64_t ObjectID, uint32_t RefCount = 1);
void init_context(TLSContext& rContext);
//! Opens a connection to the server (bbstored).
-std::auto_ptr<SocketStreamTLS> open_conn(const char *hostname,
+std::auto_ptr<SocketStream> open_conn(const char *hostname,
TLSContext& rContext);
//! Opens a connection to the server (bbstored) and logs in.
-std::auto_ptr<BackupProtocolClient> test_server_login(const char *hostname,
- TLSContext& rContext, std::auto_ptr<SocketStreamTLS>& rapConn);
+std::auto_ptr<BackupProtocolCallable> test_server_login(const char *hostname,
+ TLSContext& rContext, int flags = 0);
//! Checks the number of files of each type in the store against expectations.
bool check_num_files(int files, int old, int deleted, int dirs);