summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2021-03-02 22:45:32 +0300
committerdefanor <defanor@uberspace.net>2021-03-02 22:45:32 +0300
commit9185f8eaa387893a4c8ef18963d2ec54b76af61d (patch)
tree732baa43569e77b27932924ff7c80d3abfeaa4a3
parentb1fc173966158567575758ece5dc4e4b1cbf946b (diff)
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.
-rw-r--r--src/rexmpp.c31
1 files 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) {