class Rpc
Swift
final class Rpc
NPRPC runtime singleton
This is the main entry point for NPRPC applications. It manages:
- Network transport listeners (TCP, WebSocket, HTTP, QUIC)
- Connection to nameserver
- io_context for async operations
- POA management
Usage:
let config = RpcConfiguration(
nameserverHost: "127.0.0.1",
nameserverPort: 15000,
listenTcpPort: 8080
)
let rpc = try Rpc.initialize(config)
// Create POAs, activate servants...
// Run event loop (blocks until stopped)
try rpc.run()
nprpc_swift/Sources/NPRPC/Rpc.swift:109
Properties
var isInitialized: Bool { get }
Check if runtime is initialized
nprpc_swift/Sources/NPRPC/Rpc.swift:225
Methods
func addToHostJson(name: String, objectId: detail.ObjectId) throws
Register an activated object under a stable name for browser bootstrap.
nprpc_swift/Sources/NPRPC/Rpc.swift:230
func clearHostJson()
Clear the pending host.json object registry.
nprpc_swift/Sources/NPRPC/Rpc.swift:260
func createPoa(maxObjects: UInt32 = 0, lifetime: PoaLifetime = .Persistent, idPolicy: ObjectIdPolicy = .systemGenerated, dispatch: PoaDispatchExecutor = .inlineOnTransportThread) throws -> Poa
Create a new POA with specified configuration
- Throws: RuntimeError if creation fails
maxObjects- Maximum number of objects (0 = unlimited)
lifetime- Lifetime policy
idPolicy- Object ID assignment policy
dispatch- Thread/queue where servant
dispatchruns
Returns New POA instance
nprpc_swift/Sources/NPRPC/Poa.swift:454
func debugInfo() -> String
Get debug information
nprpc_swift/Sources/NPRPC/Rpc.swift:281
static func initialize(_ config: RpcConfiguration) throws -> Rpc
Initialize the NPRPC runtime with configuration
- Throws: RuntimeError if initialization fails
config- Runtime configuration
Returns Initialized Rpc instance
nprpc_swift/Sources/NPRPC/Rpc.swift:134
@discardableResult func produceHostJson(outputPath: String? = nil) throws -> String
Produce host.json and return the file path written by the runtime.
nprpc_swift/Sources/NPRPC/Rpc.swift:267
@discardableResult func reloadCertificates() -> Bool
Re-read the configured TLS certificate and key files.
Applies to every listener that terminates TLS with them: HTTP/1.1 + WebSocket, HTTP/3, and the QUIC RPC listener. Connections already established keep the certificate they handshook with; new handshakes use the reloaded one.
A subsystem whose files fail to parse keeps its previous certificate rather than dropping to none, so a half-written renewal cannot take TLS down.
Safe to call from any thread while the server is running — typically
from a DispatchSource signal handler on SIGHUP, driven by a certbot
deploy hook.
Returns true if every configured subsystem reloaded successfully.
nprpc_swift/Sources/NPRPC/Rpc.swift:212
func run() throws
Run the io_context event loop (blocks until stopped)
- Throws: RuntimeError if not initialized or if run fails
nprpc_swift/Sources/NPRPC/Rpc.swift:158
func startThreadPool(_ threadCount: Int) throws
Start the thread pool for handling async operations (non-blocking)
- Throws: RuntimeError if not initialized or already running
threadCount- Number of threads to start (must be > 0)
nprpc_swift/Sources/NPRPC/Rpc.swift:178
func stop()
Stop the io_context event loop
nprpc_swift/Sources/NPRPC/Rpc.swift:218