diff --git a/mtproto-client.c b/mtproto-client.c index e65a05c..ff98063 100644 --- a/mtproto-client.c +++ b/mtproto-client.c @@ -1856,6 +1856,9 @@ void mtproto_close(struct mtproto_connection *mtp) { // remove all ping timer that point to this connection stop_ping_timer (mtp->connection); + + // + mtp->connection->session->c = 0; } /** diff --git a/net.c b/net.c index d935d1f..bbc54a2 100644 --- a/net.c +++ b/net.c @@ -619,6 +619,11 @@ void connections_poll_result (struct pollfd *fds, int max) { } int send_all_acks (struct session *S) { + logprintf ("send_all_acks()\n"); + if (!S->c) { + logprintf ("WARNING: cannot send acks, session has no active connection"); + return -1; + } struct mtproto_connection *mt = S->c->mtconnection; clear_packet (mt); diff --git a/queries.c b/queries.c index 06ee03a..8b42777 100644 --- a/queries.c +++ b/queries.c @@ -3075,6 +3075,9 @@ void do_update_typing (struct telegram *instance, peer_id_t id) { int telegram_has_output (struct telegram *instance) { + if (!instance->connection) { + return 0; + } if (instance->session_state == STATE_READY) { return tree_count_query (instance->queries_tree) > 0; } diff --git a/telegram.c b/telegram.c index 99492f5..49bffd1 100755 --- a/telegram.c +++ b/telegram.c @@ -160,6 +160,10 @@ void telegram_change_state (struct telegram *instance, int state, void *data) assert (instance->config->proxy_request_cb); // tell the proxy to close all connections instance->config->proxy_close_cb (instance, instance->connection->connection->fd); + + // remove all left over queries and timers + free_timers (instance); + free_queries (instance); // start a new connection to the demanded data center. The pointer to the // new dc should was already updated by the on_error function of the query