Remove rest of mallocs from message_bridge_client
Use a pool for the client too. Docs for interleaving for SCTP type 1
say that there can be at most 1 partial message being delivered to
userspace at a time from all streams for an association, so 2 messages
in the queue is good enough.
Change-Id: I0b1bd579b92ac540a72b8849d7933a56ff611355
Signed-off-by: Austin Schuh <austin.schuh@bluerivertech.com>
diff --git a/aos/network/message_bridge_client_lib.cc b/aos/network/message_bridge_client_lib.cc
index 0c04244..d1c07eb 100644
--- a/aos/network/message_bridge_client_lib.cc
+++ b/aos/network/message_bridge_client_lib.cc
@@ -135,15 +135,22 @@
if (configuration::ChannelIsSendableOnNode(channel, remote_node_) &&
configuration::ChannelIsReadableOnNode(channel, event_loop_->node())) {
- LOG(INFO) << "Receiving channel "
- << configuration::CleanedChannelToString(channel);
+ VLOG(1) << "Receiving channel "
+ << configuration::CleanedChannelToString(channel);
max_size = std::max(channel->max_size(), max_size);
}
}
// Buffer up the max size a bit so everything fits nicely.
LOG(INFO) << "Max message size for all servers is " << max_size;
- client_.SetMaxSize(max_size + 100);
+ // RemoteMessage header appears to be between 100 and 204 bytes of overhead
+ // from the vector of data. No need to get super tight to that bound.
+ client_.SetMaxSize(max_size + 204);
+
+ // 1 client talks to 1 server. With interleaving support 1 turned on, we'll
+ // at most see 1 partial message, and 1 incoming part, for a total of 2
+ // messages in flight.
+ client_.SetPoolSize(2u);
event_loop_->epoll()->OnReadable(client_.fd(),
[this]() { MessageReceived(); });
@@ -193,6 +200,7 @@
} else if (message->message_type == Message::kMessage) {
HandleData(message.get());
}
+ client_.FreeMessage(std::move(message));
}
void SctpClientConnection::SendConnect() {
@@ -262,7 +270,7 @@
monotonic_clock::time_point(
chrono::nanoseconds(remote_data->monotonic_sent_time())) ==
channel_state->last_timestamp) {
- LOG(INFO) << "Duplicate message from " << message->PeerAddress();
+ VLOG(1) << "Duplicate message from " << message->PeerAddress();
connection_->mutate_duplicate_packets(connection_->duplicate_packets() + 1);
// Duplicate message, ignore.
} else {
diff --git a/aos/network/sctp_client.h b/aos/network/sctp_client.h
index 1ba32ff..1a0a907 100644
--- a/aos/network/sctp_client.h
+++ b/aos/network/sctp_client.h
@@ -48,11 +48,16 @@
void LogSctpStatus(sctp_assoc_t assoc_id);
void SetMaxSize(size_t max_size) { sctp_.SetMaxSize(max_size); }
+ void SetPoolSize(size_t pool_size) { sctp_.SetPoolSize(pool_size); }
void SetAssociationId(sctp_assoc_t sac_assoc_id) {
sac_assoc_id_ = sac_assoc_id;
}
+ void FreeMessage(aos::unique_c_ptr<Message> &&message) {
+ sctp_.FreeMessage(std::move(message));
+ }
+
private:
struct sockaddr_storage sockaddr_remote_;
struct sockaddr_storage sockaddr_local_;