Commit aba307ce authored by Chen Bill's avatar Chen Bill

Replay: add can_read

parent d908fd9a
...@@ -133,6 +133,7 @@ bool Replay::OpenReplay(const wchar_t* name) { ...@@ -133,6 +133,7 @@ bool Replay::OpenReplay(const wchar_t* name) {
comp_size = 0; comp_size = 0;
} }
is_replaying = true; is_replaying = true;
can_read = true;
if (!ReadInfo()) { if (!ReadInfo()) {
Reset(); Reset();
return false; return false;
...@@ -176,10 +177,6 @@ bool Replay::ReadNextResponse(unsigned char resp[]) { ...@@ -176,10 +177,6 @@ bool Replay::ReadNextResponse(unsigned char resp[]) {
unsigned char len{}; unsigned char len{};
if (!ReadData(&len, sizeof len)) if (!ReadData(&len, sizeof len))
return false; return false;
if (len > SIZE_RETURN_VALUE) {
is_replaying = false;
return false;
}
if (!ReadData(resp, len)) if (!ReadData(resp, len))
return false; return false;
return true; return true;
...@@ -196,10 +193,10 @@ void Replay::ReadHeader(ReplayHeader& header) { ...@@ -196,10 +193,10 @@ void Replay::ReadHeader(ReplayHeader& header) {
header = pheader; header = pheader;
} }
bool Replay::ReadData(void* data, size_t length) { bool Replay::ReadData(void* data, size_t length) {
if(!is_replaying) if (!is_replaying || !can_read)
return false; return false;
if (data_position + length > replay_size) { if (data_position + length > replay_size) {
is_replaying = false; can_read = false;
return false; return false;
} }
if (length) if (length)
...@@ -212,10 +209,12 @@ int32_t Replay::ReadInt32() { ...@@ -212,10 +209,12 @@ int32_t Replay::ReadInt32() {
} }
void Replay::Rewind() { void Replay::Rewind() {
data_position = 0; data_position = 0;
can_read = true;
} }
void Replay::Reset() { void Replay::Reset() {
is_recording = false; is_recording = false;
is_replaying = false; is_replaying = false;
can_read = false;
replay_size = 0; replay_size = 0;
comp_size = 0; comp_size = 0;
data_position = 0; data_position = 0;
......
...@@ -94,6 +94,7 @@ private: ...@@ -94,6 +94,7 @@ private:
size_t data_position{}; size_t data_position{};
bool is_recording{}; bool is_recording{};
bool is_replaying{}; bool is_replaying{};
bool can_read{};
}; };
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment