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: split osc packets #928

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
29 changes: 26 additions & 3 deletions src/protocol/osc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ struct client::impl : public spl::enable_shared_from_this<client::impl>
std::map<udp::endpoint, int> reference_counts_by_endpoint_;
std::vector<char> buffer_;

int64_t time_ = 0;

std::mutex mutex_;
std::condition_variable cond_;
boost::optional<core::monitor::data_map_t> bundle_opt_;
Expand Down Expand Up @@ -112,10 +114,14 @@ struct client::impl : public spl::enable_shared_from_this<client::impl>
continue;
}

::osc::OutboundPacketStream o(reinterpret_cast<char*>(buffer_.data()),
static_cast<unsigned long>(buffer_.size()));
// TODO: Should use server clock.
time_++;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good enough


char buffer[8192];

o << ::osc::BeginBundle();
::osc::OutboundPacketStream o(buffer_, 8192);

o << ::osc::BeginBundle(time_);

for (auto& p : bundle) {
o << ::osc::BeginMessage(p.first.c_str());
Expand All @@ -126,13 +132,30 @@ struct client::impl : public spl::enable_shared_from_this<client::impl>
}

o << ::osc::EndMessage;

if (o.Size() >= 1024) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limit is 1500 bytes... this an approximation.

o << ::osc::EndBundle;

boost::system::error_code ec;
for (const auto& endpoint : endpoints) {
// TODO: async send
socket_.send_to(boost::asio::buffer(o.Data(), o.Size()), endpoint, 0, ec);
// TODO Handle error
}

o.Clear();

o << ::osc::BeginBundle(time_);
}
}

o << ::osc::EndBundle;

boost::system::error_code ec;
for (const auto& endpoint : endpoints) {
// TODO: async send
socket_.send_to(boost::asio::buffer(o.Data(), o.Size()), endpoint, 0, ec);
// TODO Handle error
}
}
} catch (...) {
Expand Down