How tanvir-ahmed-m4/hub4com works
Purpose and runtime
hub4com is a native Windows communications hub in the com0com ecosystem. It opens serial or TCP endpoints, routes data/control signals among them, and can transform streams through dynamically loaded filter plugins. The main executable is built from hub4com.cpp, with Visual C++ project metadata in hub4com.vcproj and solution hub4com.sln.
Process startup and configuration
hub4com.cpp is the command-line entry point. It parses ordered options and endpoint declarations, including inline/load-file configurations, then builds the hub topology. Configuration is operationally significant: route declarations, selected port driver, queue/reconnect behavior, and filter attachment determine runtime behavior. Core command/status messaging is centralized in hubmsg.cpp and hubmsg.h.
Hub orchestration
comhub.cpp / comhub.h implement the central coordinator over all opened ports. It owns lifecycle sequencing and distributes port events into routing/filter processing. timer.cpp / timer.h support timed behavior such as reconnect intervals, making connection management part of the hub control plane rather than a transport-specific concern.
Ports and endpoint-driver boundary
The abstract port contract is defined by port.cpp / port.h. Concrete endpoint implementations are supplied as plugins, separating the core hub from Windows serial and socket transport details:
• Serial transport: plugins/serial/port.cpp, plugins/serial/comport.cpp, plugins/serial/comio.cpp
• TCP transport: plugins/tcp/port.cpp, plugins/tcp/comport.cpp, plugins/tcp/comio.cpp
• Connector transport: plugins/connector/port.cpp, plugins/connector/comport.cpp
TCP endpoints support client/server-style address forms; serial endpoints integrate physical and com0com virtual COM ports. External infrastructure is Windows serial I/O, TCP/IP networking, and optionally the com0com virtual-null-modem driver.
Routing and backpressure
route.cpp / route.h define directed relationships between port indices. The hub can fan input out to multiple destinations, implement bidirectional routes, and propagate relevant control/flow signals. Per-port write queues and connection state form the key boundary between routing intent and endpoint availability; reconnect and queue-limit settings prevent a failed TCP peer from necessarily blocking unrelated routes.
Filter pipeline and plugin ABI
filter.h, filters.cpp, and filters.h provide the core filter-chain mechanism. Plugins are discovered/loaded through plugins.cpp / plugins.h, against the shared interface in plugins/plugins_api.h and export definitions in plugins/plugins.def. Filters can be attached by port/route configuration and transform bytes or communications signals before forwarding.
Architecturally important supplied filters include Telnet/RFC 2217 handling (plugins/telnet/telnet.cpp, plugins/telnet/opt_comport.cpp), encryption-oriented transformation (plugins/crypt/filter.cpp), multiplexing/tagging (plugins/tag/filter.cpp), tracing (plugins/trace/filter.cpp), and pin/control-line mapping (plugins/pinmap/filter.cpp, plugins/pin2con/filter.cpp).
Deployment compositions
The executable is intentionally topology-driven rather than application-server-driven. Batch wrappers compose reusable configurations for common deployments: COM-to-TCP/Telnet in examples/com2tcp.bat, RFC 2217 in examples/com2tcp-rfc2217.bat, and encrypted or serial-link multiplexing in examples/multiplexer.bat. A static-build variant exists in static/hub4com-static.vcproj.
Main entry points: plugins.cpp Plugin loader · filter.h Filter chain · port.h Abstract port contract · comhub.cpp Hub coordinator
Components 20
Startup & Control
- CLI topology builder · Parses ordered options, endpoint declarations, and loaded configurations.
hub4com.cpp - Command/status messaging
hubmsg.cpp
Hub Data Plane
- Hub coordinator · Owns opened ports, lifecycle sequencing, and port-event dispatch.
comhub.cpp - Reconnect timers
timer.cpp - Directed routes · Supports fan-out, bidirectional forwarding, and control-signal propagation.
route.cpp - Abstract port contract
port.h - Write queues & state · Queues and connection state isolate routes from unavailable peers.
port.cpp - Filter chain · Transforms bytes and communications signals before forwarding.
filter.h
Plugin Ecosystem
- Plugin loader · Discovers and loads endpoint and filter plugins.
plugins.cpp - Plugin ABI
plugins/plugins_api.h - Telnet / RFC 2217
plugins/telnet/telnet.cpp - Crypt, tag & trace filters · Supplied encryption, multiplexing/tagging, and tracing transforms.
plugins/crypt/filter.cpp - Pin mapping filters
plugins/pinmap/filter.cpp
Endpoint Drivers
- Serial endpoint plugin · Connects physical and com0com virtual COM ports.
plugins/serial/port.cpp - TCP endpoint plugin · Provides client/server-style TCP address endpoints.
plugins/tcp/port.cpp - Connector endpoint plugin
plugins/connector/port.cpp - Windows serial I/O
- TCP/IP networking
Deployment
- Topology batch wrappers · Reusable COM-to-TCP, RFC 2217, encryption, and multiplexing configurations.
examples/com2tcp.bat - Static build variant
static/hub4com-static.vcproj
Connections 26
- CLI topology builder → Hub coordinator: builds topology
- CLI topology builder → Command/status messaging: reports through
- Hub coordinator → Reconnect timers: schedules reconnects
- Hub coordinator → Directed routes: dispatches events to
- Directed routes → Write queues & state: forwards to
- Write queues & state → Abstract port contract: writes via
- Directed routes → Filter chain: applies attached filters
- Filter chain → Write queues & state: emits transformed traffic
- Hub coordinator → Abstract port contract: manages ports
- Plugin loader → Plugin ABI: loads against
- Plugin loader → Serial endpoint plugin: loads
- Plugin loader → TCP endpoint plugin: loads
- Plugin loader → Connector endpoint plugin: loads
- Plugin loader → Telnet / RFC 2217: loads
- Plugin loader → Crypt, tag & trace filters: loads
- Plugin loader → Pin mapping filters: loads
- Serial endpoint plugin → Abstract port contract: implements
- TCP endpoint plugin → Abstract port contract: implements
- Connector endpoint plugin → Abstract port contract: implements
- Telnet / RFC 2217 → Filter chain: extends
- Crypt, tag & trace filters → Filter chain: extends
- Pin mapping filters → Filter chain: extends
- Serial endpoint plugin → Windows serial I/O: uses
- TCP endpoint plugin → TCP/IP networking: uses
- Topology batch wrappers → CLI topology builder: invokes
- Static build variant → CLI topology builder: builds