remove:去除冗余。

This commit is contained in:
taynpg 2024-12-15 13:14:04 +08:00
parent b02f091f79
commit 154c670839
5 changed files with 4 additions and 27 deletions

View File

@ -198,9 +198,7 @@ void CClient::handle_frame(CFrameBuffer* buf)
logger_->error("{} nullptr.", __FUNCTION__); logger_->error("{} nullptr.", __FUNCTION__);
return; return;
} }
switch (buf->type_) {
auto t = static_cast<FrameType>(buf->type_);
switch (t) {
case TYPE_GET_LIST: { case TYPE_GET_LIST: {
task_list_.clear(); task_list_.clear();
std::string source(buf->data_, buf->len_); std::string source(buf->data_, buf->len_);

View File

@ -60,11 +60,8 @@ void CTcpClient::async_recv()
if (ec) { if (ec) {
if (ec == asio::error::eof) { if (ec == asio::error::eof) {
logger_->error("Remote Server Closed."); logger_->error("Remote Server Closed.");
return;
} }
async_recv();
} else { } else {
std::lock_guard<std::mutex> lock(mutex_);
buffer_.push(tmp_buf_.data(), length); buffer_.push(tmp_buf_.data(), length);
auto* frame = CTransProtocal::parse(buffer_); auto* frame = CTransProtocal::parse(buffer_);
if (frame) { if (frame) {

View File

@ -100,9 +100,8 @@ void CTcpServer::handle_frame()
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1));
continue; continue;
} }
FrameType t = static_cast<FrameType>(buf->type_); switch (buf->type_) {
switch (t) {
case TYPE_GET_LIST: { case TYPE_GET_LIST: {
logger_->info("[{}] GetList.", buf->fid_); logger_->info("[{}] GetList.", buf->fid_);
get_client_list(&buf); get_client_list(&buf);

View File

@ -65,7 +65,6 @@ CFrameBuffer* CTransProtocal::parse(CMutBuffer& buffer)
result->tid_ = std::string(buffer.get_data() + find + 2 + 2 + 1 + 32); result->tid_ = std::string(buffer.get_data() + find + 2 + 2 + 1 + 32);
result->mark_ = mark; result->mark_ = mark;
result->type_ = static_cast<FrameType>(type); result->type_ = static_cast<FrameType>(type);
std::memset(result->data_, 0x0, len);
std::memcpy(result->data_, buffer.get_data() + find + 2 + 2 + 1 + 4 + 32 + 32, len); std::memcpy(result->data_, buffer.get_data() + find + 2 + 2 + 1 + 4 + 32 + 32, len);
buffer.remove_of(0, tail_index + 2); buffer.remove_of(0, tail_index + 2);
return result; return result;
@ -109,10 +108,4 @@ CFrameBuffer::~CFrameBuffer()
{ {
delete[] data_; delete[] data_;
len_ = 0; len_ = 0;
} }
SimpleBuffer::~SimpleBuffer()
{
delete[] data_;
len_ = 0;
}

View File

@ -40,17 +40,7 @@ public:
int len_{}; int len_{};
char mark_{}; char mark_{};
}; };
class SimpleBuffer
{
public:
SimpleBuffer() = default;
~SimpleBuffer();
public:
std::string id_;
char* data_{};
int len_{};
};
using ExFun_t = std::function<void(CFrameBuffer* buf)>; using ExFun_t = std::function<void(CFrameBuffer* buf)>;
/* /*
transm TCP transm TCP