|
@@ -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!");
|
|
|
}
|