You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2019/02/27 15:22:39 UTC

[trafficserver] branch master updated: ProcessManager: Add string_view message overload.

This is an automated email from the ASF dual-hosted git repository.

amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 040ad18  ProcessManager: Add string_view message overload.
040ad18 is described below

commit 040ad1869e46a3aae905bf259b8d1da0de46a49d
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Tue Feb 19 16:38:28 2019 -0600

    ProcessManager: Add string_view message overload.
---
 mgmt/ProcessManager.cc | 21 +++++++++++++++++++++
 mgmt/ProcessManager.h  | 15 ++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/mgmt/ProcessManager.cc b/mgmt/ProcessManager.cc
index ad0c3f7..e8e6866 100644
--- a/mgmt/ProcessManager.cc
+++ b/mgmt/ProcessManager.cc
@@ -243,7 +243,28 @@ ProcessManager::signalManager(int msg_id, const char *data_raw, int data_len)
   mh->msg_id   = msg_id;
   mh->data_len = data_len;
   memcpy((char *)mh + sizeof(MgmtMessageHdr), data_raw, data_len);
+  this->signalManager(mh);
+}
+
+void
+ProcessManager::signalManager(int msg_id, std::string_view text)
+{
+  MgmtMessageHdr *mh;
 
+  // Make space for the extra null terminator.
+  mh           = static_cast<MgmtMessageHdr *>(ats_malloc(sizeof(MgmtMessageHdr) + text.size() + 1));
+  auto body    = reinterpret_cast<char *>(mh + 1); // start of the message body.
+  mh->msg_id   = msg_id;
+  mh->data_len = text.size() + 1;
+  memcpy(body, text.data(), text.size());
+  body[text.size()] = '\0';
+
+  this->signalManager(mh);
+}
+
+void
+ProcessManager::signalManager(MgmtMessageHdr *mh)
+{
   ink_release_assert(::enqueue(mgmt_signal_queue, mh));
 
 #if HAVE_EVENTFD
diff --git a/mgmt/ProcessManager.h b/mgmt/ProcessManager.h
index dcfeb91..cc79fbc 100644
--- a/mgmt/ProcessManager.h
+++ b/mgmt/ProcessManager.h
@@ -25,12 +25,14 @@
 
 #pragma once
 
+#include <functional>
+#include <string_view>
+
 #include "MgmtUtils.h"
 #include "BaseManager.h"
 #include "tscore/ink_sock.h"
 
 #include "tscore/ink_apidefs.h"
-#include <functional>
 
 #if HAVE_EVENTFD
 #include <sys/eventfd.h>
@@ -56,6 +58,17 @@ public:
   inkcoreapi void signalManager(int msg_id, const char *data_str);
   inkcoreapi void signalManager(int msg_id, const char *data_raw, int data_len);
 
+  /** Send a management message of type @a msg_id with @a text.
+   *
+   * @param msg_id ID for the message.
+   * @param text Content for the message.
+   *
+   * A terminating null character is added automatically.
+   */
+  inkcoreapi void signalManager(int msg_id, std::string_view text);
+
+  inkcoreapi void signalManager(MgmtMessageHdr *mh);
+
   void reconfigure();
   void initLMConnection();
   void handleMgmtMsgFromLM(MgmtMessageHdr *mh);