Example #1
0
int client_connect(struct mosquitto *mosq, struct mosq_config *cfg)
{
    char err[1024];
    int rc;

#ifdef WITH_SRV
    if(cfg->use_srv) {
        rc = mosquitto_connect_srv(mosq, cfg->host, cfg->keepalive, cfg->bind_address);
    } else {
        rc = mosquitto_connect_bind(mosq, cfg->host, cfg->port, cfg->keepalive, cfg->bind_address);
    }
#else
    rc = mosquitto_connect_bind(mosq, cfg->host, cfg->port, cfg->keepalive, cfg->bind_address);
#endif
    if(rc>0) {
        if(!cfg->quiet) {
            if(rc == MOSQ_ERR_ERRNO) {
#ifndef WIN32
                strerror_r(errno, err, 1024);
#else
                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, errno, 0, (LPTSTR)&err, 1024, NULL);
#endif
                fprintf(stderr, "Error: %s\n", err);
            } else {
                fprintf(stderr, "Unable to connect (%d).\n", rc);
            }
        }
        mosquitto_lib_cleanup();
        return rc;
    }
    return MOSQ_ERR_SUCCESS;
}
Example #2
0
/* {{{ Mosquitto\Client::connect() */
PHP_METHOD(Mosquitto_Client, connect)
{
	mosquitto_client_object *object;
	char *host = NULL, *interface = NULL;
	int host_len, interface_len, retval;
	long port = 1883;
	long keepalive = 0;

	PHP_MOSQUITTO_ERROR_HANDLING();
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lls!",
				&host, &host_len, &port, &keepalive,
				&interface, &interface_len)  == FAILURE) {

		PHP_MOSQUITTO_RESTORE_ERRORS();
		return;
	}
	PHP_MOSQUITTO_RESTORE_ERRORS();

	object = (mosquitto_client_object *) mosquitto_client_object_get(getThis() TSRMLS_CC);

	if (interface == NULL) {
		retval = mosquitto_connect(object->client, host, port, keepalive);
	} else {
		retval = mosquitto_connect_bind(object->client, host, port, keepalive, interface);
	}

	php_mosquitto_handle_errno(retval, errno TSRMLS_CC);
	RETURN_LONG(retval);
}
Example #3
0
int mosquitto_connect(struct mosquitto *mosq, const char *host, int port, int keepalive)
{
	return mosquitto_connect_bind(mosq, host, port, keepalive, NULL);
}
Example #4
0
int mosquittopp::connect(const char *host, int port, int keepalive, const char *bind_address)
{
	return mosquitto_connect_bind(m_mosq, host, port, keepalive, bind_address);
}