From 9185f8eaa387893a4c8ef18963d2ec54b76af61d Mon Sep 17 00:00:00 2001 From: defanor Date: Tue, 2 Mar 2021 22:45:32 +0300 Subject: Initiate connection from the rexmpp_run function It used to be handled in a callback, but now the callback is simplified, only storing the received data. This should make the control flow a bit easier to follow. --- src/rexmpp.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/rexmpp.c b/src/rexmpp.c index d8f1b19..8cc68a1 100644 --- a/src/rexmpp.c +++ b/src/rexmpp.c @@ -1452,20 +1452,6 @@ void rexmpp_srv_cb (void *s_ptr, } else if (s->resolver_state == REXMPP_RESOLVER_SRV_2) { s->resolver_state = REXMPP_RESOLVER_READY; } - if (s->resolver_state != REXMPP_RESOLVER_READY) { - return; - } - - /* todo: sort the records */ - - if (s->server_srv == NULL && s->server_srv_tls == NULL) { - /* Failed to resolve anything: a fallback. */ - s->server_host = s->initial_jid.domain; - s->server_port = 5222; - rexmpp_start_connecting(s); - } else { - rexmpp_try_next_host(s); - } } /* Should be called after reconnect, and after rexmpp_sm_handle_ack in @@ -2412,8 +2398,7 @@ rexmpp_err_t rexmpp_run (rexmpp_t *s, fd_set *read_fds, fd_set *write_fds) { } /* Resolving SRV records. This continues in rexmpp_srv_tls_cb, - rexmpp_srv_cb, and rexmpp_after_srv, possibly leading to - connection initiation. */ + rexmpp_srv_cb. */ if (s->resolver_state != REXMPP_RESOLVER_NONE && s->resolver_state != REXMPP_RESOLVER_READY) { if (ub_poll(s->resolver_ctx)) { @@ -2426,6 +2411,20 @@ rexmpp_err_t rexmpp_run (rexmpp_t *s, fd_set *read_fds, fd_set *write_fds) { } } + /* Initiating a connection after SRV resolution. */ + if (s->resolver_state == REXMPP_RESOLVER_READY) { + s->resolver_state = REXMPP_RESOLVER_NONE; + /* todo: sort the records */ + if (s->server_srv == NULL && s->server_srv_tls == NULL) { + /* Failed to resolve anything: a fallback. */ + s->server_host = s->initial_jid.domain; + s->server_port = 5222; + rexmpp_start_connecting(s); + } else { + rexmpp_try_next_host(s); + } + } + /* Connecting. Continues in rexmpp_process_conn_err, possibly leading to stream opening. */ if (s->tcp_state == REXMPP_TCP_CONNECTING) { -- cgit v1.2.3