summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-12-28 22:03:23 +0000
committerChris Wilson <chris+github@qwirx.com>2014-12-28 22:03:23 +0000
commit1c1872a295a8f624feda363b9edb366da97798c6 (patch)
treecbf33eb2ca84250f31c8b134a77b150d48e3d4b8
parenta0e488cdab1907167d2f02a1b88706aea7f44a79 (diff)
Add missing timeouts on command socket writes.
-rw-r--r--bin/bbackupd/BackupDaemon.cpp16
-rw-r--r--lib/server/SocketStream.h6
-rw-r--r--lib/server/WinNamedPipeStream.h6
3 files changed, 16 insertions, 12 deletions
diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp
index 4ca92aad..34dfba61 100644
--- a/bin/bbackupd/BackupDaemon.cpp
+++ b/bin/bbackupd/BackupDaemon.cpp
@@ -2062,7 +2062,7 @@ void BackupDaemon::WaitOnCommandSocket(box_time_t RequiredDelay, bool &DoSyncFla
conf.GetKeyValueInt("MaxUploadWait")
<< "\nstate " << mState << "\n";
mapCommandSocketInfo->mpConnectedSocket->Write(
- hello.str());
+ hello.str(), timeout);
// Set the timeout to something very small, so we don't wait too long on waiting
// for any incoming data
@@ -2082,7 +2082,8 @@ void BackupDaemon::WaitOnCommandSocket(box_time_t RequiredDelay, bool &DoSyncFla
}
// Ping the remote side, to provide errors which will mean the socket gets closed
- mapCommandSocketInfo->mpConnectedSocket->Write("ping\n", 5);
+ mapCommandSocketInfo->mpConnectedSocket->Write("ping\n", 5,
+ timeout);
// Wait for a command or something on the socket
std::string command;
@@ -2132,7 +2133,9 @@ void BackupDaemon::WaitOnCommandSocket(box_time_t RequiredDelay, bool &DoSyncFla
// Send a response back?
if(sendResponse)
{
- mapCommandSocketInfo->mpConnectedSocket->Write(sendOK?"ok\n":"error\n", sendOK?3:6);
+ std::string response = sendOK ? "ok\n" : "error\n";
+ mapCommandSocketInfo->mpConnectedSocket->Write(
+ response, timeout);
}
// Set timeout to something very small, so this just checks for data which is waiting
@@ -2257,8 +2260,8 @@ void BackupDaemon::SendSyncStartOrFinish(bool SendStart)
try
{
message += "\n";
- mapCommandSocketInfo->mpConnectedSocket->Write(
- message.c_str(), message.size());
+ mapCommandSocketInfo->mpConnectedSocket->Write(message,
+ 1); // short timeout, it's overlapped
}
catch(std::exception &e)
{
@@ -2989,7 +2992,8 @@ void BackupDaemon::SetState(int State)
// Something connected to the command socket, tell it about the new state
try
{
- mapCommandSocketInfo->mpConnectedSocket->Write(msg.str());
+ mapCommandSocketInfo->mpConnectedSocket->Write(msg.str(),
+ 1); // very short timeout, it's overlapped anyway
}
catch(ConnectionException &ce)
{
diff --git a/lib/server/SocketStream.h b/lib/server/SocketStream.h
index 438bd989..fd57af8f 100644
--- a/lib/server/SocketStream.h
+++ b/lib/server/SocketStream.h
@@ -51,9 +51,9 @@ public:
virtual void Write(const void *pBuffer, int NBytes,
int Timeout = IOStream::TimeOutInfinite);
- // Why not inherited from IOStream?
- virtual void Write(const std::string& rBuffer,
- int Timeout = IOStream::TimeOutInfinite)
+ // Why not inherited from IOStream? Never mind, we want to enforce
+ // supplying a timeout for network operations anyway.
+ virtual void Write(const std::string& rBuffer, int Timeout)
{
IOStream::Write(rBuffer, Timeout);
}
diff --git a/lib/server/WinNamedPipeStream.h b/lib/server/WinNamedPipeStream.h
index 60641808..4c8a1e8f 100644
--- a/lib/server/WinNamedPipeStream.h
+++ b/lib/server/WinNamedPipeStream.h
@@ -45,9 +45,9 @@ public:
virtual bool StreamDataLeft();
virtual bool StreamClosed();
- // Why not inherited from IOStream?
- virtual void Write(const std::string& rBuffer,
- int Timeout = IOStream::TimeOutInfinite)
+ // Why not inherited from IOStream? Never mind, we want to enforce
+ // supplying a timeout for network operations anyway.
+ virtual void Write(const std::string& rBuffer, int Timeout)
{
IOStream::Write(rBuffer, Timeout);
}