Method: Mosquitto::Client#on_disconnect

Defined in:
ext/mosquitto/client.c

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

Set the disconnect callback. This is called when the broker has received the DISCONNECT command and has disconnected the client.

Examples:

client.on_disconnect{|rc| p :disconnected }

Yields:

  • (rc)

Returns:

  • (Boolean)

Yields:

  • disconnect callback

Yield Parameters:

  • rc (Integer)

    integer value indicating the reason for the disconnect. A value of 0 means the client has called Mosquitto::Client#disconnect. Any other value indicates that the disconnect is unexpected.

Returns:

  • (true)

    on success

Raises:

  • (TypeError, ArgumentError)

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



2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
# File 'ext/mosquitto/client.c', line 2006

static VALUE rb_mosquitto_client_on_disconnect(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->disconnect_cb)) rb_gc_unregister_address(&client->disconnect_cb);
    mosquitto_disconnect_callback_set(client->mosq, rb_mosquitto_client_on_disconnect_cb);
    client->disconnect_cb = cb;
    rb_gc_register_address(&client->disconnect_cb);
    return Qtrue;
}