fix:修正Server端,漏解析包bug。

This commit is contained in:
taynpg 2024-12-18 12:55:00 +08:00
parent 004d894129
commit 0cafcaf643
2 changed files with 12 additions and 10 deletions

View File

@ -63,18 +63,16 @@ void CTcpClient::async_recv()
}
} else {
buffer_.push(tmp_buf_.data(), length);
bool done = true;
while (done) {
while (true) {
auto* frame = CTransProtocal::parse(buffer_);
if (frame) {
if (fun_) {
fun_(frame);
}
delete frame;
} else {
done = false;
continue;
}
break;
}
async_recv();
}

View File

@ -238,11 +238,15 @@ void CTcpServer::th_client(std::shared_ptr<asio::ip::tcp::socket> socket, const
}
cache->buffer_.push(cache->tmp_buf_.data(), length);
auto* frame = CTransProtocal::parse(cache->buffer_);
if (frame) {
frame->fid_ = client_key;
std::lock_guard<std::mutex> lock(buf_mut_);
cache_.push_back(frame);
while (true) {
auto* frame = CTransProtocal::parse(cache->buffer_);
if (frame) {
frame->fid_ = client_key;
std::lock_guard<std::mutex> lock(buf_mut_);
cache_.push_back(frame);
continue;
}
break;
}
}
} catch (std::exception& e) {