fix:修正Server端,漏解析包bug。
This commit is contained in:
parent
004d894129
commit
0cafcaf643
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user