int rmt_tcp_context_reconnect(tcp_context *tc) { if (tc == NULL) { return RMT_ERROR; } rmt_tcp_context_close_sd(tc); return _rmt_tcp_context_connect(tc); }
int rmt_tcp_context_connect(tcp_context *tc, const char *host, int port, const struct timeval *timeout, const char *source_addr) { tc->port = port; if(tc->host != NULL) { free(tc->host); tc->host = NULL; } tc->host = rmt_strdup(host); if (timeout) { if (tc->timeout == NULL) { tc->timeout = rmt_alloc(sizeof(struct timeval)); } rmt_memcpy(tc->timeout, timeout, sizeof(struct timeval)); } else { if (tc->timeout) rmt_free(tc->timeout); tc->timeout = NULL; } if (tc->source_addr != NULL) { free(tc->source_addr); tc->source_addr = NULL; } if (source_addr) { tc->source_addr = rmt_strdup(source_addr); } if (!(tc->flags & RMT_RECONNECT)) { tc->flags |= RMT_RECONNECT; } return _rmt_tcp_context_connect(tc); }