4.4 KiB
S02: TCP server support
Goal: Enable TCP transport end-to-end: wx daemon start --tcp 127.0.0.1:9876 starts daemon listening on TCP, and all query commands support --tcp 127.0.0.1:9876 to connect via TCP instead of local transport. TCP bind/connect failures produce clear errors with no silent fallback (15s connect timeout, 120s read/write timeout).
Demo: wx daemon start --tcp 127.0.0.1:9876 starts daemon listening on TCP port 9876
Must-Haves
-
wx daemon start --tcp 127.0.0.1:9876starts daemon and logs TCP listening message. 2. All query commands (sessions,history,search,contacts, etc.) accept--tcp host:portflag. 3. When --tcp is specified, requests route through TCP to the daemon, not local transport. 4. TCP bind failure gives clear error (e.g. port in use). 5. TCP connect failure gives clear error (no silent fallback). 6.cargo checkpasses on all platforms.
Integration Closure
TCP server already wired in S01 (server.rs serve_tcp). This slice wires TCP into the client transport path (cli/transport.rs send/send_unix/send_windows) and the CLI struct. S03 will add client-side TCP in a future slice.
Verification
- daemon logs show TCP bind address; is_alive() and status report TCP connectivity; TCP error messages include address and errno
Tasks
-
T01: Add global --tcp CLI flag and wire into transport module
est:2hAdd--tcpflag as a global argument on the rootClistruct insrc/cli/mod.rs, not on individual subcommands. The flag takesOption<String>(e.g.,Some("127.0.0.1:9876")). Wire this through thedispatch()function so every command path receives the TCP address. Modify allcmd_*functions insrc/cli/to accept an optionaltcp_addr: Option<&str>parameter. Updatesrc/cli/transport.rs:- Add
send_tcp(req: Request, addr: &str) -> Result<Response>function usingstd::net::TcpStreamwith 15s connect timeout and 120s read/write timeout - Add
is_alive_tcp(addr: &str) -> boolfor TCP liveness check - Update
send()to accepttcp_addr: Option<&str>, routing tosend_tcpwhen present - Update
is_alive()to accepttcp_addr: Option<&str>, routing tois_alive_tcpwhen present - Update
ensure_daemon()— when --tcp is specified, do NOT auto-start daemon (user explicitly chose TCP); if connection fails, hard error with clear message
- Files:
src/cli/mod.rs,src/cli/transport.rs,src/cli/sessions.rs,src/cli/history.rs,src/cli/search.rs,src/cli/contacts.rs,src/cli/export.rs,src/cli/unread.rs,src/cli/members.rs,src/cli/new_messages.rs,src/cli/stats.rs,src/cli/favorites.rs,src/cli/sns_notifications.rs,src/cli/sns_feed.rs,src/cli/sns_search.rs,src/cli/daemon_cmd.rs - Verify: cargo check 2>&1 | tail -5; grep -c 'tcp: Option' src/cli/mod.rs; grep -q 'send_tcp' src/cli/transport.rs; grep -q 'is_alive_tcp' src/cli/transport.rs
- Add
-
T02: Wire --tcp into daemon status/stop/logs commands and verify end-to-end
est:1hUpdatesrc/cli/daemon_cmd.rsto:DaemonCommands::Status— when --tcp addr is set, check TCP liveness viais_alive_tcp; report "listening on TCP {addr}" vs "listening on local socket"DaemonCommands::Stop— when --tcp is set, warn that TCP daemon must be stopped manually (it's a separate process)DaemonCommands::Logs— unchanged, logs go to same file- Update the
cmd_daemonfunction signature to accept tcp_addr
- Files:
src/cli/daemon_cmd.rs,src/cli/transport.rs - Verify: cargo check 2>&1 | tail -5 && cargo test transport -- --nocapture 2>&1 | tail -10
-
T03: Cross-platform compilation verification
est:30mVerify that all changes compile on all target platforms:cargo check(native/macOS)cargo check --target x86_64-pc-windows-msvc(Windows cross-compile)cargo testto ensure unit tests pass
- Files:
src/cli/mod.rs,src/cli/transport.rs,src/cli/daemon_cmd.rs - Verify: cargo check 2>&1 | tail -5 && cargo check --target x86_64-pc-windows-msvc 2>&1 | tail -5 && cargo test 2>&1 | tail -10
Files Likely Touched
- src/cli/mod.rs
- src/cli/transport.rs
- src/cli/sessions.rs
- src/cli/history.rs
- src/cli/search.rs
- src/cli/contacts.rs
- src/cli/export.rs
- src/cli/unread.rs
- src/cli/members.rs
- src/cli/new_messages.rs
- src/cli/stats.rs
- src/cli/favorites.rs
- src/cli/sns_notifications.rs
- src/cli/sns_feed.rs
- src/cli/sns_search.rs
- src/cli/daemon_cmd.rs