Skip to content

Commit

Permalink
feat: session->chunk use heap memory to avoid stack overflow (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
kibae authored Sep 17, 2023
1 parent a726dcd commit ac1f7a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/transport/tcp/tcp_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace onnxruntime_server::transport::tcp {
private:
asio::socket socket;
tcp_server *server;
char chunk[MAX_RECV_BUF_LENGTH];
std::string chunk;
std::string buffer;

onnxruntime_server::task::benchmark request_time;
Expand Down
6 changes: 4 additions & 2 deletions src/transport/tcp/tcp_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ void Orts::transport::tcp::tcp_session::do_read() {
_remote_endpoint =
socket.remote_endpoint().address().to_string() + ":" + std::to_string(socket.remote_endpoint().port());

// use heap memory to avoid stack overflow
chunk.resize(MAX_RECV_BUF_LENGTH);
socket.async_read_some(
boost::asio::buffer(chunk, MAX_RECV_BUF_LENGTH),
boost::asio::buffer(chunk.data(), MAX_RECV_BUF_LENGTH),
[self = shared_from_this()](boost::system::error_code ec, std::size_t length) {
if (!ec) {
self->buffer.append(self->chunk, length);
self->buffer.append(self->chunk.data(), length);

// check protocol header
if (self->buffer.size() < sizeof(protocol_header)) {
Expand Down

0 comments on commit ac1f7a0

Please sign in to comment.