|
@@ -11,7 +11,6 @@
|
|
|
#include <string>
|
|
|
#include "portCheck/portCheck.h"
|
|
|
#include <thread>
|
|
|
-#include "guitask/format.hpp"
|
|
|
|
|
|
using boost::asio::ip::tcp;
|
|
|
|
|
@@ -120,7 +119,8 @@ ErrorCodeEnum CSocketClient::Close(){
|
|
|
}
|
|
|
|
|
|
ErrorCodeEnum CSocketClient::Write(CMessage *pMsg){
|
|
|
- ::DbgEx("CSocketClient method -> write,----%s", hexdumpToString(pMsg->getPayload(), pMsg->getLength()).c_str());
|
|
|
+ ::DbgEx("CSocketClient method -> write");
|
|
|
+ hexdump(pMsg->getPayload(), pMsg->getLength());
|
|
|
if (m_psocket && m_psocket->is_open())
|
|
|
{
|
|
|
::DbgEx("m_psocket->async_send");
|
|
@@ -239,12 +239,6 @@ void CSocketClient::handle_read(const boost::system::error_code& err,
|
|
|
|
|
|
|
|
|
void CSocketClient::hexdump(const char *buf, const int num){
|
|
|
- auto dstStr = hexdumpToString(buf, num);
|
|
|
- DbgEx(dstStr.c_str());
|
|
|
-}
|
|
|
-
|
|
|
-std::string hexdumpToString(const char* buf, const int num)
|
|
|
-{
|
|
|
char str[8192 * 2] = { 0 };
|
|
|
int i = 0;
|
|
|
char c[5] = { 0 };
|
|
@@ -255,14 +249,16 @@ std::string hexdumpToString(const char* buf, const int num)
|
|
|
sprintf(c, "%02X ", (unsigned char)buf[i]);
|
|
|
strcat(str, c);
|
|
|
}
|
|
|
- return string_format("pre 50 hex! CSocketClient hex buf len = %d : %s", num, str);
|
|
|
+ DbgEx("buffer too long to show!show pre 50 hex! CSocketClient hex buf len = %d : %s", num, str);
|
|
|
+ return;
|
|
|
}
|
|
|
- for (i = 0; i < num; i++)
|
|
|
+ for(i = 0; i < num; i++)
|
|
|
{
|
|
|
sprintf(c, "%02X ", (unsigned char)buf[i]);
|
|
|
strcat(str, c);
|
|
|
}
|
|
|
- return string_format("CSocketClient hex buf len = %d : %s", num, str);
|
|
|
+ DbgEx("CSocketClient hex buf len = %d : %s", num, str);
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
void CSocketClient::thread_recv(){
|
|
@@ -281,6 +277,8 @@ void CSocketClient::thread_recv(){
|
|
|
while (true)
|
|
|
{
|
|
|
boost::this_thread::sleep(boost::posix_time::milliseconds(1));
|
|
|
+// boost::this_thread::interruption_point();
|
|
|
+
|
|
|
boost::system::error_code ec;
|
|
|
|
|
|
FD_ZERO(&read_flags);
|
|
@@ -313,7 +311,8 @@ void CSocketClient::thread_recv(){
|
|
|
boost::this_thread::sleep(boost::posix_time::milliseconds(100));
|
|
|
}else{
|
|
|
// select something
|
|
|
- DbgEx("select something, buffer len = %d", msg.getBufferLength());
|
|
|
+ DbgEx("select something");
|
|
|
+ DbgEx("buffer len = %d", msg.getBufferLength());
|
|
|
size_t len = 0;
|
|
|
try
|
|
|
{
|
|
@@ -321,11 +320,13 @@ void CSocketClient::thread_recv(){
|
|
|
}
|
|
|
catch (...)
|
|
|
{
|
|
|
- DbgEx("first read error, %s", hexdumpToString(msg.getWriteableData(), msg.getBufferLength()).c_str());
|
|
|
+ DbgEx("first read error");
|
|
|
+ hexdump(msg.getWriteableData(), msg.getBufferLength());
|
|
|
msg.clear();
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+ DbgEx("first read len = %d", len);
|
|
|
+
|
|
|
if (0 >= len)
|
|
|
{
|
|
|
DbgEx("socket has been closed!");
|
|
@@ -334,16 +335,19 @@ void CSocketClient::thread_recv(){
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
- DbgEx("first read len = %d, dstReadLen = %d", len, *(int*)(msg.getWriteableData()));
|
|
|
len = m_psocket->receive(boost::asio::buffer(msg.getWriteableData() + 4, *(int*)(msg.getWriteableData()) + 4), 0, ec);
|
|
|
}
|
|
|
catch (...)
|
|
|
{
|
|
|
- DbgEx("second read error, %s", hexdumpToString(msg.getWriteableData(), msg.getBufferLength()).c_str());
|
|
|
+ DbgEx("second read error");
|
|
|
+ hexdump(msg.getWriteableData(), msg.getBufferLength());
|
|
|
msg.clear();
|
|
|
return;
|
|
|
}
|
|
|
- DbgEx("second read len = %d, select something receive finish len = %d, %s", len, len, hexdumpToString(msg.getWriteableData(), len).c_str());
|
|
|
+ DbgEx("second read len = %d", len);
|
|
|
+ DbgEx("select something receive finish len = %d",len);
|
|
|
+
|
|
|
+ hexdump(msg.getWriteableData(), len);
|
|
|
|
|
|
// ÓÃÀ´´¦Àí·¢Ë͸øwebsocket
|
|
|
// todo fix select len = 0
|
|
@@ -353,8 +357,10 @@ 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!");
|
|
|
}
|