aboutsummaryrefslogtreecommitdiff
path: root/daemon/AnnotateListener.cpp
diff options
context:
space:
mode:
authorDrew Richardson <drew.richardson@arm.com>2014-10-22 12:00:00 -0700
committerDrew Richardson <drew.richardson@arm.com>2014-12-19 15:59:12 -0800
commitecc3d86ea62f7be7defa303d1d14b8506ec63e75 (patch)
tree4a0c3fb31869e2eca869f3eb2d35c6d1391ecd68 /daemon/AnnotateListener.cpp
parent6a98fbff8b9f8a23045efdea51784b479cefac7f (diff)
gator: Version 5.205.20
Signed-off-by: Drew Richardson <drew.richardson@arm.com>
Diffstat (limited to 'daemon/AnnotateListener.cpp')
-rw-r--r--daemon/AnnotateListener.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/daemon/AnnotateListener.cpp b/daemon/AnnotateListener.cpp
new file mode 100644
index 0000000..50110b4
--- /dev/null
+++ b/daemon/AnnotateListener.cpp
@@ -0,0 +1,69 @@
+/**
+ * Copyright (C) ARM Limited 2014. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "AnnotateListener.h"
+
+#include <unistd.h>
+
+#include "OlySocket.h"
+
+struct AnnotateClient {
+ AnnotateClient *next;
+ int fd;
+};
+
+AnnotateListener::AnnotateListener() : mClients(NULL), mSock(NULL) {
+}
+
+AnnotateListener::~AnnotateListener() {
+ close();
+ delete mSock;
+}
+
+void AnnotateListener::setup() {
+ mSock = new OlyServerSocket(8082);
+}
+
+int AnnotateListener::getFd() {
+ return mSock->getFd();
+}
+
+void AnnotateListener::handle() {
+ AnnotateClient *const client = new AnnotateClient();
+ client->fd = mSock->acceptConnection();
+ client->next = mClients;
+ mClients = client;
+}
+
+void AnnotateListener::close() {
+ mSock->closeServerSocket();
+ while (mClients != NULL) {
+ ::close(mClients->fd);
+ AnnotateClient *next = mClients->next;
+ delete mClients;
+ mClients = next;
+ }
+}
+
+void AnnotateListener::signal() {
+ const char ch = 0;
+ AnnotateClient **ptr = &mClients;
+ AnnotateClient *client = mClients;
+ while (client != NULL) {
+ if (write(client->fd, &ch, sizeof(ch)) != 1) {
+ ::close(client->fd);
+ AnnotateClient *next = client->next;
+ delete client;
+ *ptr = next;
+ client = next;
+ continue;
+ }
+ ptr = &client->next;
+ client = client->next;
+ }
+}