summaryrefslogtreecommitdiff
path: root/bin/bbstored
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 /bin/bbstored
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 'bin/bbstored')
-rw-r--r--bin/bbstored/BackupStoreDaemon.cpp25
-rw-r--r--bin/bbstored/BackupStoreDaemon.h6
2 files changed, 16 insertions, 15 deletions
diff --git a/bin/bbstored/BackupStoreDaemon.cpp b/bin/bbstored/BackupStoreDaemon.cpp
index 2649e0a2..8fddf125 100644
--- a/bin/bbstored/BackupStoreDaemon.cpp
+++ b/bin/bbstored/BackupStoreDaemon.cpp
@@ -272,11 +272,11 @@ void BackupStoreDaemon::Run()
// Created: 2003/08/20
//
// --------------------------------------------------------------------------
-void BackupStoreDaemon::Connection(SocketStreamTLS &rStream)
+void BackupStoreDaemon::Connection(std::auto_ptr<SocketStreamTLS> apStream)
{
try
{
- Connection2(rStream);
+ Connection2(apStream);
}
catch(BoxException &e)
{
@@ -304,10 +304,10 @@ void BackupStoreDaemon::Connection(SocketStreamTLS &rStream)
// Created: 2006/11/12
//
// --------------------------------------------------------------------------
-void BackupStoreDaemon::Connection2(SocketStreamTLS &rStream)
+void BackupStoreDaemon::Connection2(std::auto_ptr<SocketStreamTLS> apStream)
{
// Get the common name from the certificate
- std::string clientCommonName(rStream.GetPeerCommonName());
+ std::string clientCommonName(apStream->GetPeerCommonName());
// Log the name
BOX_INFO("Client certificate CN: " << clientCommonName);
@@ -346,7 +346,8 @@ void BackupStoreDaemon::Connection2(SocketStreamTLS &rStream)
}
// Handle a connection with the backup protocol
- BackupProtocolServer server(rStream);
+ std::auto_ptr<SocketStream> apPlainStream(apStream);
+ BackupProtocolServer server(apPlainStream);
server.SetLogToSysLog(mExtendedLogging);
server.SetTimeout(BACKUP_STORE_TIMEOUT);
try
@@ -355,22 +356,22 @@ void BackupStoreDaemon::Connection2(SocketStreamTLS &rStream)
}
catch(...)
{
- LogConnectionStats(id, context.GetAccountName(), rStream);
+ LogConnectionStats(id, context.GetAccountName(), server);
throw;
}
- LogConnectionStats(id, context.GetAccountName(), rStream);
+ LogConnectionStats(id, context.GetAccountName(), server);
context.CleanUp();
}
void BackupStoreDaemon::LogConnectionStats(uint32_t accountId,
- const std::string& accountName, const SocketStreamTLS &s)
+ const std::string& accountName, const BackupProtocolServer &server)
{
// Log the amount of data transferred
BOX_NOTICE("Connection statistics for " <<
BOX_FORMAT_ACCOUNT(accountId) << " "
"(name=" << accountName << "):"
- " IN=" << s.GetBytesRead() <<
- " OUT=" << s.GetBytesWritten() <<
- " NET_IN=" << (s.GetBytesRead() - s.GetBytesWritten()) <<
- " TOTAL=" << (s.GetBytesRead() + s.GetBytesWritten()));
+ " IN=" << server.GetBytesRead() <<
+ " OUT=" << server.GetBytesWritten() <<
+ " NET_IN=" << (server.GetBytesRead() - server.GetBytesWritten()) <<
+ " TOTAL=" << (server.GetBytesRead() + server.GetBytesWritten()));
}
diff --git a/bin/bbstored/BackupStoreDaemon.h b/bin/bbstored/BackupStoreDaemon.h
index ce538477..a2dab5e5 100644
--- a/bin/bbstored/BackupStoreDaemon.h
+++ b/bin/bbstored/BackupStoreDaemon.h
@@ -52,8 +52,8 @@ protected:
virtual void Run();
- virtual void Connection(SocketStreamTLS &rStream);
- void Connection2(SocketStreamTLS &rStream);
+ virtual void Connection(std::auto_ptr<SocketStreamTLS> apStream);
+ void Connection2(std::auto_ptr<SocketStreamTLS> apStream);
virtual const char *DaemonName() const;
virtual std::string DaemonBanner() const;
@@ -64,7 +64,7 @@ protected:
void HousekeepingProcess();
void LogConnectionStats(uint32_t accountId,
- const std::string& accountName, const SocketStreamTLS &s);
+ const std::string& accountName, const BackupProtocolServer &server);
public:
// HousekeepingInterface implementation