浏览代码

Z991239-1017 #comment fea 精简当前chromium中的日志

陈良瑜80374463 4 年之前
父节点
当前提交
a0dff8cada
共有 3 个文件被更改,包括 65 次插入73 次删除
  1. 19 24
      Module/mod_chromium/CSocketClient.cpp
  2. 42 41
      Module/mod_chromium/CSocketClient.h
  3. 4 8
      Module/mod_chromium/CWebsocketServer.cpp

+ 19 - 24
Module/mod_chromium/CSocketClient.cpp

@@ -11,6 +11,7 @@
 #include <string>
 #include "portCheck/portCheck.h"
 #include <thread>
+#include "guitask/format.hpp"
 
 using boost::asio::ip::tcp;
 
@@ -119,8 +120,7 @@ ErrorCodeEnum CSocketClient::Close(){
 }
 
 ErrorCodeEnum CSocketClient::Write(CMessage *pMsg){
-	::DbgEx("CSocketClient method -> write");
-	hexdump(pMsg->getPayload(), pMsg->getLength());
+	::DbgEx("CSocketClient method -> write, %s", hexdumpToString(pMsg->getPayload(), pMsg->getLength()).c_str());
 	if (m_psocket && m_psocket->is_open())
 	{
 		::DbgEx("m_psocket->async_send");
@@ -199,13 +199,10 @@ ErrorCodeEnum CSocketClient::Reconnect()
 
 
 void CSocketClient::handle_write(const boost::system::error_code& err){
-	DbgEx("CSocketClient method -> handle_write");
 	if (!err)
-	{
 		DbgEx("CSocketClient method -> handle_write succeed!");
-		return;
-	}
-	DbgEx("CSocketClient method -> handle_write error!");
+	else
+		DbgEx("CSocketClient method -> handle_write error!");
 
 }
 
@@ -237,8 +234,8 @@ void CSocketClient::handle_read(const boost::system::error_code& err,
 	DbgEx("CSocketClient handle_read well!");
 }
 
-
-void CSocketClient::hexdump(const char *buf, const int num){
+std::string CSocketClient::hexdumpToString(const char* buf, const int num)
+{
 	char str[8192 * 2] = { 0 };
 	int i = 0;
 	char c[5] = { 0 };
@@ -249,16 +246,20 @@ void CSocketClient::hexdump(const char *buf, const int num){
 			sprintf(c, "%02X ", (unsigned char)buf[i]);
 			strcat(str, c);
 		}
-		DbgEx("buffer too long to show!show pre 50 hex! CSocketClient hex buf len = %d : %s", num, str);
-		return;
+		return string_format("buffer too long to show!show pre 50 hex! CSocketClient hex buf len = %d : %s", num, str);
+		
 	}
-	for(i = 0; i < num; i++) 
+	for (i = 0; i < num; i++)
 	{
 		sprintf(c, "%02X ", (unsigned char)buf[i]);
 		strcat(str, c);
 	}
-	DbgEx("CSocketClient hex buf len = %d : %s", num, str);
-	return;
+	return string_format("CSocketClient hex buf len = %d : %s", num, str);
+}
+
+void CSocketClient::hexdump(const char *buf, const int num){
+	auto hexStr = hexdumpToString(buf, num);
+	DbgEx(hexStr.c_str());
 }
 
 void CSocketClient::thread_recv(){
@@ -311,8 +312,7 @@ void CSocketClient::thread_recv(){
 				boost::this_thread::sleep(boost::posix_time::milliseconds(100));
 			}else{
 				// select something
-				DbgEx("select something");
- 				DbgEx("buffer len = %d", msg.getBufferLength());
+				DbgEx("select something, buffer len = %d", msg.getBufferLength());
 				size_t len = 0;
 				try
 				{
@@ -320,8 +320,7 @@ void CSocketClient::thread_recv(){
 				}
 				catch (...)
 				{
-					DbgEx("first read error");
-					hexdump(msg.getWriteableData(), msg.getBufferLength());
+					DbgEx("first read error, %s", hexdumpToString(msg.getWriteableData(), msg.getBufferLength()).c_str());
 					msg.clear();
 					return;
 				}
@@ -339,13 +338,11 @@ void CSocketClient::thread_recv(){
 				}
 				catch (...)
 				{
-					DbgEx("second read error");
-					hexdump(msg.getWriteableData(), msg.getBufferLength());
+					DbgEx("second read error, %s", hexdumpToString(msg.getWriteableData(), msg.getBufferLength()).c_str());
 					msg.clear();
 					return;
 				}
- 				DbgEx("second read len = %d", len);
-				DbgEx("select something receive finish len = %d",len);
+ 				DbgEx("second read len = %d, select something receive finish len = %d", len, len);
 
 				hexdump(msg.getWriteableData(), len);
 
@@ -357,10 +354,8 @@ void CSocketClient::thread_recv(){
 					this->mMessageHandler(msg, mID);
 					DbgEx("after mMessageHandler");
 				}
-				//hexdump(msg.getWriteableData(), len);
 			}
 			msg.clear();
-			//DbgEx("Then to while routine...");
 		}
 		DbgEx("warning ! : thread_recv end!");
 	}

+ 42 - 41
Module/mod_chromium/CSocketClient.h

@@ -19,55 +19,56 @@
 bool checkHttpThreadFun(const std::string url);
 std::pair<bool, std::string> DetectActiveHttp(std::vector<std::string> urlArr);
 
-namespace Chromium{
-typedef std::deque<CMessage> CMessageQueue;
+namespace Chromium {
+	typedef std::deque<CMessage> CMessageQueue;
 
-class CSocketClient {
-	typedef CSocketClient this_type;
-	typedef boost::asio::ip::tcp::acceptor acceptor_type;
-	typedef boost::asio::ip::tcp::endpoint endpoint_type;
-	typedef boost::asio::ip::tcp::socket socket_type;
-	typedef boost::asio::ip::address address_type;
-	typedef boost::shared_ptr<socket_type> sock_ptr;
-	typedef std::vector<char> buffer_type;
-public:
-	explicit CSocketClient(CEntityBase* pEntity, unsigned int id);
-	CSocketClient(boost::asio::io_service &ios , const char* ipAddr, const char* port, CEntityBase* pEntity, unsigned int id);
-	~CSocketClient();
-	ErrorCodeEnum Connect();
-	ErrorCodeEnum Close();
-	ErrorCodeEnum Reconnect();
-	ErrorCodeEnum Write(CMessage *pMsg);
-	ErrorCodeEnum StartSocketService();
-	ErrorCodeEnum StopSocketService();
-	ErrorCodeEnum SetMessageHandler(ISocketCallback *obj);
+	class CSocketClient {
+		typedef CSocketClient this_type;
+		typedef boost::asio::ip::tcp::acceptor acceptor_type;
+		typedef boost::asio::ip::tcp::endpoint endpoint_type;
+		typedef boost::asio::ip::tcp::socket socket_type;
+		typedef boost::asio::ip::address address_type;
+		typedef boost::shared_ptr<socket_type> sock_ptr;
+		typedef std::vector<char> buffer_type;
+	public:
+		explicit CSocketClient(CEntityBase* pEntity, unsigned int id);
+		CSocketClient(boost::asio::io_service& ios, const char* ipAddr, const char* port, CEntityBase* pEntity, unsigned int id);
+		~CSocketClient();
+		ErrorCodeEnum Connect();
+		ErrorCodeEnum Close();
+		ErrorCodeEnum Reconnect();
+		ErrorCodeEnum Write(CMessage* pMsg);
+		ErrorCodeEnum StartSocketService();
+		ErrorCodeEnum StopSocketService();
+		ErrorCodeEnum SetMessageHandler(ISocketCallback* obj);
 
-private:
-	void handle_connect(const boost::system::error_code& err);
-	void handle_close(const boost::system::error_code& err);
-	void handle_read(const boost::system::error_code& err,
-		const size_t bytes_transferred, CMessage &msg);
-	void handle_write(const boost::system::error_code& err);
+	private:
+		void handle_connect(const boost::system::error_code& err);
+		void handle_close(const boost::system::error_code& err);
+		void handle_read(const boost::system::error_code& err,
+			const size_t bytes_transferred, CMessage& msg);
+		void handle_write(const boost::system::error_code& err);
 
-	void thread_recv();
+		void thread_recv();
 
-	void hexdump(const char *buf, const int num);
+		void hexdump(const char* buf, const int num);
+		std::string hexdumpToString(const char* buf, const int num);
 
-private:
-	// new test
-	endpoint_type m_ep;
-	sock_ptr m_psocket;
-	buffer_type m_buf;
+	private:
+		// new test
+		endpoint_type m_ep;
+		sock_ptr m_psocket;
+		buffer_type m_buf;
 
-	boost::thread* m_pNetThread;
-	unsigned int mID;
+		boost::thread* m_pNetThread;
+		unsigned int mID;
 
-	std::vector<char> m_vbuf;
+		std::vector<char> m_vbuf;
 
-	boost::function<void(CMessage&, unsigned int)> mMessageHandler;
-	CMessageQueue write_msgs_;
-	CEntityBase* m_pEntity;
-};
+		boost::function<void(CMessage&, unsigned int)> mMessageHandler;
+		CMessageQueue write_msgs_;
+		CEntityBase* m_pEntity;
+	};
 }
 
 #endif

+ 4 - 8
Module/mod_chromium/CWebsocketServer.cpp

@@ -356,7 +356,7 @@ void CWebsocketServer::do_sendJsonBroadcast(std::string js)
 			return;
 		}
 
-		DbgEx("Enter...");
+		DbgEx("do_sendJsonBroadcast Enter...");
 		for (auto it = m_connection_hdls.begin(); it != m_connection_hdls.end(); it++)
 		{
 			try
@@ -375,9 +375,7 @@ void CWebsocketServer::do_sendJsonBroadcast(std::string js)
 				DbgEx("other exception");
 			}
 		}
-		DbgEx("End...");
-
-		
+		DbgEx("do_sendJsonBroadcast End...");
 	}
 }
 
@@ -404,7 +402,7 @@ void CWebsocketServer::do_sendJson(std::string js, int hdlID, unsigned int id)
 		}
 		try
 		{
-			DbgEx("Enter...");
+			DbgEx("do_sendJson Enter...");
 			std::map<unsigned int, websocketpp::connection_hdl>::iterator it = m_connection_hdls.find(hdlID);
 			if (m_connection_hdls.end() != it)
 			{
@@ -415,9 +413,7 @@ void CWebsocketServer::do_sendJson(std::string js, int hdlID, unsigned int id)
 			else {
 				DbgEx("ws connection handler not found! id = %u", id);
 			}
-
-
-			DbgEx("End...");
+			DbgEx("do_sendJson End...");
 		}
 		catch (const websocketpp::lib::error_code& e)
 		{