diff --git a/mtproto-client.c b/mtproto-client.c index 5fddd67..3166308 100644 --- a/mtproto-client.c +++ b/mtproto-client.c @@ -1390,6 +1390,10 @@ int rpc_execute (struct connection *c, int op, int len) { if (verbosity) { logprintf ( "outbound rpc connection #%d : received rpc answer %d with %d content bytes\n", c->fd, op, len); } + if (op < 0) { + assert (read_in (c, Response, Response_len) == Response_len); + return 0; + } if (len >= MAX_RESPONSE_SIZE/* - 12*/ || len < 0/*12*/) { logprintf ( "answer too long (%d bytes), skipping\n", len); diff --git a/net.c b/net.c index b03a5c6..9c8013e 100644 --- a/net.c +++ b/net.c @@ -141,7 +141,7 @@ int read_in (struct connection *c, void *data, int len) { int x = 0; while (len) { int y = c->in_head->wptr - c->in_head->rptr; - if (y > len) { + if (y >= len) { memcpy (data, c->in_head->rptr, len); c->in_head->rptr += len; c->in_bytes -= len; @@ -164,7 +164,7 @@ int read_in (struct connection *c, void *data, int len) { } int read_in_lookup (struct connection *c, void *data, int len) { - if (!len) { return 0; } + if (!len || !c->in_bytes) { return 0; } assert (len > 0); if (len > c->in_bytes) { len = c->in_bytes; @@ -173,12 +173,13 @@ int read_in_lookup (struct connection *c, void *data, int len) { struct connection_buffer *b = c->in_head; while (len) { int y = b->wptr - b->rptr; - if (y > len) { + if (y >= len) { memcpy (data, b->rptr, len); return x + len; } else { memcpy (data, b->rptr, y); x += y; + data += y; b = b->next; } } diff --git a/queries.c b/queries.c index f78e6bd..adb99df 100644 --- a/queries.c +++ b/queries.c @@ -1373,12 +1373,11 @@ void do_send_photo (int type, peer_id_t to_id, char *file_name) { f->size = size; f->offset = 0; f->part_num = 0; -/* int tmp = ((size + 1999) / 2000); + int tmp = ((size + 2999) / 3000); f->part_size = (1 << 10); while (f->part_size < tmp) { f->part_size *= 2; - }*/ - f->part_size = 256 << 10; + } f->id = lrand48 () * (1ll << 32) + lrand48 (); f->to_id = to_id; @@ -1398,7 +1397,7 @@ void do_send_photo (int type, peer_id_t to_id, char *file_name) { ((int *)f->key)[i] = mrand48 (); } } - if (f->part_size >= (512 << 10)) { + if (f->part_size > (512 << 10)) { close (fd); rprintf ("Too big file. Maximal supported size is %d", (512 << 10) * 1000); return;