Skip to content

Commit

Permalink
API: copy the data to send into the tcp internal buffer (esphome#1455)
Browse files Browse the repository at this point in the history
Without the flag lwip only holds a reference to the supplied buffers and the reference must be valid until the tcp ack is received. This can't be guaranteed for stack allocated buffers
  • Loading branch information
mknjc authored Jan 11, 2021
1 parent 02dc49c commit 96ab6b5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions esphome/components/api/api_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,10 @@ bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint32_t message_type)
}
}

this->client_->add(reinterpret_cast<char *>(header.data()), header.size());
this->client_->add(reinterpret_cast<char *>(buffer.get_buffer()->data()), buffer.get_buffer()->size());
this->client_->add(reinterpret_cast<char *>(header.data()), header.size(),
ASYNC_WRITE_FLAG_COPY | ASYNC_WRITE_FLAG_MORE);
this->client_->add(reinterpret_cast<char *>(buffer.get_buffer()->data()), buffer.get_buffer()->size(),
ASYNC_WRITE_FLAG_COPY);
bool ret = this->client_->send();
return ret;
}
Expand Down

0 comments on commit 96ab6b5

Please sign in to comment.