Skip to content

refactor(messaging): consume tcp_socket std::span receive callback internally (remove one copy) #319

Description

@kcenon

Parent Issue

Part of #315 (TCP receive std::span callback migration)

Summary

Update messaging components that directly use internal::tcp_socket to consume the new std::span<const uint8_t> receive callback internally, removing one copy/allocation per read while keeping existing public APIs intact.

Background

Today the receive path for messaging over TCP typically looks like:

  1. tcp_socket::do_read() allocates + copies into std::vector<uint8_t>
  2. messaging_session / messaging_client then copies that vector again (e.g., enqueueing)

After #316, step (1) can become span-view based (no vector allocation).

Proposed Solution

1) messaging_session

  • Register tcp_socket with set_receive_callback_view(...)
  • Change internal messaging_session::on_receive(...) to accept std::span<const uint8_t>
  • When queueing/retaining data is required, copy from span into a single std::vector<uint8_t> once

Files:

  • src/session/messaging_session.cpp
  • include/kcenon/network/session/messaging_session.h

2) messaging_client

  • Register tcp_socket with set_receive_callback_view(...)
  • Change internal messaging_client::on_receive(...) to accept std::span<const uint8_t>
  • Keep existing external set_receive_callback(std::function<void(const std::vector<uint8_t>&)>) working by copying span into a vector only at the API boundary

Files:

  • src/core/messaging_client.cpp
  • include/kcenon/network/core/messaging_client.h

Acceptance Criteria

  • messaging_session uses tcp_socket span callback and performs at most one copy when it must retain data
  • messaging_client uses tcp_socket span callback and keeps public vector-based callback behavior unchanged
  • Removes one allocation/copy per read vs current baseline in the messaging path
  • Unit/integration tests pass

Test Plan

  • Run:
    • ctest --output-on-failure -R messaging
    • ctest --output-on-failure (full suite as time permits)

Metadata

Metadata

Assignees

Labels

asyncAsynchronous operationsenhancementNew feature or requestperformancePerformance improvementsrefactoringCode refactoring and improvements

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions