Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactor frame parsing \& helper code

  • Loading branch information...
commit 22e1cd65635a12be5b617b629fda5427d840b1d8 1 parent b55403e
@ekarak authored
Showing with 80 additions and 0 deletions.
  1. +54 −0 helpers.cpp
  2. +26 −0 helpers.h
View
54 helpers.cpp
@@ -0,0 +1,54 @@
+/*
+ * helpers.cpp
+ *
+ * Created on: 22 Απρ 2012
+ * Author: ekarak
+ */
+
+
+#include <helpers.h>
+
+ void hexdump(const void *ptr, int buflen) {
+ unsigned char *buf = (unsigned char*)ptr;
+ int i, j;
+ for (i=0; i<buflen; i+=16) {
+ printf("%06x: ", i);
+ for (j=0; j<16; j++)
+ if (i+j < buflen)
+ printf("%02x ", buf[i+j]);
+ else
+ printf(" ");
+ printf(" ");
+ for (j=0; j<16; j++)
+ if (i+j < buflen)
+ printf("%c", isprint(buf[i+j]) ? buf[i+j] : '.');
+ printf("\n");
+ }
+ }
+
+ void hexdump(boost::asio::streambuf& sb) {
+ std::istream is(&sb);
+ std::string str;
+ is >> str;
+ hexdump(str.c_str(), str.size());
+ }
+
+ void debug_print(string& str) {
+ boost::format fmt = boost::format(str.c_str());
+ debug_print(fmt);
+ }
+
+ void debug_print(const char* cstr) {
+ boost::format fmt = boost::format(cstr);
+ debug_print(fmt);
+ }
+
+ boost::mutex global_stream_lock;
+ void debug_print(boost::format& fmt) {
+#ifdef DEBUG_STOMP
+ global_stream_lock.lock();
+ std::cout << "[" << boost::this_thread::get_id() << "] BoostStomp:" << fmt.str() << endl;
+ global_stream_lock.unlock();
+#endif
+ }
+
View
26 helpers.h
@@ -0,0 +1,26 @@
+/*
+ * helpers.h
+ *
+ * Created on: 22 Απρ 2012
+ * Author: ekarak
+ */
+
+#ifndef HELPERS_H_
+#define HELPERS_H_
+
+#include <boost/asio.hpp>
+#include <boost/format.hpp>
+#include <boost/thread.hpp>
+#include <string>
+
+using namespace std;
+
+// helper function
+void hexdump(const void *ptr, int buflen);
+void debug_print(boost::format& fmt);
+void debug_print(string& str);
+void debug_print(const char* str);
+
+
+
+#endif /* HELPERS_H_ */
Please sign in to comment.
Something went wrong with that request. Please try again.