diff --git a/mtproto-client.c b/mtproto-client.c index a0a9018..784fc40 100644 --- a/mtproto-client.c +++ b/mtproto-client.c @@ -1915,7 +1915,7 @@ void mtproto_close_foreign (struct telegram *instance) /** * Free all destroyed connections */ -void mtproto_free_closed (struct telegram *tg) { +void mtproto_free_closed (struct telegram *tg, int force) { int i; for (i = 0; i < 100; i++) { if (tg->Cs[i] == NULL) continue; @@ -1923,7 +1923,7 @@ void mtproto_free_closed (struct telegram *tg) { debug ("checking mtproto_connection %d: c_state:%d destroy:%d, quries_num:%d\n", i, c->c_state, c->destroy, c->queries_num); if (c->destroy == 0) continue; - if (c->connection->out_bytes > 0) { + if (!force && c->connection->out_bytes > 0) { debug ("still %d bytes ouput left, skipping connection...\n", c->connection->out_bytes); continue; } diff --git a/mtproto-client.h b/mtproto-client.h index fe6dcc1..073e353 100644 --- a/mtproto-client.h +++ b/mtproto-client.h @@ -508,7 +508,7 @@ static inline void hexdump_out (struct mtproto_connection *self) { void my_clock_gettime (int clock_id, struct timespec *T); void mtproto_close_foreign (struct telegram *instance); -void mtproto_free_closed (struct telegram *tg); +void mtproto_free_closed (struct telegram *tg, int force); #endif diff --git a/purple-plugin/telegram-purple.c b/purple-plugin/telegram-purple.c index f51be8a..30a5ddf 100644 --- a/purple-plugin/telegram-purple.c +++ b/purple-plugin/telegram-purple.c @@ -213,21 +213,7 @@ static void tgprpl_input_cb(gpointer data, gint source, PurpleInputCondition con telegram_flush (conn->mtp->instance); // free all mtproto_connections that may have errored - mtproto_free_closed(conn->mtp->instance); - } -} - -/** - * Telegram announced that it awaits new input from the read-handle - * TODO: this is currently unused, evaluate wether its needed at all - */ -static void tgprpl_has_input(void *handle) -{ - debug("tgprpl_has_input()\n"); - mtproto_handle *conn = handle; - if (! conn->rh) { - conn->rh = purple_input_add(conn->fd, PURPLE_INPUT_READ, tgprpl_input_cb, handle); - debug("Attached read handle: %u ", conn->rh); + mtproto_free_closed(conn->mtp->instance, 0); } } diff --git a/telegram.c b/telegram.c index 771840a..6999e9a 100755 --- a/telegram.c +++ b/telegram.c @@ -193,7 +193,7 @@ void telegram_destroy(struct telegram *this) } free_queries (this); free_timers (this); - mtproto_free_closed (this); + mtproto_free_closed (this, 1); free_bl (this->bl); free_auth (this->auth.DC_list, 11);