summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-12-28 22:03:33 +0000
committerChris Wilson <chris+github@qwirx.com>2014-12-28 22:03:33 +0000
commita36fc86490fd4eeb70094990008aff323882412a (patch)
tree60d669e968acd9e722b4c948784657fbf840fdfc
parent7b7456c31276011f012ae7d9f02437ae31071c8c (diff)
Whitespace and comment fixes.
Improve correctness and reduce code duplication in bbackupctl.
-rw-r--r--bin/bbackupctl/bbackupctl.cpp33
-rw-r--r--lib/server/WinNamedPipeListener.h4
-rw-r--r--lib/server/WinNamedPipeStream.cpp14
3 files changed, 24 insertions, 27 deletions
diff --git a/bin/bbackupctl/bbackupctl.cpp b/bin/bbackupctl/bbackupctl.cpp
index b07f65a4..0e0c1e9c 100644
--- a/bin/bbackupctl/bbackupctl.cpp
+++ b/bin/bbackupctl/bbackupctl.cpp
@@ -226,26 +226,26 @@ int main(int argc, const char *argv[])
Command command = Default;
std::string commandName(argv[0]);
- if (commandName == "wait-for-sync")
+ if(commandName == "wait-for-sync")
{
command = WaitForSyncStart;
}
- else if (commandName == "wait-for-end")
+ else if(commandName == "wait-for-end")
{
command = WaitForSyncEnd;
}
- else if (commandName == "sync-and-wait")
+ else if(commandName == "sync-and-wait")
{
command = SyncAndWaitForEnd;
}
- else if (commandName == "status")
+ else if(commandName == "status")
{
BOX_NOTICE("state " <<
BackupDaemon::GetStateName(currentState));
command = NoCommand;
}
- switch (command)
+ switch(command)
{
case WaitForSyncStart:
case WaitForSyncEnd:
@@ -270,7 +270,7 @@ int main(int argc, const char *argv[])
connection.Write(cmd, PROTOCOL_DEFAULT_TIMEOUT);
connection.WriteAllBuffered();
- if (currentState != 0)
+ if(currentState != 0)
{
BOX_INFO("Waiting for current sync/error state "
"to finish...");
@@ -283,8 +283,7 @@ int main(int argc, const char *argv[])
// Normal case, just send the command given, plus a
// quit command.
std::string cmd = commandName + "\n";
- connection.Write(cmd.c_str(), cmd.size(),
- PROTOCOL_DEFAULT_TIMEOUT);
+ connection.Write(cmd, PROTOCOL_DEFAULT_TIMEOUT);
}
// fall through
@@ -293,8 +292,7 @@ int main(int argc, const char *argv[])
// Normal case, just send the command given plus a
// quit command.
std::string cmd = "quit\n";
- connection.Write(cmd.c_str(), cmd.size(),
- PROTOCOL_DEFAULT_TIMEOUT);
+ connection.Write(cmd, PROTOCOL_DEFAULT_TIMEOUT);
}
}
@@ -323,17 +321,13 @@ int main(int argc, const char *argv[])
}
}
- switch (command)
+ switch(command)
{
case WaitForSyncStart:
{
// Need to wait for the state change...
if(line == "start-sync")
{
- // Send a quit command to finish nicely
- connection.Write("quit\n", 5,
- PROTOCOL_DEFAULT_TIMEOUT);
-
// And we're done
finished = true;
}
@@ -352,12 +346,8 @@ int main(int argc, const char *argv[])
{
if (syncIsRunning)
{
- BOX_TRACE("Sync finished.");
- // Send a quit command to finish nicely
- connection.Write("quit\n", 5,
- PROTOCOL_DEFAULT_TIMEOUT);
-
// And we're done
+ BOX_TRACE("Sync finished.");
finished = true;
}
else
@@ -391,6 +381,9 @@ int main(int argc, const char *argv[])
}
}
+ // Send a quit command to finish nicely
+ connection.Write("quit\n", 5, PROTOCOL_DEFAULT_TIMEOUT);
+
MAINHELPER_END
#if defined WIN32 && ! defined BOX_RELEASE_BUILD
diff --git a/lib/server/WinNamedPipeListener.h b/lib/server/WinNamedPipeListener.h
index fab11a87..956a7b5a 100644
--- a/lib/server/WinNamedPipeListener.h
+++ b/lib/server/WinNamedPipeListener.h
@@ -53,8 +53,8 @@ private:
socket.c_str(), // pipe name
PIPE_ACCESS_DUPLEX | // read/write access
FILE_FLAG_OVERLAPPED, // enabled overlapped I/O
- PIPE_TYPE_BYTE | // message type pipe
- PIPE_READMODE_BYTE | // message-read mode
+ PIPE_TYPE_BYTE |
+ PIPE_READMODE_BYTE |
PIPE_WAIT, // blocking mode
ListenBacklog + 1, // max. instances
4096, // output buffer size
diff --git a/lib/server/WinNamedPipeStream.cpp b/lib/server/WinNamedPipeStream.cpp
index a3e7575e..37a29cc8 100644
--- a/lib/server/WinNamedPipeStream.cpp
+++ b/lib/server/WinNamedPipeStream.cpp
@@ -286,7 +286,8 @@ bool WinNamedPipeStream::WaitForOverlappedOperation(OVERLAPPED& Overlapped,
"result code: " << waitResult);
}
- // object is ready to read from
+ // Overlapped operation completed successfully. Return the number
+ // of bytes transferred.
if (GetOverlappedResult(mSocketHandle, &Overlapped,
&NumBytesTransferred, TRUE))
{
@@ -294,7 +295,8 @@ bool WinNamedPipeStream::WaitForOverlappedOperation(OVERLAPPED& Overlapped,
return true;
}
- // We are here because there was an error.
+ // We are here because GetOverlappedResult() informed us that the
+ // overlapped operation encountered an error, so what was it?
DWORD err = GetLastError();
if (err == ERROR_HANDLE_EOF)
@@ -356,8 +358,7 @@ int WinNamedPipeStream::Read(void *pBuffer, int NBytes, int Timeout)
int64_t NumBytesRead;
- // satisfy from buffer if possible, to avoid
- // blocking on read.
+ // Satisfy from buffer if possible, to avoid blocking on read.
bool needAnotherRead = false;
if (mBytesInBuffer == 0)
{
@@ -467,7 +468,10 @@ void WinNamedPipeStream::Write(const void *pBuffer, int NBytes, int Timeout)
if (Success == TRUE)
{
- BOX_NOTICE("Write claimed success while overlapped?");
+ // Unfortunately this does happen. We should still call
+ // GetOverlappedResult() to get the number of bytes written,
+ // so we can treat it just the same.
+ // BOX_NOTICE("Write claimed success while overlapped?");
mWritesInProgress.push_back(new_write);
}
else