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 { } else {
buffer_.push(tmp_buf_.data(), length); buffer_.push(tmp_buf_.data(), length);
while (true) {
bool done = true;
while (done) {
auto* frame = CTransProtocal::parse(buffer_); auto* frame = CTransProtocal::parse(buffer_);
if (frame) { if (frame) {
if (fun_) { if (fun_) {
fun_(frame); fun_(frame);
} }
delete frame; delete frame;
} else { continue;
done = false;
} }
break;
} }
async_recv(); 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); cache->buffer_.push(cache->tmp_buf_.data(), length);
auto* frame = CTransProtocal::parse(cache->buffer_); while (true) {
if (frame) { auto* frame = CTransProtocal::parse(cache->buffer_);
frame->fid_ = client_key; if (frame) {
std::lock_guard<std::mutex> lock(buf_mut_); frame->fid_ = client_key;
cache_.push_back(frame); std::lock_guard<std::mutex> lock(buf_mut_);
cache_.push_back(frame);
continue;
}
break;
} }
} }
} catch (std::exception& e) { } catch (std::exception& e) {