Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix next_message_reader() method #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions include/hffix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2069,11 +2069,13 @@ class message_reader {
if (!is_valid_) { // this message isn't valid, so we have to try to search for the beginning of the next message.
char const* b = buffer_ + 1;
while(b < buffer_end_ - 10) {
if (!std::memcmp(b, "8=FIX", 5))
break;
if (!std::memcmp(b, "8=FIX", 5)) {
message_reader tmp(b, buffer_end_);
if (tmp.is_valid()) return tmp;
}
++b;
}
return message_reader(b, buffer_end_);
return message_reader(buffer_end_, buffer_end_);
}

return message_reader(end_.current_.value_.end_ + 1, buffer_end_);
Expand Down
Binary file modified test/expected/writer01.fix
Binary file not shown.
4 changes: 2 additions & 2 deletions test/src/reader01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int main(int argc, char** argv)
hffix::message_reader reader(buffer, buffer + buffer_length);

// Try to read as many complete messages as there are in the buffer.
for (; reader.is_complete(); reader = reader.next_message_reader()) {
for (int i = 0; reader.is_complete(); reader = reader.next_message_reader(), ++i) {
if (reader.is_valid()) {

// Here is a complete message. Read fields out of the reader.
Expand Down Expand Up @@ -98,7 +98,7 @@ int main(int argc, char** argv)
std::cerr << "Error reading fields: " << ex.what() << '\n';
}

} else {
} else if (i != 0) {
// An invalid, corrupted FIX message. Do not try to read fields
// out of this reader. The beginning of the invalid message is
// at location reader.message_begin() in the buffer, but the
Expand Down
5 changes: 4 additions & 1 deletion test/src/writer01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ int main(int argc, char** argv)

ptime tsend(date(2017,8,9), time_duration(12,34,56));

char some_data[] = "... 8=FIX ... 8=FIX ... 8=FIX ...";
memcpy(buffer, some_data, sizeof(some_data));

// We'll put a FIX Logon message in the buffer.
hffix::message_writer logon(buffer, buffer + sizeof(buffer));
hffix::message_writer logon(buffer + sizeof(some_data), buffer + sizeof(buffer));

logon.push_back_header("FIX.4.2"); // Write BeginString and BodyLength.

Expand Down