ubus. channel

Represents a channel connection to the ubus bus.

Channels provide bidirectional communication between two ubus objects through file descriptors. They are created via open_channel() or from an incoming request via new_channel().

Channels are useful for:

  • Establishing dedicated communication paths between specific objects
  • Streaming data or multiple requests over a single connection
  • File descriptor passing between processes
Example
const chan = open_channel(…);

chan.request(…);
chan.defer(…);
chan.disconnect();

chan.error();

Methods

defer(method, dataopt, cbopt, data_cbopt, fdopt, fd_cbopt) → {deferred}nullable

Send an asynchronous request on a channel connection.

Similar to defer() but uses object ID 0 for channel-based communication.

Returns a deferred request resource representing the pending operation.

Returns null if the deferred call could not be initiated.

Parameters:
NameTypeDescription
methodstring

The name of the method to invoke.

dataObject(optional)

Optional method arguments as an object with field names and values.

cbfunction(optional)

Callback function invoked when the operation completes.

data_cbfunction(optional)

Optional callback invoked for intermediate data notifications.

fdnumber(optional)

Optional file descriptor to send along with the request.

fd_cbfunction(optional)

Optional callback function invoked when a file descriptor is received.

Returns: deferred
Example
const chan = open_channel(…);
const req = chan.defer("method_name", { arg: "value" },
    (status, data) => {
        printf("Status: %d\n", status);
    });

error(numericopt) → {string|number}

Query ubus error information.

Returns a string containing a description of the last ubus error when the numeric argument is absent or false.

Returns a ubus status code number when the numeric argument is true.

Returns null if there is no error information.

Parameters:
NameTypeDescription
numericboolean(optional)

Whether to return a numeric status code (true) or a human readable error message (false).

Returns: string | number

request(method, dataopt, returnopt, fdopt, fd_cbopt) → {*}nullable

Send a request on a channel connection.

Similar to call() but uses object ID 0 for channel-based communication.

Returns the method response data.

Returns null if the request failed.

Parameters:
NameTypeDescription
methodstring

The name of the method to invoke.

dataObject(optional)

Optional method arguments as an object with field names and values.

returnstring | boolean(optional, default: "single")

Controls how multiple responses are handled.

fdnumber(optional)

Optional file descriptor to send along with the request.

fd_cbfunction(optional)

Optional callback function invoked when a file descriptor is received.

Returns: *
Example
const chan = open_channel(…);
const result = chan.request("method_name", { arg: "value" });