diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-03-01 10:42:48 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2014-03-01 10:42:48 +0000 |
commit | 2b6ac135fa7071290289741c9e35747bb9f1012f (patch) | |
tree | 037507c43ac097fb2cd5850bbd57f25a553e20e8 /bin/bbackupquery | |
parent | 2ef0a9aa8cd3cd4dcfa0cd9d2014051832c52e8a (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 'bin/bbackupquery')
-rw-r--r-- | bin/bbackupquery/bbackupquery.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/bin/bbackupquery/bbackupquery.cpp b/bin/bbackupquery/bbackupquery.cpp index dbac3f27..1ff3b28a 100644 --- a/bin/bbackupquery/bbackupquery.cpp +++ b/bin/bbackupquery/bbackupquery.cpp @@ -429,15 +429,16 @@ int main(int argc, const char *argv[]) // 2. Connect to server if(!quiet) BOX_INFO("Connecting to store..."); - SocketStreamTLS socket; - socket.Open(tlsContext, Socket::TypeINET, + SocketStreamTLS *socket = new SocketStreamTLS; + std::auto_ptr<SocketStream> apSocket(socket); + socket->Open(tlsContext, Socket::TypeINET, conf.GetKeyValue("StoreHostname").c_str(), conf.GetKeyValueInt("StorePort")); // 3. Make a protocol, and handshake if(!quiet) BOX_INFO("Handshake with store..."); std::auto_ptr<BackupProtocolClient> - apConnection(new BackupProtocolClient(socket)); + apConnection(new BackupProtocolClient(apSocket)); BackupProtocolClient& connection(*(apConnection.get())); connection.Handshake(); |