diff --git a/mtproto-client.c b/mtproto-client.c index 675cb5b..827a50c 100644 --- a/mtproto-client.c +++ b/mtproto-client.c @@ -66,7 +66,6 @@ #include "mtproto-common.h" -#include "tg-cli.h" #define MAX_NET_RES (1L << 16) extern int log_level; diff --git a/purple-plugin/telegram-purple.c b/purple-plugin/telegram-purple.c index f4f9ac3..8a7fd98 100644 --- a/purple-plugin/telegram-purple.c +++ b/purple-plugin/telegram-purple.c @@ -307,7 +307,7 @@ static int tgprpl_send_im(PurpleConnection * gc, const char *who, const char *me PurpleBuddy *b = purple_find_buddy(_pa, who); peer_id_t *peer = purple_buddy_get_protocol_data(b); do_send_message(*peer, message, strlen(message)); - // TODO: error handling + flush_queries(); return 1; } diff --git a/queries.c b/queries.c index 5a4129b..7d561e2 100644 --- a/queries.c +++ b/queries.c @@ -53,7 +53,6 @@ #include "no-preview.h" #include "binlog.h" -#include "tg-cli.h" #define sha1 SHA1 @@ -75,7 +74,22 @@ long long cur_downloaded_bytes; extern int binlog_enabled; extern int sync_from_start; -int queries_num; +int queries_num = 0; + +int all_queries_done() +{ + if (queries_num > 0) { + logprintf("all_queries_done() == false\n"); + return 0; + } else { + logprintf("all_queries_done() == true\n"); + return 1; + } +} + +void flush_queries () { + net_loop(0, all_queries_done); +} void out_peer_id (peer_id_t id); #define QUERY_TIMEOUT 6.0 @@ -162,6 +176,7 @@ struct query *send_query (struct dc *DC, int ints, void *data, struct query_meth q->extra = extra; queries_num ++; + logprintf("queries_num: %d\n", queries_num); return q; } @@ -201,6 +216,7 @@ void query_error (long long id) { tfree (q, sizeof (*q)); } queries_num --; + logprintf("queries_num: %d\n", queries_num); } #define MAX_PACKED_SIZE (1 << 24) @@ -255,6 +271,7 @@ void query_result (long long id UU) { in_end = eend; } queries_num --; + logprintf("queries_num: %d\n", queries_num); } #define event_timer_cmp(a,b) ((a)->timeout > (b)->timeout ? 1 : ((a)->timeout < (b)->timeout ? -1 : (memcmp (a, b, sizeof (struct event_timer))))) @@ -2907,3 +2924,4 @@ void do_update_status (int online UU) { out_int (online ? CODE_bool_false : CODE_bool_true); send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &update_status_methods, 0); } + diff --git a/telegram.h b/telegram.h index 69882c4..a63ac99 100644 --- a/telegram.h +++ b/telegram.h @@ -73,6 +73,11 @@ void parse_config (); void store_config (); void read_auth_file (); +/** + * Read and write until all queries received a response or errored + */ +void flush_queries (); + /** * Connect to the telegram network with the given configuration */ @@ -184,6 +189,6 @@ extern void *proxy_connection_data; void set_proxy_connection_source (void (*connection_source)(const char *host, int port, void (*on_connection_created)(int fd)), void* data); /** - * ? + * */ void set_default_username ();