Skip to content

Commit 09e2997

Browse files
committed
fix: split osc packets
1 parent 97cbe67 commit 09e2997

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/protocol/osc/client.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ struct client::impl : public spl::enable_shared_from_this<client::impl>
7373
std::map<udp::endpoint, int> reference_counts_by_endpoint_;
7474
std::vector<char> buffer_;
7575

76+
int64_t time_ = 0;
77+
7678
std::mutex mutex_;
7779
std::condition_variable cond_;
7880
boost::optional<core::monitor::data_map_t> bundle_opt_;
@@ -112,10 +114,14 @@ struct client::impl : public spl::enable_shared_from_this<client::impl>
112114
continue;
113115
}
114116

115-
::osc::OutboundPacketStream o(reinterpret_cast<char*>(buffer_.data()),
116-
static_cast<unsigned long>(buffer_.size()));
117+
// TODO: Should use server clock.
118+
time_++;
119+
120+
char buffer[8192];
117121

118-
o << ::osc::BeginBundle();
122+
::osc::OutboundPacketStream o(buffer_, 8192);
123+
124+
o << ::osc::BeginBundle(time_);
119125

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

128134
o << ::osc::EndMessage;
135+
136+
if (o.Size() >= 1024) {
137+
o << ::osc::EndBundle;
138+
139+
boost::system::error_code ec;
140+
for (const auto& endpoint : endpoints) {
141+
// TODO: async send
142+
socket_.send_to(boost::asio::buffer(o.Data(), o.Size()), endpoint, 0, ec);
143+
// TODO Handle error
144+
}
145+
146+
o.Clear();
147+
148+
o << ::osc::BeginBundle(time_);
149+
}
129150
}
130151

131152
o << ::osc::EndBundle;
132153

133154
boost::system::error_code ec;
134155
for (const auto& endpoint : endpoints) {
156+
// TODO: async send
135157
socket_.send_to(boost::asio::buffer(o.Data(), o.Size()), endpoint, 0, ec);
158+
// TODO Handle error
136159
}
137160
}
138161
} catch (...) {

0 commit comments

Comments
 (0)