Skip to content

tcp_socket missing bind() method #210

@sgerbino

Description

@sgerbino

Summary

tcp_socket does not expose a bind() method, while udp_socket and tcp_acceptor both do. The underlying infrastructure (reactor_basic_socket::do_bind()) supports it for all socket types — it's just not wired through the TCP path.

Current state

tcp_socket udp_socket tcp_acceptor
open() Yes Yes Yes
bind() No Yes Yes
  • udp_service has bind_datagram() virtual — tcp_service has no equivalent
  • reactor_basic_socket::do_bind() works for both TCP and UDP
  • Native variants (native_tcp_socket, native_udp_socket) inherit non-async ops from the type-erased base, so the gap propagates uniformly

Impact

A TCP client that needs to bind to a specific local address/port before connecting (multi-homed hosts, source-port pinning) cannot do so at any API level.

Proposed fix

  1. Add bind_socket() to tcp_service (virtual interface)
  2. Implement in all backends (delegate to do_bind())
  3. Expose bind(endpoint) on tcp_socket
  4. native_tcp_socket inherits it automatically

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions