static int _mosquitto_connect_init(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address) { if(!mosq) return MOSQ_ERR_INVAL; if(!host || port <= 0) return MOSQ_ERR_INVAL; if(mosq->host) _mosquitto_free(mosq->host); mosq->host = _mosquitto_strdup(host); if(!mosq->host) return MOSQ_ERR_NOMEM; mosq->port = port; if(mosq->bind_address) _mosquitto_free(mosq->bind_address); if(bind_address){ mosq->bind_address = _mosquitto_strdup(bind_address); if(!mosq->bind_address) return MOSQ_ERR_NOMEM; } mosq->keepalive = keepalive; if(mosq->sockpairR != INVALID_SOCKET){ COMPAT_CLOSE(mosq->sockpairR); mosq->sockpairR = INVALID_SOCKET; } if(mosq->sockpairW != INVALID_SOCKET){ COMPAT_CLOSE(mosq->sockpairW); mosq->sockpairW = INVALID_SOCKET; } if(_mosquitto_socketpair(&mosq->sockpairR, &mosq->sockpairW)){ _mosquitto_log_printf(mosq, MOSQ_LOG_WARNING, "Warning: Unable to open socket pair, outgoing publish commands may be delayed."); } return MOSQ_ERR_SUCCESS; }
static int _mosquitto_connect_init(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address) { if(!mosq) return MOSQ_ERR_INVAL; if(!host || port <= 0) return MOSQ_ERR_INVAL; if(mosq->host) _mosquitto_free(mosq->host); mosq->host = _mosquitto_strdup(host); if(!mosq->host) return MOSQ_ERR_NOMEM; mosq->port = port; if(mosq->bind_address) _mosquitto_free(mosq->bind_address); if(bind_address){ mosq->bind_address = _mosquitto_strdup(bind_address); if(!mosq->bind_address) return MOSQ_ERR_NOMEM; } mosq->keepalive = keepalive; _mosquitto_socketpair(&mosq->sockpairR, &mosq->sockpairW); return MOSQ_ERR_SUCCESS; }