summaryrefslogtreecommitdiffstats
path: root/configd/src/apps/sentinel/command-connection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'configd/src/apps/sentinel/command-connection.cpp')
-rw-r--r--configd/src/apps/sentinel/command-connection.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/configd/src/apps/sentinel/command-connection.cpp b/configd/src/apps/sentinel/command-connection.cpp
new file mode 100644
index 00000000000..9b35d801ecb
--- /dev/null
+++ b/configd/src/apps/sentinel/command-connection.cpp
@@ -0,0 +1,58 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <unistd.h>
+#include <stdarg.h>
+#include <cstdio>
+#include <cstring>
+#include <sys/socket.h>
+
+#include "command-connection.h"
+#include "line-splitter.h"
+
+namespace config {
+namespace sentinel {
+
+CommandConnection::CommandConnection(int f)
+ : _fd(f),
+ _lines(f)
+{
+}
+
+bool
+CommandConnection::isFinished() const
+{
+ return _lines.eof();
+}
+
+char *
+CommandConnection::getCommand()
+{
+ return _lines.getLine();
+}
+
+CommandConnection::~CommandConnection()
+{
+ close(_fd);
+}
+
+void
+CommandConnection::finish()
+{
+ ::shutdown(_fd, SHUT_RDWR);
+}
+
+int
+CommandConnection::printf(const char *fmt, ...)
+{
+ char buf[10000];
+ va_list args;
+ va_start(args, fmt);
+
+ int ret = vsnprintf(buf, sizeof buf, fmt, args);
+ va_end(args);
+
+ write(_fd, buf, strlen(buf));
+ return ret;
+}
+
+} // end namespace config::sentinel
+} // end namespace config