summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2021-02-13 16:36:35 +0300
committerdefanor <defanor@uberspace.net>2021-02-13 16:36:35 +0300
commit83787c83cc09ad6efdf62816b202820c4f9d3fc7 (patch)
tree8836f09ffdd92ad26b40f16d0d901c64201d5e53
parent4876fa155a02bbd32fc7ccaad212630c9df56043 (diff)
Don't try to reconnect on TCP errors while closing a stream
-rw-r--r--src/rexmpp.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/rexmpp.c b/src/rexmpp.c
index dde85f1..d8f1b19 100644
--- a/src/rexmpp.c
+++ b/src/rexmpp.c
@@ -631,6 +631,12 @@ void rexmpp_done (rexmpp_t *s) {
}
void rexmpp_schedule_reconnect (rexmpp_t *s) {
+ if (s->stream_state == REXMPP_STREAM_CLOSE_REQUESTED ||
+ s->stream_state == REXMPP_STREAM_CLOSING) {
+ /* Don't schedule a reconnect if a reconnect-causing condition
+ happened during closing. */
+ return;
+ }
if (s->reconnect_number == 0) {
gnutls_rnd(GNUTLS_RND_NONCE, &s->reconnect_seconds, sizeof(time_t));
if (s->reconnect_seconds < 0) {
@@ -2319,6 +2325,7 @@ rexmpp_err_t rexmpp_close (rexmpp_t *s) {
}
rexmpp_err_t rexmpp_stop (rexmpp_t *s) {
+ s->stream_state = REXMPP_STREAM_CLOSE_REQUESTED;
if (s->stream_state == REXMPP_STREAM_READY) {
xmlNodePtr presence = rexmpp_xml_add_id(s, xmlNewNode(NULL, "presence"));
xmlNewProp(presence, "type", "unavailable");
@@ -2330,7 +2337,6 @@ rexmpp_err_t rexmpp_stop (rexmpp_t *s) {
return ret;
}
}
- s->stream_state = REXMPP_STREAM_CLOSE_REQUESTED;
if (s->send_buffer == NULL) {
return rexmpp_close(s);
} else {
@@ -2398,6 +2404,13 @@ rexmpp_err_t rexmpp_run (rexmpp_t *s, fd_set *read_fds, fd_set *write_fds) {
}
}
+ /* Don't try to reconnect if a stream is requested to be closed. */
+ if (s->tcp_state == REXMPP_TCP_ERROR &&
+ (s->stream_state == REXMPP_STREAM_CLOSE_REQUESTED ||
+ s->stream_state == REXMPP_STREAM_CLOSING)) {
+ return REXMPP_E_TCP;
+ }
+
/* Resolving SRV records. This continues in rexmpp_srv_tls_cb,
rexmpp_srv_cb, and rexmpp_after_srv, possibly leading to
connection initiation. */