summaryrefslogtreecommitdiffstats
path: root/src/publisher
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-08-03 12:01:51 +0300
committerimarom <imarom@cisco.com>2016-08-03 15:03:09 +0300
commit35ab1e1766baedee576d282c928ac37b42f66e8d (patch)
tree182f311e6822a7ccf1f8497825ad275643604394 /src/publisher
parentbcc2ca1a462ac65dec74e65c81e633e4f30d7fc1 (diff)
async compressed - https://trex-tgn.cisco.com/youtrack/issue/trex-232
Diffstat (limited to 'src/publisher')
-rw-r--r--src/publisher/trex_publisher.cpp26
-rw-r--r--src/publisher/trex_publisher.h7
2 files changed, 29 insertions, 4 deletions
diff --git a/src/publisher/trex_publisher.cpp b/src/publisher/trex_publisher.cpp
index f56d56df..850b5955 100644
--- a/src/publisher/trex_publisher.cpp
+++ b/src/publisher/trex_publisher.cpp
@@ -20,6 +20,7 @@ limitations under the License.
*/
#include "trex_publisher.h"
+#include "trex_rpc_zip.h"
#include <zmq.h>
#include <assert.h>
#include <sstream>
@@ -73,13 +74,32 @@ TrexPublisher::Delete(){
void
-TrexPublisher::publish_json(const std::string &s){
+TrexPublisher::publish_json(const std::string &s, uint32_t zip_threshold){
+
if (m_publisher) {
- int size = zmq_send (m_publisher, s.c_str(), s.length(), 0);
- assert(size == s.length());
+ if ( (zip_threshold > 0) && (s.size() > zip_threshold) ) {
+ publish_zipped_json(s);
+ } else {
+ publish_raw_json(s);
+ }
}
}
+void
+TrexPublisher::publish_zipped_json(const std::string &s) {
+ std::string compressed_msg;
+
+ TrexRpcZip::compress(s, compressed_msg);
+ int size = zmq_send (m_publisher, compressed_msg.c_str(), compressed_msg.length(), 0);
+ assert(size == compressed_msg.length());
+}
+
+void
+TrexPublisher::publish_raw_json(const std::string &s) {
+ int size = zmq_send (m_publisher, s.c_str(), s.length(), 0);
+ assert(size == s.length());
+}
+
void
TrexPublisher::publish_event(event_type_e type, const Json::Value &data) {
Json::FastWriter writer;
diff --git a/src/publisher/trex_publisher.h b/src/publisher/trex_publisher.h
index 1d283478..fb7226c4 100644
--- a/src/publisher/trex_publisher.h
+++ b/src/publisher/trex_publisher.h
@@ -38,7 +38,7 @@ public:
virtual bool Create(uint16_t port, bool disable);
virtual void Delete();
- virtual void publish_json(const std::string &s);
+ virtual void publish_json(const std::string &s, uint32_t zip_threshold = MSG_COMPRESS_THRESHOLD);
enum event_type_e {
EVENT_PORT_STARTED = 0,
@@ -71,9 +71,14 @@ public:
private:
void show_zmq_last_error(const std::string &err);
+ void publish_zipped_json(const std::string &s);
+ void publish_raw_json(const std::string &s);
+
private:
void * m_context;
void * m_publisher;
+
+ static const int MSG_COMPRESS_THRESHOLD = 256;
};
#endif /* __TREX_PUBLISHER_H__ */