Class
ControlSocket
Cross-platform, Sendable line-oriented wrapper around a Tor control socket file descriptor.
final class ControlSocket
Mentioned In
Overview
ControlSocket is the POSIX-level plumbing that sits under TorControlClient. It provides the three operations the control protocol demands (control-spec.txt §2): write a CRLF-terminated command line, read back a CRLF-terminated reply line, and assemble multi-line (250-, 250+, 650+) replies into a single [String]. The underlying FD is either the pre-authenticated socket from tor_main_configuration_setup_control_socket() (embedded mode) or a freshly-opened TCP connection to a listening ControlPort.
Platform plumbing is abstracted across Darwin (Darwin), Linux (Glibc, Musl), and Windows (WinSDK) via #if canImport(…) guards. Sockets are configured with SO_RCVTIMEO so blocking recv calls honour readTimeout without requiring a polling loop.
Note
Conformance is Sendable (compiler-verified, no @unchecked). All mutable state lives inside a Mutex<State> from the Synchronization module (SE-0410); callers may share instances across concurrency domains and call methods concurrently — each operation acquires the mutex for its own critical section.
Important
The deinit calls close(2) (or closesocket() on Windows) only when init(fileDescriptor:ownsDescriptor:) was invoked with ownsDescriptor: true. Embedded control sockets from tor_api are owned by Tor; swift-tor must not close them.
Topics
Creating
I/O
State