Skip to content

Runtime Lifecycle

v2rayroot edited this page Jun 14, 2026 · 1 revision

Runtime Lifecycle

State Model

STOPPED -> STARTING -> RUNNING -> STOPPING -> STOPPED

GetStatus

char *GetStatus(void);

Returns an allocated state string. Release it with FreeCString.

Start

char *Start(char *configInput, char *optionsJSON);

configInput accepts:

  • Complete Xray JSON
  • Path to an Xray JSON file
  • vless://, vmess://, trojan://, or ss:// URI

Basic options:

{
  "geositeFile": "/absolute/path/geosite.dat",
  "geositePath": "/absolute/path/geosite.dat"
}

Return value:

  • Null: startup accepted
  • Non-null: allocated error text

Startup is asynchronous. Applications may poll status and verify their local proxy port before presenting a connected state.

Stop

char *Stop(void);

Returns null after a successful stop. When no instance is active, it returns the allocated string server not running.

Recommended Sequence

  1. Load library.
  2. Read version metadata.
  3. Configure logging.
  4. Validate configuration.
  5. Start runtime.
  6. Poll status and statistics.
  7. Stop runtime.
  8. Release all native strings.
  9. Unload library.

Serialize lifecycle calls in the application even though internal state is mutex protected.

Clone this wiki locally