summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/bbackupd/BackupClientContext.cpp50
-rw-r--r--bin/bbackupd/BackupClientContext.h5
-rw-r--r--bin/bbackupquery/bbackupquery.cpp7
-rw-r--r--bin/bbstored/BackupStoreDaemon.cpp25
-rw-r--r--bin/bbstored/BackupStoreDaemon.h6
5 files changed, 40 insertions, 53 deletions
diff --git a/bin/bbackupd/BackupClientContext.cpp b/bin/bbackupd/BackupClientContext.cpp
index 26df04be..45c48a67 100644
--- a/bin/bbackupd/BackupClientContext.cpp
+++ b/bin/bbackupd/BackupClientContext.cpp
@@ -73,7 +73,8 @@ BackupClientContext::BackupClientContext
mKeepAliveTimer(0, "KeepAliveTime"),
mbIsManaged(false),
mrProgressNotifier(rProgressNotifier),
- mTcpNiceMode(TcpNiceMode)
+ mTcpNiceMode(TcpNiceMode),
+ mpNice(NULL)
{
}
@@ -113,13 +114,12 @@ BackupProtocolClient &BackupClientContext::GetConnection()
{
return *mapConnection;
}
-
- // there shouldn't be a connection open
- ASSERT(mapSocket.get() == 0);
+
// Defensive. Must close connection before releasing any old socket.
mapConnection.reset();
- mapSocket.reset(new SocketStreamTLS);
-
+
+ std::auto_ptr<SocketStream> apSocket(new SocketStreamTLS);
+
try
{
// Defensive.
@@ -130,21 +130,22 @@ BackupProtocolClient &BackupClientContext::GetConnection()
mHostname << "'...");
// Connect!
- ((SocketStreamTLS *)(mapSocket.get()))->Open(mrTLSContext,
+ ((SocketStreamTLS *)(apSocket.get()))->Open(mrTLSContext,
Socket::TypeINET, mHostname, mPort);
if(mTcpNiceMode)
{
- // Pass control of mapSocket to NiceSocketStream,
+ // Pass control of apSocket to NiceSocketStream,
// which will take care of destroying it for us.
- mapNice.reset(new NiceSocketStream(mapSocket));
- mapConnection.reset(new BackupProtocolClient(*mapNice));
+ // But we need to hang onto a pointer to the nice
+ // socket, so we can enable and disable nice mode.
+ // This is scary, it could be deallocated under us.
+ mpNice = new NiceSocketStream(apSocket);
+ apSocket.reset(mpNice);
}
- else
- {
- mapConnection.reset(new BackupProtocolClient(*mapSocket));
- }
-
+
+ mapConnection.reset(new BackupProtocolClient(apSocket));
+
// Set logging option
mapConnection->SetLogToSysLog(mExtendedLogging);
@@ -165,10 +166,10 @@ BackupProtocolClient &BackupClientContext::GetConnection()
mapConnection->SetLogToFile(mpExtendedLogFileHandle);
}
}
-
+
// Handshake
mapConnection->Handshake();
-
+
// Check the version of the server
{
std::auto_ptr<BackupProtocolVersion> serverVersion(
@@ -192,8 +193,6 @@ BackupProtocolClient &BackupClientContext::GetConnection()
try
{
mapConnection->QueryFinished();
- mapNice.reset();
- mapSocket.reset();
}
catch(...)
{
@@ -222,8 +221,6 @@ BackupProtocolClient &BackupClientContext::GetConnection()
{
// Clean up.
mapConnection.reset();
- mapNice.reset();
- mapSocket.reset();
throw;
}
@@ -269,17 +266,6 @@ void BackupClientContext::CloseAnyOpenConnection()
mapConnection.reset();
}
- try
- {
- // Be nice about closing the socket
- mapNice.reset();
- mapSocket.reset();
- }
- catch(...)
- {
- // Ignore errors
- }
-
// Delete any pending list
if(mpDeleteList != 0)
{
diff --git a/bin/bbackupd/BackupClientContext.h b/bin/bbackupd/BackupClientContext.h
index 1fcc6ede..7e081e2d 100644
--- a/bin/bbackupd/BackupClientContext.h
+++ b/bin/bbackupd/BackupClientContext.h
@@ -214,7 +214,7 @@ public:
{
if(mTcpNiceMode)
{
- mapNice->SetEnabled(enabled);
+ mpNice->SetEnabled(enabled);
}
}
@@ -226,8 +226,6 @@ private:
std::string mHostname;
int mPort;
uint32_t mAccountNumber;
- std::auto_ptr<SocketStream> mapSocket;
- std::auto_ptr<NiceSocketStream> mapNice;
std::auto_ptr<BackupProtocolClient> mapConnection;
bool mExtendedLogging;
bool mExtendedLogToFile;
@@ -246,6 +244,7 @@ private:
int mMaximumDiffingTime;
ProgressNotifier &mrProgressNotifier;
bool mTcpNiceMode;
+ NiceSocketStream *mpNice;
};
#endif // BACKUPCLIENTCONTEXT__H
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();
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