Method: Mosquitto::Client#on_connect

Defined in:
ext/mosquitto/client.c

#on_connect {|rc| ... } ⇒ Boolean

Set the connect callback. This is called when the broker sends a CONNACK message in response to a connection.

Examples:

client.on_connect{|rc| p :connected }

Yields:

  • (rc)

Returns:

  • (Boolean)

Yields:

  • connect callback

Yield Parameters:

  • rc (Integer)

    the return code of the connection response, one of: 0 - success, 1 - connection refused (unacceptable protocol version), 2 - connection refused (identifier rejected) 3 - connection refused (broker unavailable)

Returns:

  • (true)

    on success

Raises:

  • (TypeError, ArgumentError)

    if callback is not a Proc or if the method arity is wrong



1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
# File 'ext/mosquitto/client.c', line 1976

static VALUE rb_mosquitto_client_on_connect(int argc, VALUE *argv, VALUE obj)
{
    VALUE proc, cb;
    MosquittoGetClient(obj);
    rb_scan_args(argc, argv, "01&", &proc, &cb);
    MosquittoAssertCallback(cb, 1);
    if (!NIL_P(client->connect_cb)) rb_gc_unregister_address(&client->connect_cb);
    mosquitto_connect_callback_set(client->mosq, rb_mosquitto_client_on_connect_cb);
    client->connect_cb = cb;
    rb_gc_register_address(&client->connect_cb);
    return Qtrue;
}